extractGroupId($data); } /** * Returns a valid data structure. * * @param mixed $data * * @return array */ protected function decode(array $data): array { return [ 'id' => (int) $data['id'], 'name' => $data['name'], 'groupId' => $this->extractGroupId($data), 'backgroundURL' => $this->extractBackgroundUrl($data), 'backgroundColor' => $this->extractBackgroundColor($data), 'isFavorite' => $this->extractFavorite($data), 'width' => (int) $data['width'], 'height' => (int) $data['height'], ]; } private function extractGroupId(array $data): int { if (isset($data['id_group']) === true && \is_numeric($data['id_group']) === true && $data['id_group'] >= 0 ) { return $data['id_group']; } else if (isset($data['groupId']) === true && \is_numeric($data['groupId']) === true && $data['groupId'] >= 0 ) { return $data['groupId']; } throw new \InvalidArgumentException( 'the group Id property is required and should be integer' ); } private function extractBackgroundUrl(array $data) { $background = Model::notEmptyStringOr( Model::issetInArray($data, ['background', 'backgroundURL']), null ); return $background; } private function extractBackgroundColor(array $data) { $backgroundColor = Model::notEmptyStringOr( Model::issetInArray($data, ['backgroundColor', 'background_color']), null ); return $backgroundColor; } private function extractFavorite(array $data): bool { $favorite = Model::parseBool( Model::issetInArray($data, ['is_favourite', 'isFavorite']), null ); return $favorite; } }