Skip to content

Commit

Permalink
Rector up to PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSiepmann committed Dec 4, 2023
1 parent dcc9c91 commit 65898e9
Show file tree
Hide file tree
Showing 46 changed files with 130 additions and 228 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.Build/
/.phpunit.cache
/composer.lock
/.phpunit.cache
/Tests/Acceptance/Support/_generated
/vendor/
2 changes: 1 addition & 1 deletion Classes/DependencyInjection/ConverterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class ConverterPass implements CompilerPassInterface
{
public const TAG = 'thuecat.typo3.converter';
final public const TAG = 'thuecat.typo3.converter';

public function process(ContainerBuilder $container): void
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/DependencyInjection/EntityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class EntityPass implements CompilerPassInterface
{
public const TAG = 'thuecat.entity';
final public const TAG = 'thuecat.entity';

public function process(ContainerBuilder $container): void
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/DependencyInjection/UrlProvidersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class UrlProvidersPass implements CompilerPassInterface
{
public const TAG = 'thuecat:urlprovider';
final public const TAG = 'thuecat:urlprovider';

public function process(ContainerBuilder $container): void
{
Expand Down
5 changes: 1 addition & 4 deletions Classes/Domain/Import/Entity/Properties/DayOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@

class DayOfWeek
{
protected string $dayOfWeek = '';

public function __construct(
string $dayOfWeek
protected string $dayOfWeek
) {
$this->dayOfWeek = $dayOfWeek;
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Import/Entity/Properties/Offer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setOfferType($offerType): void
}

$this->offerTypes = array_map(
[PropertyValues::class, 'removePrefixFromEntry'],
PropertyValues::removePrefixFromEntry(...),
$offerType
);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Import/Entity/Properties/OpeningHour.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

class OpeningHour
{
protected ?DateTimeImmutable $validFrom;
protected ?DateTimeImmutable $validFrom = null;

protected ?DateTimeImmutable $validThrough;
protected ?DateTimeImmutable $validThrough = null;

protected DateTimeImmutable $opens;

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function mapDataToEntity(

try {
return $serializer->deserialize(
json_encode($jsonLD),
json_encode($jsonLD, JSON_THROW_ON_ERROR),
$targetClassName,
'json',
$context
Expand Down
32 changes: 16 additions & 16 deletions Classes/Domain/Import/EntityMapper/CustomAnnotationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@
*/
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<string, array{DocBlock|null, int|null, string|null}>
*/
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
Expand All @@ -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();
Expand Down Expand Up @@ -246,7 +246,7 @@ private function getDocBlockFromConstructor(string $class, string $property): ?D
$docBlock = $this->docBlockFactory->create($reflectionConstructor, $this->contextFactory->createFromReflector($reflectionConstructor));

return $this->filterDocBlockParams($docBlock, $property);
} catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException) {
return null;
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ private function getDocBlockFromProperty(string $class, string $property): ?DocB

try {
return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector));
} catch (InvalidArgumentException|RuntimeException $e) {
} catch (InvalidArgumentException|RuntimeException) {
return null;
}
}
Expand Down Expand Up @@ -348,7 +348,7 @@ private function getDocBlockFromMethod(string $class, string $ucFirstProperty, i
) {
break;
}
} catch (ReflectionException $e) {
} catch (ReflectionException) {
// Try the next prefix if the method doesn't exist
}
}
Expand All @@ -367,7 +367,7 @@ private function getDocBlockFromMethod(string $class, string $ucFirstProperty, i

try {
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
} catch (InvalidArgumentException|RuntimeException $e) {
} catch (InvalidArgumentException|RuntimeException) {
return null;
}
}
Expand Down
17 changes: 6 additions & 11 deletions Classes/Domain/Import/EntityMapper/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class JsonDecode extends SymfonyJsonDecode
{
public const ACTIVE_LANGUAGE = 'active_language';
final public const ACTIVE_LANGUAGE = 'active_language';

/**
* @var array[]
Expand Down Expand Up @@ -92,12 +92,11 @@ private function process(
*
* 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) {
Expand Down Expand Up @@ -154,12 +153,11 @@ private function decodeLanguageSpecificValue(
*
* 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;
Expand Down Expand Up @@ -189,12 +187,11 @@ private function decodeSingleValues(
/**
* Prepare data structure for PHP \DateTimeImmutable.
*
* @param mixed $value
*
* @return mixed
*/
private function decodeDateTime(
&$value
mixed &$value
) {
$supportedTypes = [
'schema:Time',
Expand All @@ -214,11 +211,9 @@ private function decodeDateTime(
}

/**
* @param mixed $key
*
* @return mixed
*/
private function mapKey($key)
private function mapKey(mixed $key)
{
if (is_string($key) === false) {
return $key;
Expand All @@ -240,7 +235,7 @@ private function mapKey($key)
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;
Expand Down
10 changes: 2 additions & 8 deletions Classes/Domain/Import/EntityMapper/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@

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(
'Could not map incoming JSON-LD to target object: ' . $previous->getMessage(),
1628157659,
$previous
);
$this->jsonLD = $jsonLD;
$this->targetClassName = $targetClassName;
}

public function getUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/EntityMapper/PropertyValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function removePrefixFromEntry(string $entryWithPrefix): string
public static function removePrefixFromEntries(array $entriesWithPrefix): array
{
return array_map(
[PropertyValues::class, 'removePrefixFromEntry'],
PropertyValues::removePrefixFromEntry(...),
$entriesWithPrefix
);
}
Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Import/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@

class Importer
{
private Logger $logger;
private readonly Logger $logger;

private Import $import;
private readonly Import $import;

public function __construct(
private readonly UrlProviderRegistry $urls,
Expand All @@ -58,7 +58,7 @@ public function __construct(
private readonly SaveData $saveData,
LogManager $logManager
) {
$this->logger = $logManager->getLogger(__CLASS__);
$this->logger = $logManager->getLogger(self::class);
$this->import = new Import();
}

Expand Down Expand Up @@ -143,7 +143,7 @@ private function importJsonEntity(array $jsonEntity, string $url): void
}

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;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/Importer/FetchData.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function jsonLDFromUrl(string $url): array

$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;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/Importer/SaveData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class SaveData
{
/**
* @var mixed[]
* @var string[]
*/
private array $errorLog;

Expand Down
27 changes: 6 additions & 21 deletions Classes/Domain/Import/Model/GenericEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,20 @@

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
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function createRequest(string $method, $uri): RequestInterface

try {
$query['api_key'] = $this->extensionConfiguration->get('thuecat', 'apiKey');
} catch (ExtensionConfigurationExtensionNotConfiguredException $e) {
} catch (ExtensionConfigurationExtensionNotConfiguredException) {
// Nothing todo, not configured, don't add.
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/ResolveForeignReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function resolve(
): ?object {
try {
$jsonLD = $this->fetchData->jsonLDFromUrl($foreignReference->getId());
} catch (InvalidResponseException $e) {
} catch (InvalidResponseException) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Import/Typo3Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function convert(
$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
);
}
Expand Down
Loading

0 comments on commit 65898e9

Please sign in to comment.