diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a6089eb..5755098 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @keichinger @jesko-plitt +* @rafaelsouzaf @mangoischke diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c4c9a94..715c320 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.1', '8.2', '8.3'] name: PHP ${{ matrix.php-versions }} Testing steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -22,11 +22,16 @@ jobs: - name: Composer Install run: composer install + - name: Configure Composer Plugin Permissions + run: | + composer config allow-plugins.bamarni/composer-bin-plugin true + composer config allow-plugins.ergebnis/composer-normalize true + - name: Composer Plugins - run: composer global require ergebnis/composer-normalize bamarni/composer-bin-plugin php-coveralls/php-coveralls --no-interaction --prefer-dist --no-progress --no-suggest --no-suggest + run: composer require --dev ergebnis/composer-normalize bamarni/composer-bin-plugin --no-interaction --prefer-dist --no-progress - name: Composer Vendor-Bin Dependencies - run: composer bin all install --no-interaction --prefer-dist --no-progress --no-suggest + run: composer bin all install --no-interaction --prefer-dist --no-progress - name: Create Build Logs Directory run: mkdir -p build/logs diff --git a/CHANGELOG.md b/CHANGELOG.md index 14c34cf..87f3567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +9.0.0 +===== + +* (breaking) Minimum PHP version increased to 8.1. +* (breaking) All Doctrine ORM annotations converted to PHP 8 attributes. + + 8.6.1 ===== diff --git a/UPGRADE.md b/UPGRADE.md index bf71bd6..79b9174 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,10 @@ +8.x to 9.0 +========== + +* The minimum PHP version has been increased from **7.4** to **8.1**. +* All Doctrine ORM annotations have been converted to PHP 8 attributes. + + 7.x to 8.0 ========== diff --git a/composer.json b/composer.json index 224d953..d0d04b8 100644 --- a/composer.json +++ b/composer.json @@ -11,28 +11,28 @@ ], "homepage": "https://github.com/Becklyn/rad", "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-json": "*", "beberlei/doctrineextensions": "^1.3.0", "becklyn/rad-bundles": "^1.1.0", - "doctrine/doctrine-bundle": "^2.3.2", - "doctrine/orm": "^2.10.3", + "doctrine/doctrine-bundle": "^2.5.6", + "doctrine/orm": "^2.11.1", "psr/log": "^1.1.4", "scienta/doctrine-json-functions": "^4.5.0 || ^5.0.0", - "symfony/config": "^5.4.3 || ^6.0.3", - "symfony/dependency-injection": "^5.4.3 || ^6.0.3", - "symfony/form": "^5.4.3 || ^6.0.3", - "symfony/http-kernel": "^5.4.3 || ^6.0.4", - "symfony/property-access": "^5.4.3 || ^6.0.3", - "symfony/translation-contracts": "^v2.5.0 || ^v3.0.0", - "symfony/validator": "^5.4.3 || ^6.0.3", - "twig/twig": "^v3.3.4" + "symfony/config": "^6.4", + "symfony/dependency-injection": "^6.4", + "symfony/form": "^6.4", + "symfony/http-kernel": "^6.4", + "symfony/property-access": "^6.4", + "symfony/translation-contracts": "^3.0.0", + "symfony/validator": "^6.4", + "twig/twig": "^3.3.8" }, "require-dev": { "algolia/search-bundle": "^5.2.1 || ^6.0.0", "roave/security-advisories": "dev-master", - "symfony/phpunit-bridge": "^5.4.3 || ^6.0.3", - "symfony/twig-bridge": "^5.4.3 || ^6.0.3" + "symfony/phpunit-bridge": "^6.4", + "symfony/twig-bridge": "^6.4" }, "conflict": { "becklyn/rad-bundle": "*" @@ -51,6 +51,10 @@ } }, "config": { + "allow-plugins": { + "bamarni/composer-bin-plugin": true, + "ergebnis/composer-normalize": true + }, "sort-packages": true }, "extra": { diff --git a/src/Ajax/AjaxResponseBuilder.php b/src/Ajax/AjaxResponseBuilder.php index 99d8e37..bc3def8 100644 --- a/src/Ajax/AjaxResponseBuilder.php +++ b/src/Ajax/AjaxResponseBuilder.php @@ -17,17 +17,9 @@ */ class AjaxResponseBuilder { - /** @var TranslatorInterface */ - protected $translator; + protected bool $ok; - /** @var UrlGeneratorInterface */ - protected $urlGenerator; - - /** @var bool */ - protected $ok; - - /** @var string */ - protected $status; + protected ?string $status; /** @var DeferredRoute|string|null */ protected $redirect; @@ -51,8 +43,8 @@ class AjaxResponseBuilder /** */ public function __construct ( - TranslatorInterface $translator, - UrlGeneratorInterface $urlGenerator, + protected TranslatorInterface $translator, + protected UrlGeneratorInterface $urlGenerator, bool $ok, ?string $status = null ) @@ -61,9 +53,6 @@ public function __construct ( { $status = $ok ? "ok" : "failed"; } - - $this->urlGenerator = $urlGenerator; - $this->translator = $translator; $this->ok = $ok; $this->status = $status; } diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 1e00411..770d015 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -8,14 +8,8 @@ class CommandHelper { - private Profiler $profiler; - private EventManager $eventManager; - - - public function __construct (Profiler $profiler, EventManager $eventManager) + public function __construct(private readonly Profiler $profiler, private readonly EventManager $eventManager) { - $this->profiler = $profiler; - $this->eventManager = $eventManager; } diff --git a/src/Controller/BaseController.php b/src/Controller/BaseController.php index 1f36042..517b806 100644 --- a/src/Controller/BaseController.php +++ b/src/Controller/BaseController.php @@ -90,7 +90,7 @@ protected function getLogger () : LoggerInterface */ protected function getJsonRequestData (Request $request, bool $isRequired = true) : array { - if ("json" !== $request->getContentType()) + if ("json" !== $request->getContentTypeFormat()) { if (!$isRequired) { @@ -121,12 +121,12 @@ protected function getJsonRequestData (Request $request, bool $isRequired = true return $data; } - catch (\JsonException $e) + catch (\JsonException $jsonException) { throw new InvalidJsonRequestException( - "Invalid JSON received, error: {$e->getMessage()}", + 'Invalid JSON received, error: ' . $jsonException->getMessage(), 400, - $e + $jsonException ); } } diff --git a/src/Entity/Interfaces/SortableEntityInterface.php b/src/Entity/Interfaces/SortableEntityInterface.php index 07436d6..ca04362 100644 --- a/src/Entity/Interfaces/SortableEntityInterface.php +++ b/src/Entity/Interfaces/SortableEntityInterface.php @@ -6,8 +6,6 @@ interface SortableEntityInterface extends EntityInterface { /** * Returns the sort order. - * - * @return int */ public function getSortOrder () : ?int; diff --git a/src/Entity/Tag/TagEntity.php b/src/Entity/Tag/TagEntity.php index 3d7b843..0b1a027 100644 --- a/src/Entity/Tag/TagEntity.php +++ b/src/Entity/Tag/TagEntity.php @@ -11,22 +11,17 @@ /** * Base class for implementing tag entities - * - * @ORM\MappedSuperclass() - * - * @UniqueEntity(fields={"tag"}, message="becklyn.rad.tag.duplicate") */ +#[ORM\MappedSuperclass] +#[UniqueEntity(fields: ['tag'], message: 'becklyn.rad.tag.duplicate')] abstract class TagEntity implements EntityInterface, TagInterface { use IdTrait; - /** - * @ORM\Column(name="tag", type="string", length=254, unique=true) - * - * @Assert\NotNull() - * @Assert\Length(max="254") - * @Assert\Regex(pattern="~^[a-z0-9\-_., ]+$~i", message="becklyn.rad.tag.pattern") - */ + #[ORM\Column(name: 'tag', type: 'string', length: 254, unique: true)] + #[Assert\NotNull] + #[Assert\Length(max: 254)] + #[Assert\Regex(pattern: '~^[a-z0-9\\-_., ]+$~i', message: 'becklyn.rad.tag.pattern')] private ?string $tag = null; diff --git a/src/Entity/Traits/IdTrait.php b/src/Entity/Traits/IdTrait.php index 269c140..d1b6e04 100644 --- a/src/Entity/Traits/IdTrait.php +++ b/src/Entity/Traits/IdTrait.php @@ -9,11 +9,9 @@ */ trait IdTrait { - /** - * @ORM\Id() - * @ORM\GeneratedValue(strategy="AUTO") - * @ORM\Column(name="id", type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'AUTO')] + #[ORM\Column(name: 'id', type: 'integer')] private ?int $id = null; diff --git a/src/Entity/Traits/SortOrderTrait.php b/src/Entity/Traits/SortOrderTrait.php index e5f4e9b..ca48061 100644 --- a/src/Entity/Traits/SortOrderTrait.php +++ b/src/Entity/Traits/SortOrderTrait.php @@ -9,15 +9,12 @@ */ trait SortOrderTrait { - /** - * @ORM\Column(name="sort_order", type="integer") - */ + #[ORM\Column(name: 'sort_order', type: 'integer')] private ?int $sortOrder = null; /** - * @return int */ public function getSortOrder () : ?int { diff --git a/src/Entity/Traits/TimestampsTrait.php b/src/Entity/Traits/TimestampsTrait.php index e3cbbc8..b446739 100644 --- a/src/Entity/Traits/TimestampsTrait.php +++ b/src/Entity/Traits/TimestampsTrait.php @@ -9,15 +9,10 @@ */ trait TimestampsTrait { - /** - * @ORM\Column(name="time_created", type="datetime_immutable") - */ + #[ORM\Column(name: 'time_created', type: 'datetime_immutable')] private \DateTimeImmutable $timeCreated; - - /** - * @ORM\Column(name="time_modified", type="datetime_immutable", nullable=true) - */ + #[ORM\Column(name: 'time_modified', type: 'datetime_immutable', nullable: true)] private ?\DateTimeImmutable $timeModified = null; diff --git a/src/Exception/Controller/InvalidJsonRequestException.php b/src/Exception/Controller/InvalidJsonRequestException.php index 263818c..21a63c2 100644 --- a/src/Exception/Controller/InvalidJsonRequestException.php +++ b/src/Exception/Controller/InvalidJsonRequestException.php @@ -6,7 +6,7 @@ final class InvalidJsonRequestException extends \RuntimeException implements HttpExceptionInterface { - private int $statusCode; + private readonly int $statusCode; /** diff --git a/src/Exception/EntityRemovalBlockedException.php b/src/Exception/EntityRemovalBlockedException.php index 1d88230..213033e 100644 --- a/src/Exception/EntityRemovalBlockedException.php +++ b/src/Exception/EntityRemovalBlockedException.php @@ -9,7 +9,7 @@ class EntityRemovalBlockedException extends \InvalidArgumentException implements RadException { /** @var object[] */ - private array $entities; + private readonly array $entities; /** diff --git a/src/Exception/LabeledEntityRemovalBlockedException.php b/src/Exception/LabeledEntityRemovalBlockedException.php index 181333d..0ca7e7f 100644 --- a/src/Exception/LabeledEntityRemovalBlockedException.php +++ b/src/Exception/LabeledEntityRemovalBlockedException.php @@ -7,9 +7,6 @@ */ class LabeledEntityRemovalBlockedException extends EntityRemovalBlockedException implements LabeledExceptionInterface { - /** @var string */ - private $frontendMessage; - /** * {@inheritdoc} * @@ -18,15 +15,14 @@ class LabeledEntityRemovalBlockedException extends EntityRemovalBlockedException * @param object|object[] $entities * @param string $frontendMessage the #TranslationKey to use */ - public function __construct ($entities, string $message, string $frontendMessage, ?\Throwable $previous = null) + public function __construct ($entities, string $message, private readonly string $frontendMessage, ?\Throwable $previous = null) { parent::__construct($entities, $message, $previous); - $this->frontendMessage = $frontendMessage; } /** */ - public function getFrontendMessage () + public function getFrontendMessage () : string { return $this->frontendMessage; } diff --git a/src/Exception/UnexpectedTypeException.php b/src/Exception/UnexpectedTypeException.php index 5f9df50..8c9a223 100644 --- a/src/Exception/UnexpectedTypeException.php +++ b/src/Exception/UnexpectedTypeException.php @@ -15,7 +15,7 @@ public function __construct ($value, string $expectedType) parent::__construct(\sprintf( 'Expected argument of type %s, "%s" given', $expectedType, - \is_object($value) ? \get_class($value) : \gettype($value) + \get_debug_type($value) )); } } diff --git a/src/Form/DeferredForm.php b/src/Form/DeferredForm.php index 1dc2c92..70f08d9 100644 --- a/src/Form/DeferredForm.php +++ b/src/Form/DeferredForm.php @@ -10,16 +10,10 @@ */ final class DeferredForm { - private string $type; - private array $options; - - /** */ - public function __construct (string $type, array $options = []) + public function __construct(private readonly string $type, private array $options = []) { - $this->type = $type; - $this->options = $options; } @@ -39,9 +33,6 @@ public function getOptions () : array } - /** - * @return static - */ public function withOptions (array $options) : self { $modified = clone $this; diff --git a/src/Form/Extension/ChoicePlaceholderFormExtension.php b/src/Form/Extension/ChoicePlaceholderFormExtension.php index ef343b2..81bc959 100644 --- a/src/Form/Extension/ChoicePlaceholderFormExtension.php +++ b/src/Form/Extension/ChoicePlaceholderFormExtension.php @@ -14,13 +14,8 @@ */ class ChoicePlaceholderFormExtension extends AbstractTypeExtension { - private TranslatorInterface $translator; - - /** - */ - public function __construct (TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } /** diff --git a/src/Form/Extension/CollectionAdditionalOptionsFormExtension.php b/src/Form/Extension/CollectionAdditionalOptionsFormExtension.php index aa8a088..24ac652 100644 --- a/src/Form/Extension/CollectionAdditionalOptionsFormExtension.php +++ b/src/Form/Extension/CollectionAdditionalOptionsFormExtension.php @@ -22,6 +22,7 @@ public function buildForm (FormBuilderInterface $builder, array $options) : void { $builder->setAttribute($label, $options[$label]); } + $builder->setAttribute("allow_sort", $options["allow_sort"]); } @@ -34,6 +35,7 @@ public function buildView (FormView $view, FormInterface $form, array $options) { $view->vars[$label] = $form->getConfig()->getAttribute($label); } + $view->vars["allow_sort"] = $form->getConfig()->getAttribute("allow_sort"); } diff --git a/src/Form/FormErrorMapper.php b/src/Form/FormErrorMapper.php index 3d912bf..e667bda 100644 --- a/src/Form/FormErrorMapper.php +++ b/src/Form/FormErrorMapper.php @@ -11,14 +11,10 @@ */ class FormErrorMapper { - private TranslatorInterface $translator; - - /** */ - public function __construct (TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } @@ -53,15 +49,12 @@ private function addChildErrors (FormInterface $form, string $fieldPrefix, strin foreach ($form->all() as $children) { $childErrors = $children->getErrors(); - $fieldName = \ltrim("{$fieldPrefix}{$children->getName()}"); + $fieldName = \ltrim($fieldPrefix . $children->getName()); if (0 < \count($childErrors)) { $allErrors[$fieldName] = \array_map( - function (FormError $error) use ($translationDomain) - { - return $this->translator->trans($error->getMessage(), [], $translationDomain); - }, + fn(FormError $error) : string => $this->translator->trans($error->getMessage(), [], $translationDomain), \iterator_to_array($childErrors) ); } diff --git a/src/Integration/Profiler.php b/src/Integration/Profiler.php index f4ec9b1..5c3fd2b 100644 --- a/src/Integration/Profiler.php +++ b/src/Integration/Profiler.php @@ -6,12 +6,8 @@ class Profiler { - private ?SymfonyProfiler $profiler; - - - public function __construct (?SymfonyProfiler $profiler) + public function __construct(private readonly ?SymfonyProfiler $profiler) { - $this->profiler = $profiler; } diff --git a/src/Pagination/Data/PaginatedList.php b/src/Pagination/Data/PaginatedList.php index 6abe267..adb8f5f 100644 --- a/src/Pagination/Data/PaginatedList.php +++ b/src/Pagination/Data/PaginatedList.php @@ -9,14 +9,8 @@ */ class PaginatedList { - private iterable $list; - private Pagination $pagination; - - - public function __construct (iterable $list, Pagination $pagination) + public function __construct(private readonly iterable $list, private readonly Pagination $pagination) { - $this->list = $list; - $this->pagination = $pagination; } diff --git a/src/Pagination/Data/Pagination.php b/src/Pagination/Data/Pagination.php index 7876ca9..d99fc63 100644 --- a/src/Pagination/Data/Pagination.php +++ b/src/Pagination/Data/Pagination.php @@ -9,20 +9,16 @@ */ class Pagination { + private readonly int $numberOfItems; + private readonly int $perPage; + private readonly int $maxPage; + /** * WARNING: this value is unsanitized. You should never use it except for when passing it to a pagination with a * different number of elements. Always use the getter, which returns the normalized value. Also use the normalized * getter in internal methods to have correct calculation. */ - private int $currentPage; - private int $numberOfItems; - private int $perPage; - private int $maxPage; - - - /** - */ - public function __construct (int $currentPage, int $perPage = 50, int $numberOfItems = 0) + public function __construct (private readonly int $currentPage, int $perPage = 50, int $numberOfItems = 0) { if ($perPage <= 0) { @@ -33,11 +29,9 @@ public function __construct (int $currentPage, int $perPage = 50, int $numberOfI { throw new InvalidPaginationException("Pagination can only be created for a positive number of items"); } - - $this->currentPage = $currentPage; $this->numberOfItems = $numberOfItems; $this->perPage = $perPage; - $this->maxPage = (int) \max(1, (int) \ceil($numberOfItems / $perPage)); + $this->maxPage = \max(1, (int) \ceil($numberOfItems / $perPage)); } @@ -144,7 +138,6 @@ public function toArray () : array /** - * @return Pagination */ public function withNumberOfItems (int $numberOfItems) : self { diff --git a/src/Route/DeferredRoute.php b/src/Route/DeferredRoute.php index 5e544cb..530c5d1 100644 --- a/src/Route/DeferredRoute.php +++ b/src/Route/DeferredRoute.php @@ -21,10 +21,7 @@ class DeferredRoute implements LinkableInterface { public const OPTIONAL = true; public const REQUIRED = false; - - private string $route; private array $parameters; - private int $referenceType; /** @@ -32,11 +29,9 @@ class DeferredRoute implements LinkableInterface * @param array $parameters the parameters required for generating the route * @param int $referenceType The reference type to generate for this route */ - public function __construct (string $route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) + public function __construct (private readonly string $route, array $parameters = [], private readonly int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) { - $this->route = $route; $this->parameters = $this->normalizeParameters($parameters); - $this->referenceType = $referenceType; } @@ -121,7 +116,7 @@ public static function generateValue ($value, UrlGeneratorInterface $urlGenerato throw new InvalidRouteActionException(\sprintf( "Can't generate route for value of type '%s', only DeferredRoutes, strings and null are allowed.", - \is_object($value) ? \get_class($value) : \gettype($value) + \get_debug_type($value) )); } diff --git a/src/Search/SimpleEntitySearchHelper.php b/src/Search/SimpleEntitySearchHelper.php index f406e5f..e3348d6 100644 --- a/src/Search/SimpleEntitySearchHelper.php +++ b/src/Search/SimpleEntitySearchHelper.php @@ -12,13 +12,11 @@ final class SimpleEntitySearchHelper { public const MODE_PREFIX = SimpleQueryTokenizer::MODE_PREFIX; public const MODE_EVERYWHERE = SimpleQueryTokenizer::MODE_EVERYWHERE; - private SimpleQueryTokenizer $tokenizer; /** */ - public function __construct (SimpleQueryTokenizer $tokenizer) + public function __construct(private readonly SimpleQueryTokenizer $tokenizer) { - $this->tokenizer = $tokenizer; } diff --git a/src/Search/SimpleQueryTokenizer.php b/src/Search/SimpleQueryTokenizer.php index f19ddec..01f584b 100644 --- a/src/Search/SimpleQueryTokenizer.php +++ b/src/Search/SimpleQueryTokenizer.php @@ -14,7 +14,7 @@ final class SimpleQueryTokenizer /** * Transforms the given raw query to a mysql-ready and queryable query string */ - public function transformToQuery (string $query, bool $mode = self::MODE_PREFIX) + public function transformToQuery (string $query, bool $mode = self::MODE_PREFIX) : string { $query = \trim($query); diff --git a/src/Sortable/PropertiesSortableHandler.php b/src/Sortable/PropertiesSortableHandler.php index 420c20e..c38f9e8 100644 --- a/src/Sortable/PropertiesSortableHandler.php +++ b/src/Sortable/PropertiesSortableHandler.php @@ -13,10 +13,12 @@ */ final class PropertiesSortableHandler { - private SortableHandler $nested; + private readonly SortableHandler $nested; + /** @var string[] */ - private array $properties; - private PropertyAccessor $accessor; + private readonly array $properties; + + private readonly PropertyAccessor $accessor; /** diff --git a/src/Sortable/SortableHandler.php b/src/Sortable/SortableHandler.php index a2c8774..f47ab78 100644 --- a/src/Sortable/SortableHandler.php +++ b/src/Sortable/SortableHandler.php @@ -8,14 +8,8 @@ final class SortableHandler { - private EntityRepository $repository; - - - /** - */ - public function __construct (EntityRepository $repository) + public function __construct(private readonly EntityRepository $repository) { - $this->repository = $repository; } @@ -82,7 +76,7 @@ public function sortElementBefore ( // no $before reference element given, it should be moved to the end // -> just use next index - if (null === $before) + if (!$before instanceof SortableEntityInterface) { $entity->setSortOrder($index); } diff --git a/src/Stats/NestedStatsCounter.php b/src/Stats/NestedStatsCounter.php index 2c44c3b..0387221 100644 --- a/src/Stats/NestedStatsCounter.php +++ b/src/Stats/NestedStatsCounter.php @@ -4,14 +4,12 @@ final class NestedStatsCounter implements StatsCounterInterface { - private StatsCounterInterface $base; - private string $prefix; + private readonly string $prefix; /** */ - public function __construct (StatsCounterInterface $base, string $prefix) + public function __construct (private readonly StatsCounterInterface $base, string $prefix) { - $this->base = $base; $this->prefix = \rtrim($prefix) . " "; } diff --git a/src/Stats/StatsCounter.php b/src/Stats/StatsCounter.php index 7c2d24a..953c3af 100644 --- a/src/Stats/StatsCounter.php +++ b/src/Stats/StatsCounter.php @@ -116,9 +116,9 @@ public function render (SymfonyStyle $io, ?bool $showDebug = null) : void } $rows = \array_map( - function (array $row) + static function (array $row) : array { - $row[0] = "{$row[0]}"; + $row[0] = \sprintf('%s', $row[0]); return $row; }, $this->toArray() @@ -130,19 +130,19 @@ function (array $row) foreach ($this->critical as $line) { - $listing[] = "CRITICAL {$line}"; + $listing[] = 'CRITICAL ' . $line; } foreach ($this->warnings as $line) { - $listing[] = "WARNING {$line}"; + $listing[] = 'WARNING ' . $line; } if ($showDebug) { foreach ($this->debug as $line) { - $listing[] = "DEBUG {$line}"; + $listing[] = 'DEBUG ' . $line; } } diff --git a/src/Tags/TagMatcher.php b/src/Tags/TagMatcher.php index cbc4c95..01d9090 100644 --- a/src/Tags/TagMatcher.php +++ b/src/Tags/TagMatcher.php @@ -13,17 +13,14 @@ class TagMatcher public const HAS_ANY_TAG = false; public const HAS_ALL_TAGS = true; - private array $tags; - private string $selector; - private bool $selectionMode; + private readonly array $tags; + private bool $mustJoin = true; - public function __construct (iterable $tags, string $selector, bool $selectionMode = self::HAS_ALL_TAGS) + public function __construct (iterable $tags, private readonly string $selector, private readonly bool $selectionMode = self::HAS_ALL_TAGS) { $this->tags = self::normalizeTagList($tags); - $this->selectionMode = $selectionMode; - $this->selector = $selector; } @@ -124,7 +121,7 @@ public static function normalizeTagList (iterable $tags) : array throw new TagNormalizationException(\sprintf( "Can't transform value of type '%s'.", - \is_object($tag) ? \get_class($tag) : \gettype($tag) + \get_debug_type($tag) )); } diff --git a/src/Translation/BackendTranslator.php b/src/Translation/BackendTranslator.php index fc40f8b..8b7a03a 100644 --- a/src/Translation/BackendTranslator.php +++ b/src/Translation/BackendTranslator.php @@ -9,14 +9,8 @@ */ class BackendTranslator { - private TranslatorInterface $translator; - - - /** - */ - public function __construct (TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } @@ -34,7 +28,7 @@ public function t (?string $id, array $parameters = [], ?string $locale = null) /** * Translates all messages. * - * @param (string|null|array)[] $messages + * @param (string|array|null)[] $messages * * @return (string|null)[] */ diff --git a/src/Translation/DeferredTranslation.php b/src/Translation/DeferredTranslation.php index 5acfda0..b3ff849 100644 --- a/src/Translation/DeferredTranslation.php +++ b/src/Translation/DeferredTranslation.php @@ -18,21 +18,14 @@ class DeferredTranslation public const OPTIONAL = true; public const REQUIRED = false; - private string $id; - private array $parameters; - private string $domain; - /** * @param string $id Translation key #TranslationKey * @param array $parameters Translation parameters * @param string $domain Translation domain #TranslationDomain */ - public function __construct (string $id, array $parameters = [], string $domain = "messages") + public function __construct(private readonly string $id, private array $parameters = [], private readonly string $domain = "messages") { - $this->id = $id; - $this->parameters = $parameters; - $this->domain = $domain; } @@ -101,7 +94,7 @@ public static function translateValue ($value, TranslatorInterface $translator) throw new InvalidTranslationActionException(\sprintf( "Can't translate value of type '%s', only DeferredTranslations, strings and null are allowed.", - \is_object($value) ? \get_class($value) : \gettype($value) + \get_debug_type($value) )); } @@ -177,5 +170,6 @@ public static function backend (string $id, array $parameters = []) : self { return new self($id, $parameters, "backend"); } + //endregion } diff --git a/src/Twig/RadTwigExtension.php b/src/Twig/RadTwigExtension.php index f761fe7..5327b46 100644 --- a/src/Twig/RadTwigExtension.php +++ b/src/Twig/RadTwigExtension.php @@ -14,27 +14,15 @@ class RadTwigExtension extends AbstractExtension { - private DataContainer $dataContainer; - private TranslatorInterface $translator; - private ?LinkableHandlerInterface $linkableHandler; - - - public function __construct ( - DataContainer $dataContainer, - TranslatorInterface $translator, - ?LinkableHandlerInterface $linkableHandler = null - ) + public function __construct(private readonly DataContainer $dataContainer, private readonly TranslatorInterface $translator, private readonly ?LinkableHandlerInterface $linkableHandler = null) { - $this->dataContainer = $dataContainer; - $this->translator = $translator; - $this->linkableHandler = $linkableHandler; } public function appendToKey (array $map, string $key, string $append) : array { $value = $map[$key] ?? ""; - $map[$key] = \trim("{$value} {$append}"); + $map[$key] = \trim(\sprintf('%s %s', $value, $append)); return $map; } @@ -104,9 +92,9 @@ public function linkableUrl ($link) : ?string return $this->linkableHandler->generateUrl($link); } - catch (UnexpectedTypeException $e) + catch (UnexpectedTypeException $unexpectedTypeException) { - throw new \LogicException("Could not generate URL for LinkableInterface due to an error.", 500, $e); + throw new \LogicException("Could not generate URL for LinkableInterface due to an error.", 500, $unexpectedTypeException); } } diff --git a/tests/Ajax/AjaxResponseBuilderTest.php b/tests/Ajax/AjaxResponseBuilderTest.php index c504e44..eb3a93b 100644 --- a/tests/Ajax/AjaxResponseBuilderTest.php +++ b/tests/Ajax/AjaxResponseBuilderTest.php @@ -362,7 +362,7 @@ public function provideDefaultStatus () : iterable /** * @dataProvider provideDefaultStatus */ - public function testDefaultStatus (bool $ok, string $expected) + public function testDefaultStatus (bool $ok, string $expected): void { $builder = new AjaxResponseBuilder( $this->getMockBuilder(TranslatorInterface::class)->disableOriginalConstructor()->getMock(), diff --git a/tests/Form/DeferredFormTest.php b/tests/Form/DeferredFormTest.php index fcda6bd..997ff19 100644 --- a/tests/Form/DeferredFormTest.php +++ b/tests/Form/DeferredFormTest.php @@ -32,9 +32,6 @@ public function testGenerate () : void } - /** - * @return iterable - */ public function provideCloneWithOptions () : iterable { yield "simple merge" => [ diff --git a/tests/Html/DataContainerTest.php b/tests/Html/DataContainerTest.php index cf9d11f..57c03fa 100644 --- a/tests/Html/DataContainerTest.php +++ b/tests/Html/DataContainerTest.php @@ -20,6 +20,7 @@ public function testRender () : void $dataContainer->renderToHtml(["" => 2], "test") ); } + /** * */ diff --git a/tests/Pagination/Data/PaginationTest.php b/tests/Pagination/Data/PaginationTest.php index 096767d..7f1ca91 100644 --- a/tests/Pagination/Data/PaginationTest.php +++ b/tests/Pagination/Data/PaginationTest.php @@ -7,9 +7,6 @@ class PaginationTest extends TestCase { - /** - * @return array - */ public function provideValidMaxPage () : array { return [ @@ -26,10 +23,6 @@ public function provideValidMaxPage () : array /** * @dataProvider provideValidMaxPage - * - * @param int $numberOfItems - * @param int $itemsPerPage - * @param int $expectedMaxPage */ public function testValidMaxPage (int $numberOfItems, int $itemsPerPage, int $expectedMaxPage) : void { @@ -38,9 +31,6 @@ public function testValidMaxPage (int $numberOfItems, int $itemsPerPage, int $ex } - /** - * @return array - */ public function provideInvalid () : array { return [ @@ -53,9 +43,6 @@ public function provideInvalid () : array /** * @dataProvider provideInvalid - * - * @param int $numberOfItems - * @param int $itemsPerPage */ public function testInvalid (int $numberOfItems, int $itemsPerPage) : void { @@ -96,9 +83,6 @@ public function testPreserveCurrentPage () : void } - /** - * @return array - */ public function provideCurrent () : array { return [ diff --git a/tests/Path/PathHelperTest.php b/tests/Path/PathHelperTest.php index b1d5acf..243bdb2 100644 --- a/tests/Path/PathHelperTest.php +++ b/tests/Path/PathHelperTest.php @@ -7,10 +7,7 @@ class PathHelperTest extends TestCase { - /** - * @return array - */ - public function providerVariations () + public function providerVariations (): array { return [ [["a", "b", "c"], "a/b/c"], diff --git a/tests/Route/DeferredRouteTest.php b/tests/Route/DeferredRouteTest.php index ac285bf..ea290a7 100644 --- a/tests/Route/DeferredRouteTest.php +++ b/tests/Route/DeferredRouteTest.php @@ -31,9 +31,6 @@ public function testGenerate () : void } - /** - * @return iterable - */ public function provideCloneWithParameters () : iterable { yield "simple merge" => [ @@ -80,7 +77,7 @@ public function testEntityInterfaceSupport () : void { $entity = new class implements EntityInterface { - public function getId () : ?int { return 123; } + public function getId () : int { return 123; } public function isNew () : bool { return false; } }; @@ -106,13 +103,13 @@ public function testEntityInterfaceSupportWhenCloning () : void { $entity1 = new class implements EntityInterface { - public function getId () : ?int { return 123; } + public function getId () : int { return 123; } public function isNew () : bool { return false; } }; $entity2 = new class implements EntityInterface { - public function getId () : ?int { return 234; } + public function getId () : int { return 234; } public function isNew () : bool { return false; } }; @@ -156,7 +153,7 @@ public function provideValidRouteValue () : \Generator * * @param mixed $value */ - public function testValidRouteValue ($value, ?string $expected) : void + public function testValidRouteValue (string|DeferredRoute|null $value, ?string $expected) : void { $router = $this->getMockBuilder(RouterInterface::class) ->getMock(); @@ -187,7 +184,7 @@ public function provideInvalidRouteValue () : \Generator * * @param mixed $value */ - public function testInvalidRouteValue ($value) : void + public function testInvalidRouteValue (bool|int|\stdClass $value) : void { $this->expectException(InvalidRouteActionException::class); @@ -218,7 +215,7 @@ public function provideValueVariations () : iterable /** * @dataProvider provideValueVariations */ - public function testIsValid (bool $expected, $value, bool $isOptional) : void + public function testIsValid (bool $expected, string|DeferredRoute|int|bool|null $value, bool $isOptional) : void { self::assertSame($expected, DeferredRoute::isValidValue($value, $isOptional)); } @@ -227,7 +224,7 @@ public function testIsValid (bool $expected, $value, bool $isOptional) : void /** * @dataProvider provideValueVariations */ - public function testEnsureValid (bool $shouldBeOk, $value, bool $isOptional) : void + public function testEnsureValid (bool $shouldBeOk, string|DeferredRoute|int|bool|null $value, bool $isOptional) : void { if (!$shouldBeOk) { diff --git a/tests/Sortable/PropertiesSortableHandlerTest.php b/tests/Sortable/PropertiesSortableHandlerTest.php index dcb7baf..3bdf68c 100644 --- a/tests/Sortable/PropertiesSortableHandlerTest.php +++ b/tests/Sortable/PropertiesSortableHandlerTest.php @@ -56,6 +56,7 @@ public function testNextSortOrderEmpty () : void $sortable = new PropertiesSortableHandler($repository); $sortable->setNextSortOrder($entity); } + //endregion @@ -97,5 +98,6 @@ public function testSortElementBeforeInvalid () : void $sortable = new PropertiesSortableHandler($repository, "a"); self::assertFalse($sortable->sortElementBefore($entity, $before)); } + //endregion } diff --git a/tests/Sortable/SortableHandlerTest.php b/tests/Sortable/SortableHandlerTest.php index 6eacd56..f308dab 100644 --- a/tests/Sortable/SortableHandlerTest.php +++ b/tests/Sortable/SortableHandlerTest.php @@ -16,9 +16,6 @@ class SortableHandlerTest extends TestCase use SortableTestTrait; //region Next Sort Order - /** - * @return array - */ public function provideNextSortOrder () : array { return [ @@ -31,9 +28,6 @@ public function provideNextSortOrder () : array /** * @dataProvider provideNextSortOrder - * - * @param int|null $returnValue - * @param int $expected */ public function testNextSortOrder (?int $returnValue, int $expected) : void { @@ -61,6 +55,7 @@ public function testNextSortOrder (?int $returnValue, int $expected) : void self::assertSame($expected, $sortable->getNextSortOrder()); } + //endregion @@ -110,6 +105,7 @@ public function testFixSortOrderExcludedNeverCalled () : void $sortable = new SortableHandler($repository); $sortable->fixSortOrder([$entityExcluded1, $entityExcluded2]); } + //endregion @@ -198,6 +194,7 @@ public function testSortElementBeforeSelf () : void $success = $sortable->sortElementBefore($entity, $entity); self::assertFalse($success); } + //endregion @@ -266,5 +263,6 @@ public function testWherePassing () : void "t.obj = :where_value_2", ], $andX->getParts()); } + //endregion } diff --git a/tests/Sortable/SortableTestTrait.php b/tests/Sortable/SortableTestTrait.php index 4bc0fb2..5d1e953 100644 --- a/tests/Sortable/SortableTestTrait.php +++ b/tests/Sortable/SortableTestTrait.php @@ -10,27 +10,17 @@ trait SortableTestTrait { - /** - * @param int $id - * @param int|null $sortOrder - * - * @return SortableEntityInterface - */ private function createEntity (int $id, ?int $sortOrder = null) : SortableEntityInterface { return new class ($id, $sortOrder) implements SortableEntityInterface { - private int $id; - private ?int $sortOrder; - public function __construct (int $id, ?int $sortOrder = null) + public function __construct(private readonly int $id, private ?int $sortOrder = null) { - $this->id = $id; - $this->sortOrder = $sortOrder; } - public function getId () : ?int + public function getId () : int { return $this->id; } @@ -55,33 +45,16 @@ public function setSortOrder (int $sortOrder) : void }; } - /** - * @param int $id - * @param int|null $sortOrder - * - * @return SortableEntityInterface - */ private function createEntityWithProperties (int $id, $a, $b, $c, ?int $sortOrder = null) : SortableEntityInterface { return new class ($id, $sortOrder, $a, $b, $c) implements SortableEntityInterface { - private int $id; - private ?int $sortOrder; - private $a; - private $b; - private $c; - - public function __construct (int $id, ?int $sortOrder, $a, $b, $c) + public function __construct(private readonly int $id, private ?int $sortOrder, private $a, private $b, private $c) { - $this->id = $id; - $this->sortOrder = $sortOrder; - $this->a = $a; - $this->b = $b; - $this->c = $c; } - public function getId () : ?int + public function getId () : int { return $this->id; } @@ -122,11 +95,6 @@ public function getC () } - /** - * @param int $number - * - * @return array - */ private function createEntities (int $number) : array { $result = []; @@ -142,8 +110,6 @@ private function createEntities (int $number) : array /** * @param SortableEntityInterface[] $entities - * - * @return array */ private function mapEntities (array $entities) : array { @@ -188,7 +154,7 @@ private function createIteratingRepository (SortableEntityInterface ...$entities \usort( $entities, - static fn (SortableEntityInterface $left, SortableEntityInterface $right) => $left->getSortOrder() - $right->getSortOrder() + static fn (SortableEntityInterface $left, SortableEntityInterface $right): int => $left->getSortOrder() - $right->getSortOrder() ); $query diff --git a/tests/Translation/DeferredTranslationTest.php b/tests/Translation/DeferredTranslationTest.php index 20169f3..fd9f1c2 100644 --- a/tests/Translation/DeferredTranslationTest.php +++ b/tests/Translation/DeferredTranslationTest.php @@ -29,9 +29,6 @@ public function testTranslate () : void } - /** - * @return iterable - */ public function provideCloneWithParameters () : iterable { yield "simple merge" => [ @@ -90,7 +87,7 @@ public function provideValidTranslateValue () : \Generator * * @param mixed $value */ - public function testValidTranslateValue ($value, ?string $expected) : void + public function testValidTranslateValue (string|DeferredTranslation|null $value, ?string $expected) : void { $translator = $this->getMockBuilder(TranslatorInterface::class) ->getMock(); @@ -121,7 +118,7 @@ public function provideInvalidTranslateValue () : \Generator * * @param mixed $value */ - public function testInvalidTranslateValue ($value) : void + public function testInvalidTranslateValue (bool|int|\stdClass $value) : void { $this->expectException(InvalidTranslationActionException::class); @@ -152,7 +149,7 @@ public function provideValueVariations () : iterable /** * @dataProvider provideValueVariations */ - public function testIsValidValue (bool $expected, $value, bool $required) : void + public function testIsValidValue (bool $expected, string|DeferredTranslation|int|bool|null $value, bool $required) : void { self::assertSame($expected, DeferredTranslation::isValidValue($value, $required)); } @@ -161,7 +158,7 @@ public function testIsValidValue (bool $expected, $value, bool $required) : void /** * @dataProvider provideValueVariations */ - public function testEnsureValidValue (bool $shouldBeOk, $value, bool $isOptional) : void + public function testEnsureValidValue (bool $shouldBeOk, string|DeferredTranslation|int|bool|null $value, bool $isOptional) : void { if (!$shouldBeOk) { diff --git a/tests/Twig/RadTwigExtensionTest.php b/tests/Twig/RadTwigExtensionTest.php index f04a6c0..1e759a7 100644 --- a/tests/Twig/RadTwigExtensionTest.php +++ b/tests/Twig/RadTwigExtensionTest.php @@ -29,9 +29,6 @@ public function testAppendToKey () : void } - /** - * @return array - */ public function provideClassnames () : array { return [ @@ -61,9 +58,6 @@ public function provideClassnames () : array /** * @dataProvider provideClassnames - * - * @param array $classnames - * @param string $expected */ public function testClassnames (array $classnames, string $expected) : void {