diff --git a/src/contracts/Event/NameSchema/AbstractSchemaEvent.php b/src/contracts/Event/NameSchema/AbstractSchemaEvent.php index b1e890ad4d..d736c63e38 100644 --- a/src/contracts/Event/NameSchema/AbstractSchemaEvent.php +++ b/src/contracts/Event/NameSchema/AbstractSchemaEvent.php @@ -13,22 +13,22 @@ abstract class AbstractSchemaEvent extends Event { /** @var array */ - protected array $schemaIdentifiers; + private array $schemaIdentifiers; /** @var array> */ - protected array $tokenValues = []; + private array $tokenValues = []; public function __construct(array $schemaIdentifiers) { $this->schemaIdentifiers = $schemaIdentifiers; } - public function getTokenValues(): array + final public function getTokenValues(): array { return $this->tokenValues; } - public function setTokenValues(array $names): void + final public function setTokenValues(array $names): void { $this->tokenValues = $names; } diff --git a/src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php b/src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php index 8f4815a061..01435a74cf 100644 --- a/src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php +++ b/src/contracts/Event/NameSchema/ResolveContentNameSchemaEvent.php @@ -13,7 +13,7 @@ final class ResolveContentNameSchemaEvent extends AbstractNameSchemaEvent implements ContentAwareEventInterface { - protected Content $content; + private Content $content; public function __construct( Content $content, diff --git a/src/lib/Repository/Helper/NameSchemaService.php b/src/lib/Repository/Helper/NameSchemaService.php index f233147e2a..3b348022c2 100644 --- a/src/lib/Repository/Helper/NameSchemaService.php +++ b/src/lib/Repository/Helper/NameSchemaService.php @@ -123,9 +123,7 @@ protected function mergeFieldMap(Content $content, array $fieldMap, array $langu foreach ($content->fields as $fieldIdentifier => $fieldLanguageMap) { foreach ($languageCodes as $languageCode) { - $mergedFieldMap[$fieldIdentifier][$languageCode] = isset($fieldMap[$fieldIdentifier][$languageCode]) - ? $fieldMap[$fieldIdentifier][$languageCode] - : $fieldLanguageMap[$languageCode]; + $mergedFieldMap[$fieldIdentifier][$languageCode] = $fieldMap[$fieldIdentifier][$languageCode] ?? $fieldLanguageMap[$languageCode]; } } @@ -152,40 +150,38 @@ protected function getFieldTitles(array $schemaIdentifiers, $contentType, array $fieldTitles = []; foreach ($schemaIdentifiers as $fieldDefinitionIdentifier) { - if (isset($fieldMap[$fieldDefinitionIdentifier][$languageCode])) { - if ($contentType instanceof SPIContentType) { - $fieldDefinition = null; - foreach ($contentType->fieldDefinitions as $spiFieldDefinition) { - if ($spiFieldDefinition->identifier === $fieldDefinitionIdentifier) { - $fieldDefinition = $this->contentTypeDomainMapper->buildFieldDefinitionDomainObject( - $spiFieldDefinition, - // This is probably not main language, but as we don't expose it, it's ok for now. - $languageCode - ); - break; - } - } - - if ($fieldDefinition === null) { - $fieldTitles[$fieldDefinitionIdentifier] = ''; - continue; + if (!isset($fieldMap[$fieldDefinitionIdentifier][$languageCode])) { + continue; + } + if ($contentType instanceof SPIContentType) { + $fieldDefinition = null; + foreach ($contentType->fieldDefinitions as $spiFieldDefinition) { + if ($spiFieldDefinition->identifier === $fieldDefinitionIdentifier) { + $fieldDefinition = $this->contentTypeDomainMapper->buildFieldDefinitionDomainObject( + $spiFieldDefinition, + // This is probably not main language, but as we don't expose it, it's ok for now. + $languageCode + ); + break; } - } elseif ($contentType instanceof ContentType) { - $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); - } else { - throw new InvalidArgumentType('$contentType', 'API or SPI variant of a Content Type'); } - - $fieldTypeService = $this->fieldTypeRegistry->getFieldType( - $fieldDefinition->fieldTypeIdentifier - ); - - $fieldTitles[$fieldDefinitionIdentifier] = $fieldTypeService->getName( - $fieldMap[$fieldDefinitionIdentifier][$languageCode], - $fieldDefinition, - $languageCode - ); + if ($fieldDefinition === null) { + $fieldTitles[$fieldDefinitionIdentifier] = ''; + continue; + } + } elseif ($contentType instanceof ContentType) { + $fieldDefinition = $contentType->getFieldDefinition($fieldDefinitionIdentifier); + } else { + throw new InvalidArgumentType('$contentType', 'API or SPI variant of a Content Type'); } + $fieldTypeService = $this->fieldTypeRegistry->getFieldType( + $fieldDefinition->fieldTypeIdentifier + ); + $fieldTitles[$fieldDefinitionIdentifier] = $fieldTypeService->getName( + $fieldMap[$fieldDefinitionIdentifier][$languageCode], + $fieldDefinition, + $languageCode + ); } return $fieldTitles; diff --git a/src/lib/Repository/NameSchema/NameSchemaService.php b/src/lib/Repository/NameSchema/NameSchemaService.php index 8e1d4becc3..3ed92f7371 100644 --- a/src/lib/Repository/NameSchema/NameSchemaService.php +++ b/src/lib/Repository/NameSchema/NameSchemaService.php @@ -58,9 +58,9 @@ class NameSchemaService implements NameSchemaServiceInterface */ protected array $settings; - protected EventDispatcherInterface $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - protected SchemaIdentifierExtractorInterface $schemaIdentifierExtractor; + private SchemaIdentifierExtractorInterface $schemaIdentifierExtractor; /** * @param array{limit?: integer, sequence?: string} $settings