diff --git a/src/Import.php b/src/Import.php index 8f925fd..b5d51cc 100644 --- a/src/Import.php +++ b/src/Import.php @@ -109,7 +109,7 @@ private function importContentType(string $contenttypeslug, array $data): void /** @var ContentType $contentType */ $contentType = $this->config->getContentType($record->get('contentType', $contenttypeslug)); - if (! $contentType) { + if (!$contentType) { $this->io->error('Requested ContentType ' . $record->get('contentType', $contenttypeslug) . ' is not defined in contenttypes.yaml.'); return; @@ -142,7 +142,7 @@ private function importRecord(ContentType $contentType, Collection $record): voi /** @var Content $content */ $content = $this->contentRepository->findOneBySlug(Str::slug($slug), $contentType); - if (! $content) { + if (!$content) { $content = new Content($contentType); $content->setAuthor($user); } @@ -156,10 +156,10 @@ private function importRecord(ContentType $contentType, Collection $record): voi // Convert 'file' in incoming image or file to 'filename' if (in_array($fieldDefinition['type'], ['image', 'file'], true)) { $item = (array) $item; - $item['filename'] = ! empty($item['file']) ? $item['file'] : current($item); + $item['filename'] = !empty($item['file']) ? $item['file'] : current($item); // If no filename is set, don't import a broken/missing image - if (! $item['filename']) { + if (!$item['filename']) { continue; } } @@ -298,11 +298,11 @@ private function importRecord(ContentType $contentType, Collection $record): voi foreach ($item as $taxo) { $configForTaxonomy = $this->config->getTaxonomy($key); - if (! $taxo['slug']) { + if (!$taxo['slug']) { continue; } - if (! is_object($configForTaxonomy)) { + if (!is_object($configForTaxonomy)) { continue; } @@ -420,16 +420,16 @@ private function isLocalisedField(Content $content, string $key, $item): bool { $fieldDefinition = $content->getDefinition()->get('fields')->get($key); - if (! $fieldDefinition['localize']) { + if (!$fieldDefinition['localize']) { return false; } - if (! is_array($item)) { + if (!is_array($item)) { return false; } foreach (array_keys($item) as $key) { - if (! preg_match('/^[a-z]{2}([_-][a-z]{2,3})?$/i', $key)) { + if (!preg_match('/^[a-z]{2}([_-][a-z]{2,3})?$/i', $key)) { return false; } } @@ -486,7 +486,7 @@ private function guesstimateUser(Collection $record): User } // Fall back to the first user we can find. 🤷‍ - if (! $user) { + if (!$user) { $user = $this->userRepository->findOneBy([]); } @@ -523,7 +523,7 @@ private function importUsers(array $data): void } } - private function getValues(string $id): int + private function getValues(string $id): ?int { $contentType = $this->config->getContentType(explode('/', $id)[0]); $slug = explode('/', $id)[1]; @@ -531,6 +531,8 @@ private function getValues(string $id): int if ($referencedEntity instanceof Content) { return $referencedEntity->getId(); } + + return null; } private function getMultipleValues(array $item): array