diff --git a/.gitignore b/.gitignore index bc598d6..16c3c4b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.Build/ -/.phpunit.cache /composer.lock +/.phpunit.cache +/Tests/Acceptance/Support/_generated /vendor/ diff --git a/Classes/DependencyInjection/ConverterPass.php b/Classes/DependencyInjection/ConverterPass.php index a07eaf4..d2356e8 100644 --- a/Classes/DependencyInjection/ConverterPass.php +++ b/Classes/DependencyInjection/ConverterPass.php @@ -29,7 +29,7 @@ use WerkraumMedia\ThueCat\Domain\Import\Typo3Converter\Registry; class ConverterPass implements CompilerPassInterface { - public const TAG = 'thuecat.typo3.converter'; + final public const TAG = 'thuecat.typo3.converter'; public function process(ContainerBuilder $container): void { diff --git a/Classes/DependencyInjection/EntityPass.php b/Classes/DependencyInjection/EntityPass.php index 8bff4b6..34288bd 100644 --- a/Classes/DependencyInjection/EntityPass.php +++ b/Classes/DependencyInjection/EntityPass.php @@ -29,7 +29,7 @@ use WerkraumMedia\ThueCat\Domain\Import\EntityMapper\EntityRegistry; class EntityPass implements CompilerPassInterface { - public const TAG = 'thuecat.entity'; + final public const TAG = 'thuecat.entity'; public function process(ContainerBuilder $container): void { diff --git a/Classes/DependencyInjection/UrlProvidersPass.php b/Classes/DependencyInjection/UrlProvidersPass.php index 0edd3b2..ba6473c 100644 --- a/Classes/DependencyInjection/UrlProvidersPass.php +++ b/Classes/DependencyInjection/UrlProvidersPass.php @@ -29,7 +29,7 @@ use WerkraumMedia\ThueCat\Domain\Import\UrlProvider\Registry; class UrlProvidersPass implements CompilerPassInterface { - public const TAG = 'thuecat:urlprovider'; + final public const TAG = 'thuecat:urlprovider'; public function process(ContainerBuilder $container): void { diff --git a/Classes/Domain/Import/Entity/Properties/DayOfWeek.php b/Classes/Domain/Import/Entity/Properties/DayOfWeek.php index 8588018..cd577dd 100644 --- a/Classes/Domain/Import/Entity/Properties/DayOfWeek.php +++ b/Classes/Domain/Import/Entity/Properties/DayOfWeek.php @@ -25,11 +25,8 @@ namespace WerkraumMedia\ThueCat\Domain\Import\Entity\Properties; class DayOfWeek { - protected string $dayOfWeek = ''; - public function __construct( - string $dayOfWeek + protected string $dayOfWeek ) { - $this->dayOfWeek = $dayOfWeek; } } diff --git a/Classes/Domain/Import/Entity/Properties/Offer.php b/Classes/Domain/Import/Entity/Properties/Offer.php index f079b91..8367f23 100644 --- a/Classes/Domain/Import/Entity/Properties/Offer.php +++ b/Classes/Domain/Import/Entity/Properties/Offer.php @@ -58,7 +58,7 @@ class Offer extends Minimum } $this->offerTypes = array_map( - [PropertyValues::class, 'removePrefixFromEntry'], + PropertyValues::removePrefixFromEntry(...), $offerType ); } diff --git a/Classes/Domain/Import/Entity/Properties/OpeningHour.php b/Classes/Domain/Import/Entity/Properties/OpeningHour.php index 8b065d4..99b5d60 100644 --- a/Classes/Domain/Import/Entity/Properties/OpeningHour.php +++ b/Classes/Domain/Import/Entity/Properties/OpeningHour.php @@ -27,9 +27,9 @@ use DateTimeImmutable; class OpeningHour { - protected ?DateTimeImmutable $validFrom; + protected ?DateTimeImmutable $validFrom = null; - protected ?DateTimeImmutable $validThrough; + protected ?DateTimeImmutable $validThrough = null; protected DateTimeImmutable $opens; diff --git a/Classes/Domain/Import/EntityMapper.php b/Classes/Domain/Import/EntityMapper.php index f4ce833..5fe5a9f 100644 --- a/Classes/Domain/Import/EntityMapper.php +++ b/Classes/Domain/Import/EntityMapper.php @@ -51,7 +51,7 @@ class EntityMapper try { return $serializer->deserialize( - json_encode($jsonLD), + json_encode($jsonLD, JSON_THROW_ON_ERROR), $targetClassName, 'json', $context diff --git a/Classes/Domain/Import/EntityMapper/CustomAnnotationExtractor.php b/Classes/Domain/Import/EntityMapper/CustomAnnotationExtractor.php index 1842cfb..936b6fa 100644 --- a/Classes/Domain/Import/EntityMapper/CustomAnnotationExtractor.php +++ b/Classes/Domain/Import/EntityMapper/CustomAnnotationExtractor.php @@ -54,26 +54,26 @@ use Symfony\Component\PropertyInfo\Util\PhpDocTypeHelper; */ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface, PropertyTypeExtractorInterface, ConstructorArgumentTypeExtractorInterface { - public const PROPERTY = 0; - public const ACCESSOR = 1; - public const MUTATOR = 2; + final public const PROPERTY = 0; + final public const ACCESSOR = 1; + final public const MUTATOR = 2; /** * @var array */ - private $docBlocks = []; + private array $docBlocks = []; /** * @var Context[] */ - private $contexts = []; + private array $contexts = []; - private $docBlockFactory; - private $contextFactory; - private $phpDocTypeHelper; - private $mutatorPrefixes; - private $accessorPrefixes; - private $arrayMutatorPrefixes; + private readonly \phpDocumentor\Reflection\DocBlockFactoryInterface $docBlockFactory; + private readonly \phpDocumentor\Reflection\Types\ContextFactory $contextFactory; + private readonly \Symfony\Component\PropertyInfo\Util\PhpDocTypeHelper $phpDocTypeHelper; + private readonly array $mutatorPrefixes; + private readonly array $accessorPrefixes; + private readonly array $arrayMutatorPrefixes; /** * @param string[]|null $mutatorPrefixes @@ -83,7 +83,7 @@ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface public function __construct(DocBlockFactoryInterface $docBlockFactory = null, array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null) { if (!class_exists(DocBlockFactory::class)) { - throw new LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed. Try running composer require "phpdocumentor/reflection-docblock".', __CLASS__)); + throw new LogicException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed. Try running composer require "phpdocumentor/reflection-docblock".', self::class)); } $this->docBlockFactory = $docBlockFactory ?: DocBlockFactory::createInstance(); @@ -246,7 +246,7 @@ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface $docBlock = $this->docBlockFactory->create($reflectionConstructor, $this->contextFactory->createFromReflector($reflectionConstructor)); return $this->filterDocBlockParams($docBlock, $property); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { return null; } } @@ -320,7 +320,7 @@ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface try { return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector)); - } catch (InvalidArgumentException|RuntimeException $e) { + } catch (InvalidArgumentException|RuntimeException) { return null; } } @@ -348,7 +348,7 @@ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface ) { break; } - } catch (ReflectionException $e) { + } catch (ReflectionException) { // Try the next prefix if the method doesn't exist } } @@ -367,7 +367,7 @@ class CustomAnnotationExtractor implements PropertyDescriptionExtractorInterface try { return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix]; - } catch (InvalidArgumentException|RuntimeException $e) { + } catch (InvalidArgumentException|RuntimeException) { return null; } } diff --git a/Classes/Domain/Import/EntityMapper/JsonDecode.php b/Classes/Domain/Import/EntityMapper/JsonDecode.php index e709926..809a91f 100644 --- a/Classes/Domain/Import/EntityMapper/JsonDecode.php +++ b/Classes/Domain/Import/EntityMapper/JsonDecode.php @@ -33,7 +33,7 @@ use Symfony\Component\Serializer\Encoder\JsonDecode as SymfonyJsonDecode; */ class JsonDecode extends SymfonyJsonDecode { - public const ACTIVE_LANGUAGE = 'active_language'; + final public const ACTIVE_LANGUAGE = 'active_language'; /** * @var array[] @@ -92,12 +92,11 @@ class JsonDecode extends SymfonyJsonDecode * * This decode will resolve the list to a single value based on current language settings from context. * - * @param mixed $value * * @return mixed */ private function decodeLanguageSpecificValue( - &$value, + mixed &$value, string $activeLanguage ) { if (is_array($value) === false) { @@ -154,12 +153,11 @@ class JsonDecode extends SymfonyJsonDecode * * This decode will resolve single values wrapped in array with extra info. * - * @param mixed $value * * @return mixed */ private function decodeSingleValues( - &$value + mixed &$value ) { if (is_array($value) === false) { return $value; @@ -189,12 +187,11 @@ class JsonDecode extends SymfonyJsonDecode /** * Prepare data structure for PHP \DateTimeImmutable. * - * @param mixed $value * * @return mixed */ private function decodeDateTime( - &$value + mixed &$value ) { $supportedTypes = [ 'schema:Time', @@ -214,11 +211,9 @@ class JsonDecode extends SymfonyJsonDecode } /** - * @param mixed $key - * * @return mixed */ - private function mapKey($key) + private function mapKey(mixed $key) { if (is_string($key) === false) { return $key; @@ -240,7 +235,7 @@ class JsonDecode extends SymfonyJsonDecode private function doesRuleMatch(array $rule, string $type): bool { if ($rule['type'] === 'beginsWith') { - return str_starts_with($type, $rule['comparisonValue']); + return str_starts_with($type, (string) $rule['comparisonValue']); } return false; diff --git a/Classes/Domain/Import/EntityMapper/MappingException.php b/Classes/Domain/Import/EntityMapper/MappingException.php index fc475d4..eb520a4 100644 --- a/Classes/Domain/Import/EntityMapper/MappingException.php +++ b/Classes/Domain/Import/EntityMapper/MappingException.php @@ -28,13 +28,9 @@ use Throwable; class MappingException extends Exception { - protected array $jsonLD = []; - - protected string $targetClassName = ''; - public function __construct( - array $jsonLD, - string $targetClassName, + protected array $jsonLD, + protected string $targetClassName, Throwable $previous ) { parent::__construct( @@ -42,8 +38,6 @@ class MappingException extends Exception 1628157659, $previous ); - $this->jsonLD = $jsonLD; - $this->targetClassName = $targetClassName; } public function getUrl(): string diff --git a/Classes/Domain/Import/EntityMapper/PropertyValues.php b/Classes/Domain/Import/EntityMapper/PropertyValues.php index fb4969c..48885ef 100644 --- a/Classes/Domain/Import/EntityMapper/PropertyValues.php +++ b/Classes/Domain/Import/EntityMapper/PropertyValues.php @@ -36,7 +36,7 @@ class PropertyValues public static function removePrefixFromEntries(array $entriesWithPrefix): array { return array_map( - [PropertyValues::class, 'removePrefixFromEntry'], + PropertyValues::removePrefixFromEntry(...), $entriesWithPrefix ); } diff --git a/Classes/Domain/Import/Importer.php b/Classes/Domain/Import/Importer.php index a1b7ca2..b8a650a 100644 --- a/Classes/Domain/Import/Importer.php +++ b/Classes/Domain/Import/Importer.php @@ -43,9 +43,9 @@ use WerkraumMedia\ThueCat\Domain\Repository\Backend\ImportLogRepository; class Importer { - private Logger $logger; + private readonly Logger $logger; - private Import $import; + private readonly Import $import; public function __construct( private readonly UrlProviderRegistry $urls, @@ -58,7 +58,7 @@ class Importer private readonly SaveData $saveData, LogManager $logManager ) { - $this->logger = $logManager->getLogger(__CLASS__); + $this->logger = $logManager->getLogger(self::class); $this->import = new Import(); } @@ -143,7 +143,7 @@ class Importer } if (!$mappedEntity instanceof MapsToType) { - $this->logger->error('Mapping did not result in an MapsToType instance.', ['class' => get_class($mappedEntity)]); + $this->logger->error('Mapping did not result in an MapsToType instance.', ['class' => $mappedEntity::class]); continue; } diff --git a/Classes/Domain/Import/Importer/FetchData.php b/Classes/Domain/Import/Importer/FetchData.php index 5561efc..544d3f8 100644 --- a/Classes/Domain/Import/Importer/FetchData.php +++ b/Classes/Domain/Import/Importer/FetchData.php @@ -70,7 +70,7 @@ class FetchData $this->handleInvalidResponse($response, $request); - $jsonLD = json_decode((string)$response->getBody(), true); + $jsonLD = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); if (is_array($jsonLD)) { $this->cache->set($cacheIdentifier, $jsonLD); return $jsonLD; diff --git a/Classes/Domain/Import/Importer/SaveData.php b/Classes/Domain/Import/Importer/SaveData.php index da4ded2..10a7a64 100644 --- a/Classes/Domain/Import/Importer/SaveData.php +++ b/Classes/Domain/Import/Importer/SaveData.php @@ -33,7 +33,7 @@ use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLogEntry\SavingEntity; class SaveData { /** - * @var mixed[] + * @var string[] */ private array $errorLog; diff --git a/Classes/Domain/Import/Model/GenericEntity.php b/Classes/Domain/Import/Model/GenericEntity.php index 9f75847..534fa99 100644 --- a/Classes/Domain/Import/Model/GenericEntity.php +++ b/Classes/Domain/Import/Model/GenericEntity.php @@ -25,35 +25,20 @@ namespace WerkraumMedia\ThueCat\Domain\Import\Model; class GenericEntity implements Entity { - private int $typo3StoragePid; - - private string $typo3DatabaseTableName; - - private int $typo3SystemLanguageUid; - private bool $created = false; private int $typo3Uid = 0; - private string $remoteId; - /** - * @var mixed[] + * @param mixed[] $data */ - private array $data; - public function __construct( - int $typo3StoragePid, - string $typo3DatabaseTableName, - int $typo3SystemLanguageUid, - string $remoteId, - array $data + private readonly int $typo3StoragePid, + private readonly string $typo3DatabaseTableName, + private readonly int $typo3SystemLanguageUid, + private readonly string $remoteId, + private readonly array $data ) { - $this->typo3StoragePid = $typo3StoragePid; - $this->typo3DatabaseTableName = $typo3DatabaseTableName; - $this->typo3SystemLanguageUid = $typo3SystemLanguageUid; - $this->remoteId = $remoteId; - $this->data = $data; } public function getTypo3StoragePid(): int diff --git a/Classes/Domain/Import/RequestFactory.php b/Classes/Domain/Import/RequestFactory.php index 2b02fc0..bfba08a 100644 --- a/Classes/Domain/Import/RequestFactory.php +++ b/Classes/Domain/Import/RequestFactory.php @@ -56,7 +56,7 @@ class RequestFactory implements RequestFactoryInterface try { $query['api_key'] = $this->extensionConfiguration->get('thuecat', 'apiKey'); - } catch (ExtensionConfigurationExtensionNotConfiguredException $e) { + } catch (ExtensionConfigurationExtensionNotConfiguredException) { // Nothing todo, not configured, don't add. } diff --git a/Classes/Domain/Import/ResolveForeignReference.php b/Classes/Domain/Import/ResolveForeignReference.php index 449dca2..8f1aeaa 100644 --- a/Classes/Domain/Import/ResolveForeignReference.php +++ b/Classes/Domain/Import/ResolveForeignReference.php @@ -51,7 +51,7 @@ class ResolveForeignReference ): ?object { try { $jsonLD = $this->fetchData->jsonLDFromUrl($foreignReference->getId()); - } catch (InvalidResponseException $e) { + } catch (InvalidResponseException) { return null; } diff --git a/Classes/Domain/Import/Typo3Converter.php b/Classes/Domain/Import/Typo3Converter.php index 38f2779..eb98011 100644 --- a/Classes/Domain/Import/Typo3Converter.php +++ b/Classes/Domain/Import/Typo3Converter.php @@ -51,7 +51,7 @@ class Typo3Converter implements Converter $concreteConverter = $this->registry->getConverterBasedOnType($mapped); if (!$concreteConverter instanceof Typo3ConcreteConverter) { throw new Exception( - 'No TYPO3 Converter registered for given Entity "' . get_class($mapped) . '".', + 'No TYPO3 Converter registered for given Entity "' . $mapped::class . '".', 1628244329 ); } diff --git a/Classes/Domain/Import/Typo3Converter/GeneralConverter.php b/Classes/Domain/Import/Typo3Converter/GeneralConverter.php index fd42b08..4454dc4 100644 --- a/Classes/Domain/Import/Typo3Converter/GeneralConverter.php +++ b/Classes/Domain/Import/Typo3Converter/GeneralConverter.php @@ -53,7 +53,7 @@ use WerkraumMedia\ThueCat\Domain\Repository\Backend\TownRepository; class GeneralConverter implements Converter { - private Logger $logger; + private readonly Logger $logger; private ImportConfiguration $importConfiguration; @@ -79,7 +79,7 @@ class GeneralConverter implements Converter private readonly NameExtractor $nameExtractor, LogManager $logManager ) { - $this->logger = $logManager->getLogger(__CLASS__); + $this->logger = $logManager->getLogger(self::class); } public function convert( @@ -95,7 +95,7 @@ class GeneralConverter implements Converter $converted = new GenericEntity( $importConfiguration->getStoragePid(), - $this->getTableNameByEntityClass(get_class($entity)), + $this->getTableNameByEntityClass($entity::class), $this->languageHandling->getLanguageUidForString( $importConfiguration->getStoragePid(), $language @@ -120,12 +120,12 @@ class GeneralConverter implements Converter ImportConfiguration $importConfiguration, string $language ): bool { - $tableName = $this->getTableNameByEntityClass(get_class($entity)); + $tableName = $this->getTableNameByEntityClass($entity::class); if (!$entity instanceof Minimum) { $this->logger->info('Skipped conversion of entity, got unexpected type', [ 'expectedType' => Minimum::class, - 'actualType' => get_class($entity), + 'actualType' => $entity::class, ]); return false; } @@ -313,6 +313,7 @@ class GeneralConverter implements Converter if ($result === false || $result === '[]') { return '{}'; } + return $result; } @@ -346,7 +347,7 @@ class GeneralConverter implements Converter } } - return json_encode($data) ?: ''; + return json_encode($data, JSON_THROW_ON_ERROR) ?: ''; } private function getSingleMedia( @@ -386,7 +387,7 @@ class GeneralConverter implements Converter ]); } - return json_encode($data) ?: ''; + return json_encode($data, JSON_THROW_ON_ERROR) ?: ''; } private function getAddress(Place $entity): string @@ -415,7 +416,7 @@ class GeneralConverter implements Converter ]; } - return json_encode($data) ?: ''; + return json_encode($data, JSON_THROW_ON_ERROR) ?: ''; } private function getOffers(Place $entity): string @@ -426,11 +427,11 @@ class GeneralConverter implements Converter 'types' => $offer->getOfferTypes(), 'title' => $offer->getName(), 'description' => $offer->getDescription(), - 'prices' => array_map([$this, 'getPrice'], $offer->getPrices()), + 'prices' => array_map($this->getPrice(...), $offer->getPrices()), ]; } - return json_encode($data) ?: ''; + return json_encode($data, JSON_THROW_ON_ERROR) ?: ''; } private function getPrice(PriceSpecification $priceSpecification): array diff --git a/Classes/Domain/Import/Typo3Converter/NameExtractor.php b/Classes/Domain/Import/Typo3Converter/NameExtractor.php index cfac8b4..13e0c78 100644 --- a/Classes/Domain/Import/Typo3Converter/NameExtractor.php +++ b/Classes/Domain/Import/Typo3Converter/NameExtractor.php @@ -28,12 +28,9 @@ use WerkraumMedia\ThueCat\Domain\Import\ResolveForeignReference; class NameExtractor { - private ResolveForeignReference $resolveForeignReference; - public function __construct( - ResolveForeignReference $resolveForeignReference + private readonly ResolveForeignReference $resolveForeignReference ) { - $this->resolveForeignReference = $resolveForeignReference; } /** @@ -62,7 +59,7 @@ class NameExtractor } if ($name === '' && method_exists($remote, 'getName')) { - $name = trim($remote->getName()); + $name = trim((string) $remote->getName()); } return $name; diff --git a/Classes/Domain/Model/Backend/AbstractEntity.php b/Classes/Domain/Model/Backend/AbstractEntity.php index 197a79a..c4e7e8e 100644 --- a/Classes/Domain/Model/Backend/AbstractEntity.php +++ b/Classes/Domain/Model/Backend/AbstractEntity.php @@ -34,7 +34,7 @@ class AbstractEntity extends Typo3AbstractEntity protected string $description = ''; - protected ?DateTimeImmutable $tstamp; + protected ?DateTimeImmutable $tstamp = null; public function getRemoteId(): string { diff --git a/Classes/Domain/Model/Backend/ImportConfiguration.php b/Classes/Domain/Model/Backend/ImportConfiguration.php index f774cbe..895a472 100644 --- a/Classes/Domain/Model/Backend/ImportConfiguration.php +++ b/Classes/Domain/Model/Backend/ImportConfiguration.php @@ -41,7 +41,7 @@ class ImportConfiguration extends AbstractEntity implements ImportConfigurationI protected string $configuration = ''; - protected ?DateTimeImmutable $tstamp; + protected ?DateTimeImmutable $tstamp = null; /** * @var ObjectStorage @@ -51,7 +51,7 @@ class ImportConfiguration extends AbstractEntity implements ImportConfigurationI /** * @var string[]|null */ - protected ?array $urls; + protected ?array $urls = null; /** * @var string[] diff --git a/Classes/Domain/Model/Backend/ImportLog.php b/Classes/Domain/Model/Backend/ImportLog.php index 6f322fb..b4e14be 100644 --- a/Classes/Domain/Model/Backend/ImportLog.php +++ b/Classes/Domain/Model/Backend/ImportLog.php @@ -35,15 +35,12 @@ class ImportLog extends Typo3AbstractEntity */ protected ObjectStorage $logEntries; - protected ?ImportConfiguration $configuration; - - protected ?DateTimeImmutable $crdate; + protected ?DateTimeImmutable $crdate = null; public function __construct( - ?ImportConfiguration $configuration = null + protected ?ImportConfiguration $configuration = null ) { $this->logEntries = new ObjectStorage(); - $this->configuration = $configuration; } public function addEntry(ImportLogEntry $entry): void diff --git a/Classes/Domain/Model/Backend/ImportLogEntry/MappingError.php b/Classes/Domain/Model/Backend/ImportLogEntry/MappingError.php index 6c07f95..e2515c4 100644 --- a/Classes/Domain/Model/Backend/ImportLogEntry/MappingError.php +++ b/Classes/Domain/Model/Backend/ImportLogEntry/MappingError.php @@ -37,7 +37,7 @@ class MappingError extends ImportLogEntry MappingException $exception ) { $this->remoteId = $exception->getUrl(); - $this->errors = json_encode([$exception->getMessage()]) ?: ''; + $this->errors = json_encode([$exception->getMessage()], JSON_THROW_ON_ERROR) ?: ''; } public function getRemoteId(): string @@ -47,7 +47,7 @@ class MappingError extends ImportLogEntry public function getErrors(): array { - $errors = json_decode($this->errors, true); + $errors = json_decode($this->errors, true, 512, JSON_THROW_ON_ERROR); if (is_array($errors) === false) { throw new Exception('Could not parse errors.', 1671097690); } diff --git a/Classes/Domain/Model/Backend/ImportLogEntry/SavingEntity.php b/Classes/Domain/Model/Backend/ImportLogEntry/SavingEntity.php index 7b3130f..ac5efb2 100644 --- a/Classes/Domain/Model/Backend/ImportLogEntry/SavingEntity.php +++ b/Classes/Domain/Model/Backend/ImportLogEntry/SavingEntity.php @@ -42,20 +42,17 @@ class SavingEntity extends ImportLogEntry protected string $errors = ''; /** - * @var string[] + * @param string[] $errorsAsArray */ - protected array $errorsAsArray = []; - public function __construct( Entity $entity, - array $dataHandlerErrorLog + protected array $errorsAsArray ) { $this->remoteId = $entity->getRemoteId(); $this->insertion = $entity->wasCreated(); $this->recordUid = $entity->getTypo3Uid(); $this->recordPid = $entity->getTypo3StoragePid(); $this->tableName = $entity->getTypo3DatabaseTableName(); - $this->errorsAsArray = $dataHandlerErrorLog; } public function getRemoteId(): string @@ -81,7 +78,7 @@ class SavingEntity extends ImportLogEntry public function getErrors(): array { if ($this->errorsAsArray === [] && $this->errors !== '') { - $errorsAsArray = json_decode($this->errors, true); + $errorsAsArray = json_decode($this->errors, true, 512, JSON_THROW_ON_ERROR); if (is_array($errorsAsArray) === false) { throw new Exception('Could not parse errors.', 1671097690); } diff --git a/Classes/Domain/Model/Frontend/AccessiblitySpecification.php b/Classes/Domain/Model/Frontend/AccessiblitySpecification.php index 9025c94..21e6f70 100644 --- a/Classes/Domain/Model/Frontend/AccessiblitySpecification.php +++ b/Classes/Domain/Model/Frontend/AccessiblitySpecification.php @@ -27,17 +27,15 @@ use TYPO3\CMS\Core\Type\TypeInterface; class AccessiblitySpecification implements TypeInterface { - private string $serialized; - /** * @var mixed[] */ private array $data; - public function __construct(string $serialized) - { - $this->serialized = $serialized; - $this->data = json_decode($serialized, true); + public function __construct( + private readonly string $serialized + ) { + $this->data = json_decode($serialized, true, 512, JSON_THROW_ON_ERROR); } public function getCertificationStatus(): string diff --git a/Classes/Domain/Model/Frontend/Address.php b/Classes/Domain/Model/Frontend/Address.php index df951cd..1aaf63b 100644 --- a/Classes/Domain/Model/Frontend/Address.php +++ b/Classes/Domain/Model/Frontend/Address.php @@ -27,17 +27,15 @@ use TYPO3\CMS\Core\Type\TypeInterface; class Address implements TypeInterface { - private string $serialized; - /** * @var mixed[] */ private array $data; - public function __construct(string $serialized) - { - $this->serialized = $serialized; - $this->data = json_decode($serialized, true); + public function __construct( + private readonly string $serialized + ) { + $this->data = json_decode($serialized, true, 512, JSON_THROW_ON_ERROR); } public function getStreet(): string diff --git a/Classes/Domain/Model/Frontend/Base.php b/Classes/Domain/Model/Frontend/Base.php index ed4580a..02bfc2f 100644 --- a/Classes/Domain/Model/Frontend/Base.php +++ b/Classes/Domain/Model/Frontend/Base.php @@ -31,7 +31,7 @@ abstract class Base extends AbstractEntity protected string $description = ''; - protected ?Media $media; + protected ?Media $media = null; public function getTitle(): string { diff --git a/Classes/Domain/Model/Frontend/Media.php b/Classes/Domain/Model/Frontend/Media.php index bb0f19c..1330131 100644 --- a/Classes/Domain/Model/Frontend/Media.php +++ b/Classes/Domain/Model/Frontend/Media.php @@ -28,22 +28,20 @@ use TYPO3\CMS\Core\Type\TypeInterface; class Media implements TypeInterface { - private string $serialized; - /** * @var array[] */ - private array $data; + private readonly array $data; /** * @var FileReference[] */ protected array $editorialImages = []; - public function __construct(string $serialized) - { - $this->serialized = $serialized; - $data = json_decode($serialized, true); + public function __construct( + private readonly string $serialized + ) { + $data = json_decode($serialized, true, 512, JSON_THROW_ON_ERROR); $this->data = $this->prepareData(is_array($data) ? $data : []); } diff --git a/Classes/Domain/Model/Frontend/MergedOpeningHour.php b/Classes/Domain/Model/Frontend/MergedOpeningHour.php index 04c5b64..6958511 100644 --- a/Classes/Domain/Model/Frontend/MergedOpeningHour.php +++ b/Classes/Domain/Model/Frontend/MergedOpeningHour.php @@ -32,9 +32,9 @@ class MergedOpeningHour */ private array $weekDays = []; - private ?DateTimeImmutabl $from; + private readonly ?DateTimeImmutable $from; - private ?DateTimeImmutabl $through; + private readonly ?DateTimeImmutable $through; public function __construct( array $weekDays, diff --git a/Classes/Domain/Model/Frontend/MergedOpeningHourWeekDay.php b/Classes/Domain/Model/Frontend/MergedOpeningHourWeekDay.php index 82c69c5..814aa9c 100644 --- a/Classes/Domain/Model/Frontend/MergedOpeningHourWeekDay.php +++ b/Classes/Domain/Model/Frontend/MergedOpeningHourWeekDay.php @@ -27,20 +27,11 @@ use WerkraumMedia\ThueCat\Domain\TimingFormat; class MergedOpeningHourWeekDay { - private string $opens; - - private string $closes; - - private string $dayOfWeek; - public function __construct( - string $opens, - string $closes, - string $dayOfWeek + private readonly string $opens, + private readonly string $closes, + private readonly string $dayOfWeek ) { - $this->opens = $opens; - $this->closes = $closes; - $this->dayOfWeek = $dayOfWeek; } public function getOpens(): string diff --git a/Classes/Domain/Model/Frontend/Offer.php b/Classes/Domain/Model/Frontend/Offer.php index ab0c106..5052c48 100644 --- a/Classes/Domain/Model/Frontend/Offer.php +++ b/Classes/Domain/Model/Frontend/Offer.php @@ -27,39 +27,19 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; class Offer { - private string $title; - - /** - * @var string[] - */ - private array $types; - - private string $description; - - /** - * @var mixed[] - */ - private array $prices; - /** * @param string[] $types + * @param mixed[] $prices */ private function __construct( - string $title, - array $types, - string $description, - array $prices + private readonly string $title, + private array $types, + private readonly string $description, + private readonly array $prices ) { - $this->title = $title; - $this->types = $types; - $this->description = $description; - $this->prices = $prices; } - /** - * @return Offer - */ - public static function createFromArray(array $rawData) + public static function createFromArray(array $rawData): Offer { $prices = []; diff --git a/Classes/Domain/Model/Frontend/Offers.php b/Classes/Domain/Model/Frontend/Offers.php index 2419d09..87ab4d2 100644 --- a/Classes/Domain/Model/Frontend/Offers.php +++ b/Classes/Domain/Model/Frontend/Offers.php @@ -32,8 +32,6 @@ use TYPO3\CMS\Core\Type\TypeInterface; */ class Offers implements TypeInterface, Iterator, Countable { - private string $serialized = ''; - /** * @var mixed[] */ @@ -41,10 +39,10 @@ class Offers implements TypeInterface, Iterator, Countable private int $position = 0; - public function __construct(string $serialized) - { - $this->serialized = $serialized; - $array = json_decode($serialized, true); + public function __construct( + private readonly string $serialized + ) { + $array = json_decode($serialized, true, 512, JSON_THROW_ON_ERROR); if (is_array($array)) { $array = array_map([Offer::class, 'createFromArray'], $array); usort($array, function (Offer $offerA, Offer $offerB) { diff --git a/Classes/Domain/Model/Frontend/OpeningHour.php b/Classes/Domain/Model/Frontend/OpeningHour.php index 034d4cb..3951979 100644 --- a/Classes/Domain/Model/Frontend/OpeningHour.php +++ b/Classes/Domain/Model/Frontend/OpeningHour.php @@ -29,37 +29,19 @@ use WerkraumMedia\ThueCat\Domain\TimingFormat; class OpeningHour { - private string $opens; - - private string $closes; - /** - * @var mixed[] + * @param mixed[] $daysOfWeek */ - private array $daysOfWeek; - - private ?DateTimeImmutable $from; - - private ?DateTimeImmutable $through; - private function __construct( - string $opens, - string $closes, - array $daysOfWeek, - ?DateTimeImmutable $from, - ?DateTimeImmutable $through + private readonly string $opens, + private readonly string $closes, + private array $daysOfWeek, + private readonly ?DateTimeImmutable $from, + private readonly ?DateTimeImmutable $through ) { - $this->opens = $opens; - $this->closes = $closes; - $this->daysOfWeek = $daysOfWeek; - $this->from = $from; - $this->through = $through; } - /** - * @return OpeningHour - */ - public static function createFromArray(array $rawData) + public static function createFromArray(array $rawData): OpeningHour { $from = null; if (isset($rawData['from'])) { diff --git a/Classes/Domain/Model/Frontend/OpeningHours.php b/Classes/Domain/Model/Frontend/OpeningHours.php index 92d3c0a..9cd2ba0 100644 --- a/Classes/Domain/Model/Frontend/OpeningHours.php +++ b/Classes/Domain/Model/Frontend/OpeningHours.php @@ -31,12 +31,10 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use WerkraumMedia\ThueCat\Service\DateBasedFilter; /** - * @implements \Iterator + * @implements Iterator */ class OpeningHours implements TypeInterface, Iterator, Countable { - private string $serialized = ''; - /** * @var mixed[] */ @@ -44,9 +42,9 @@ class OpeningHours implements TypeInterface, Iterator, Countable private int $position = 0; - public function __construct(string $serialized) - { - $this->serialized = $serialized; + public function __construct( + private readonly string $serialized + ) { $this->array = $this->createArray($serialized); } @@ -54,7 +52,7 @@ class OpeningHours implements TypeInterface, Iterator, Countable { $array = array_map( [OpeningHour::class, 'createFromArray'], - json_decode($serialized, true) ?? [] + json_decode($serialized, true, 512, JSON_THROW_ON_ERROR) ?? [] ); $array = GeneralUtility::makeInstance(DateBasedFilter::class) diff --git a/Classes/Domain/Model/Frontend/Place.php b/Classes/Domain/Model/Frontend/Place.php index f846420..e40fcd2 100644 --- a/Classes/Domain/Model/Frontend/Place.php +++ b/Classes/Domain/Model/Frontend/Place.php @@ -28,13 +28,13 @@ use TYPO3\CMS\Extbase\Persistence\ObjectStorage; abstract class Place extends Base { - protected ?Address $address; + protected ?Address $address = null; protected string $url = ''; - protected ?OpeningHours $openingHours; + protected ?OpeningHours $openingHours = null; - protected ?OpeningHours $specialOpeningHours; + protected ?OpeningHours $specialOpeningHours = null; /** * @var ObjectStorage @@ -51,7 +51,7 @@ abstract class Place extends Base protected string $distanceToPublicTransport = ''; - protected ?AccessiblitySpecification $accessibilitySpecification; + protected ?AccessiblitySpecification $accessibilitySpecification = null; public function initializeObject(): void { diff --git a/Classes/Domain/Model/Frontend/TouristAttraction.php b/Classes/Domain/Model/Frontend/TouristAttraction.php index c468692..b7ea300 100644 --- a/Classes/Domain/Model/Frontend/TouristAttraction.php +++ b/Classes/Domain/Model/Frontend/TouristAttraction.php @@ -29,9 +29,9 @@ class TouristAttraction extends Place { protected string $slogan = ''; - protected ?Offers $offers; + protected ?Offers $offers = null; - protected ?Town $town; + protected ?Town $town = null; protected string $startOfConstruction = ''; diff --git a/Classes/Domain/Repository/Backend/ImportLogRepository.php b/Classes/Domain/Repository/Backend/ImportLogRepository.php index 0df30bd..8412277 100644 --- a/Classes/Domain/Repository/Backend/ImportLogRepository.php +++ b/Classes/Domain/Repository/Backend/ImportLogRepository.php @@ -75,7 +75,7 @@ class ImportLogRepository extends Repository 'import_log' => 'NEW0', 'type' => $entry->getType(), 'remote_id' => $entry->getRemoteId(), - 'errors' => json_encode($entry->getErrors()), + 'errors' => json_encode($entry->getErrors(), JSON_THROW_ON_ERROR), ] ); } diff --git a/Classes/Extension.php b/Classes/Extension.php index e2a0029..7e1edd8 100644 --- a/Classes/Extension.php +++ b/Classes/Extension.php @@ -30,13 +30,13 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; class Extension { - public const EXTENSION_KEY = 'thuecat'; + final public const EXTENSION_KEY = 'thuecat'; - public const EXTENSION_NAME = 'Thuecat'; + final public const EXTENSION_NAME = 'Thuecat'; - public const TCA_SELECT_GROUP_IDENTIFIER = 'thuecat'; + final public const TCA_SELECT_GROUP_IDENTIFIER = 'thuecat'; - public const PAGE_DOKTYPE_TOURIST_ATTRACTION = 950; + final public const PAGE_DOKTYPE_TOURIST_ATTRACTION = 950; public static function getLanguagePath(): string { diff --git a/Classes/Frontend/DataProcessing/ResolveEntities.php b/Classes/Frontend/DataProcessing/ResolveEntities.php index 7677ac8..3d7797a 100644 --- a/Classes/Frontend/DataProcessing/ResolveEntities.php +++ b/Classes/Frontend/DataProcessing/ResolveEntities.php @@ -33,7 +33,7 @@ use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; class ResolveEntities implements DataProcessorInterface { - private TypoScriptFrontendController $tsfe; + private readonly TypoScriptFrontendController $tsfe; public function __construct( private readonly ConnectionPool $connectionPool, diff --git a/Classes/Typo3/Extbase/DataMapping/AfterObjectThawedHandler.php b/Classes/Typo3/Extbase/DataMapping/AfterObjectThawedHandler.php index 675aa07..a182ca0 100644 --- a/Classes/Typo3/Extbase/DataMapping/AfterObjectThawedHandler.php +++ b/Classes/Typo3/Extbase/DataMapping/AfterObjectThawedHandler.php @@ -77,7 +77,7 @@ class AfterObjectThawedHandler private function getTableNameForObject(Base $object): string { return $this->dataMapFactory - ->buildDataMap(get_class($object)) + ->buildDataMap($object::class) ->getTableName() ; } diff --git a/Configuration/TCA/tx_thuecat_parking_facility.php b/Configuration/TCA/tx_thuecat_parking_facility.php index 3af1e46..ec1cdb6 100644 --- a/Configuration/TCA/tx_thuecat_parking_facility.php +++ b/Configuration/TCA/tx_thuecat_parking_facility.php @@ -44,7 +44,7 @@ return (static function (string $extensionKey, string $tableName) { [ 'label' => '', 'value' => 0, - ] + ], ], 'foreign_table' => $tableName, 'foreign_table_where' => 'AND ' . $tableName . '.pid=###CURRENT_PID### AND ' . $tableName . '.sys_language_uid IN (-1,0)', diff --git a/Configuration/TCA/tx_thuecat_tourist_attraction.php b/Configuration/TCA/tx_thuecat_tourist_attraction.php index bdb707a..8a93e9f 100644 --- a/Configuration/TCA/tx_thuecat_tourist_attraction.php +++ b/Configuration/TCA/tx_thuecat_tourist_attraction.php @@ -44,7 +44,7 @@ return (static function (string $extensionKey, string $tableName) { [ 'label' => '', 'value' => 0, - ] + ], ], 'foreign_table' => $tableName, 'foreign_table_where' => 'AND ' . $tableName . '.pid=###CURRENT_PID### AND ' . $tableName . '.sys_language_uid IN (-1,0)', diff --git a/Tests/Acceptance/Support/_generated/.gitignore b/Tests/Acceptance/Support/_generated/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/Tests/Acceptance/Support/_generated/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/Tests/Functional/GuzzleClientFaker.php b/Tests/Functional/GuzzleClientFaker.php index 515a1fe..1a0d01b 100644 --- a/Tests/Functional/GuzzleClientFaker.php +++ b/Tests/Functional/GuzzleClientFaker.php @@ -11,10 +11,7 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse; class GuzzleClientFaker { - /** - * @var MockHandler - */ - private static $mockHandler; + private static ?MockHandler $mockHandler = null; public static function registerClient(): void {