diff --git a/.gitignore b/.gitignore index faf9368..d6a61c0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ vendor .phpunit.cache tools .php-cs-fixer.cache -.vscode \ No newline at end of file +.vscode +rector.log \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d507a23..c2936c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.3 + +* build: add rector + ## 0.9.2 * fix(orm): `getQueryBuilder()` now clones the query builder diff --git a/Makefile b/Makefile index 5b094c2..b3f2fbc 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,11 @@ php-cs-fixer: tools/php-cs-fixer tools/php-cs-fixer: phive install php-cs-fixer +.PHONY: rector +rector: + $(PHP) vendor/bin/rector process > rector.log + make php-cs-fixer + .PHONY: clean clean: $(PHP) vendor/bin/psalm --clear-cache @@ -38,6 +43,10 @@ clean: monorepo-merge: $(PHP) vendor/bin/monorepo-builder merge +.PHONY: monorepo-release-% +monorepo-release-%: + $(PHP) vendor/bin/monorepo-builder release $* + .PHONY: fixtures: tests/var/data.db diff --git a/composer.json b/composer.json index 10a7e7b..20e36d6 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,8 @@ "bnf/phpstan-psr-container": "^1.0", "psalm/plugin-symfony": "^5.2", "symfony/debug-bundle": "^7.1", - "dama/doctrine-test-bundle": "^8.2" + "dama/doctrine-test-bundle": "^8.2", + "rector/rector": "^1.2" }, "replace": { "rekalogika/collections-common": "0.9.1", diff --git a/packages/collections-common/src/Configuration.php b/packages/collections-common/src/Configuration.php index f8129f4..32c996d 100644 --- a/packages/collections-common/src/Configuration.php +++ b/packages/collections-common/src/Configuration.php @@ -61,8 +61,6 @@ private function __construct() * If the duration of a count operation exceeds this number of seconds, a * deprecation notice will be emitted. Used by `SafeDelegatedCountStrategy`, * Not applicable with other count strategies. - * - * @var float */ public static float $defaultCountDurationThreshold = 2; diff --git a/packages/collections-common/src/Count/SafeDelegatedCountStrategy.php b/packages/collections-common/src/Count/SafeDelegatedCountStrategy.php index 1b29f0c..7c1aa8c 100644 --- a/packages/collections-common/src/Count/SafeDelegatedCountStrategy.php +++ b/packages/collections-common/src/Count/SafeDelegatedCountStrategy.php @@ -20,9 +20,9 @@ class SafeDelegatedCountStrategy implements CountStrategy { public function __construct( - private ?int $softLimit = null, - private ?int $hardLimit = null, - private ?float $durationThreshold = null, + private readonly ?int $softLimit = null, + private readonly ?int $hardLimit = null, + private readonly ?float $durationThreshold = null, ) { } diff --git a/packages/collections-common/src/Internal/ParameterUtil.php b/packages/collections-common/src/Internal/ParameterUtil.php index fca60c5..c733728 100644 --- a/packages/collections-common/src/Internal/ParameterUtil.php +++ b/packages/collections-common/src/Internal/ParameterUtil.php @@ -81,7 +81,7 @@ public static function normalizeOrderBy( $orderBy = [$orderBy => Order::Ascending]; } - if (empty($orderBy)) { + if ($orderBy === []) { throw new UnexpectedValueException('The order by clause cannot be empty.'); } diff --git a/packages/collections-common/src/KeyTransformer/UuidKeyTransformer.php b/packages/collections-common/src/KeyTransformer/UuidKeyTransformer.php index 04da420..54db830 100644 --- a/packages/collections-common/src/KeyTransformer/UuidKeyTransformer.php +++ b/packages/collections-common/src/KeyTransformer/UuidKeyTransformer.php @@ -44,7 +44,7 @@ public function transformToKey(mixed $key): int|string $uuid = new Uuid($key); return $key; - } catch (\InvalidArgumentException $e) { + } catch (\InvalidArgumentException) { throw new NotFoundException(); } } diff --git a/packages/collections-common/src/Trait/ArrayAccessTrait.php b/packages/collections-common/src/Trait/ArrayAccessTrait.php index 7bb12cd..d43b266 100644 --- a/packages/collections-common/src/Trait/ArrayAccessTrait.php +++ b/packages/collections-common/src/Trait/ArrayAccessTrait.php @@ -26,6 +26,7 @@ trait ArrayAccessTrait * @return Collection */ abstract private function getSafeCollection(): Collection; + abstract private function ensureSafety(): void; /** @@ -33,9 +34,6 @@ abstract private function ensureSafety(): void; */ abstract private function getRealCollection(): Collection; - /** - * @param mixed $offset - */ final public function offsetExists(mixed $offset): bool { /** @var TKey */ @@ -47,7 +45,6 @@ final public function offsetExists(mixed $offset): bool } /** - * @param mixed $offset * @return T|null */ final public function offsetGet(mixed $offset): mixed @@ -61,7 +58,6 @@ final public function offsetGet(mixed $offset): mixed } /** - * @param mixed $offset * @param T $value */ final public function offsetSet(mixed $offset, mixed $value): void @@ -80,9 +76,6 @@ final public function offsetSet(mixed $offset, mixed $value): void $this->getRealCollection()->offsetSet($offset, $value); } - /** - * @param mixed $offset - */ final public function offsetUnset(mixed $offset): void { /** @var TKey */ diff --git a/packages/collections-common/src/Trait/CollectionTrait.php b/packages/collections-common/src/Trait/CollectionTrait.php index 5ee41c6..258130f 100644 --- a/packages/collections-common/src/Trait/CollectionTrait.php +++ b/packages/collections-common/src/Trait/CollectionTrait.php @@ -41,6 +41,7 @@ abstract private function getRealCollection(): Collection; * @return Collection */ abstract private function getSafeCollection(): Collection; + abstract private function ensureSafety(): void; /** @@ -58,7 +59,6 @@ final public function clear(): void } /** - * @param mixed $key * @return T|null */ final public function remove(mixed $key): mixed @@ -81,7 +81,6 @@ final public function removeElement(mixed $element): bool } /** - * @param mixed $key * @param T $value */ final public function set(mixed $key, mixed $value): void diff --git a/packages/collections-common/src/Trait/FetchTrait.php b/packages/collections-common/src/Trait/FetchTrait.php index 4f0a08f..66e2dc3 100644 --- a/packages/collections-common/src/Trait/FetchTrait.php +++ b/packages/collections-common/src/Trait/FetchTrait.php @@ -22,7 +22,6 @@ trait FetchTrait { /** - * @param mixed $key * @return T * @throws NotFoundException */ diff --git a/packages/collections-common/src/Trait/MinimalReadableRecollectionTrait.php b/packages/collections-common/src/Trait/MinimalReadableRecollectionTrait.php index 4cd7367..5b1e6b2 100644 --- a/packages/collections-common/src/Trait/MinimalReadableRecollectionTrait.php +++ b/packages/collections-common/src/Trait/MinimalReadableRecollectionTrait.php @@ -49,9 +49,6 @@ final public function contains(mixed $element): bool return $this->getRealCollection()->contains($element); } - /** - * @param mixed $key - */ final public function containsKey(mixed $key): bool { /** @var TKey */ @@ -61,7 +58,6 @@ final public function containsKey(mixed $key): bool } /** - * @param mixed $key * @return T|null */ final public function get(mixed $key): mixed diff --git a/packages/collections-common/src/Trait/ReadableCollectionTrait.php b/packages/collections-common/src/Trait/ReadableCollectionTrait.php index a0eacb8..379d2a4 100644 --- a/packages/collections-common/src/Trait/ReadableCollectionTrait.php +++ b/packages/collections-common/src/Trait/ReadableCollectionTrait.php @@ -55,9 +55,6 @@ final public function isEmpty(): bool return $this->getSafeCollection()->isEmpty(); } - /** - * @param mixed $key - */ final public function containsKey(mixed $key): bool { /** @var TKey */ @@ -67,7 +64,6 @@ final public function containsKey(mixed $key): bool } /** - * @param mixed $key * @return T|null */ final public function get(mixed $key): mixed diff --git a/packages/collections-common/src/Trait/RefreshCountTrait.php b/packages/collections-common/src/Trait/RefreshCountTrait.php index 4188fe7..a4b943a 100644 --- a/packages/collections-common/src/Trait/RefreshCountTrait.php +++ b/packages/collections-common/src/Trait/RefreshCountTrait.php @@ -19,6 +19,7 @@ trait RefreshCountTrait { abstract private function getCountStrategy(): CountStrategy; + abstract private function getUnderlyingCountable(): ?\Countable; /** diff --git a/packages/collections-contracts/src/MinimalReadableRecollection.php b/packages/collections-contracts/src/MinimalReadableRecollection.php index 014e916..51e44d3 100644 --- a/packages/collections-contracts/src/MinimalReadableRecollection.php +++ b/packages/collections-contracts/src/MinimalReadableRecollection.php @@ -30,19 +30,14 @@ interface MinimalReadableRecollection extends PageableInterface */ public function contains(mixed $element): bool; - /** - * @param mixed $key - */ public function containsKey(mixed $key): bool; /** - * @param mixed $key * @return T|null */ public function get(mixed $key): mixed; /** - * @param mixed $key * @return T * @throws NotFoundException */ diff --git a/packages/collections-contracts/src/MinimalReadableRepository.php b/packages/collections-contracts/src/MinimalReadableRepository.php index 2a057a9..c2cf57a 100644 --- a/packages/collections-contracts/src/MinimalReadableRepository.php +++ b/packages/collections-contracts/src/MinimalReadableRepository.php @@ -21,7 +21,6 @@ interface MinimalReadableRepository extends MinimalReadableRecollection { /** - * @param mixed $key * @return T */ public function reference(mixed $key): object; diff --git a/packages/collections-contracts/src/MinimalRepository.php b/packages/collections-contracts/src/MinimalRepository.php index 0d439e8..3de04e0 100644 --- a/packages/collections-contracts/src/MinimalRepository.php +++ b/packages/collections-contracts/src/MinimalRepository.php @@ -22,7 +22,6 @@ interface MinimalRepository extends MinimalReadableRepository, MinimalRecollection { /** - * @param mixed $key * @return T|null */ public function remove(mixed $key): mixed; diff --git a/packages/collections-contracts/src/ReadableRecollection.php b/packages/collections-contracts/src/ReadableRecollection.php index 6e6ab8e..6c0086a 100644 --- a/packages/collections-contracts/src/ReadableRecollection.php +++ b/packages/collections-contracts/src/ReadableRecollection.php @@ -29,10 +29,8 @@ interface ReadableRecollection extends PageableInterface, ReadableCollection // Overridden methods, to widen keys in parameters to accommodate Uuid key // types // - /** * @param mixed $key - * @return bool */ #[\Override] public function containsKey(mixed $key): bool; @@ -47,9 +45,7 @@ public function get(mixed $key): mixed; // // Methods // - /** - * @param mixed $key * @return T * @throws NotFoundException */ diff --git a/packages/collections-contracts/src/ReadableRepository.php b/packages/collections-contracts/src/ReadableRepository.php index dd62f79..f414124 100644 --- a/packages/collections-contracts/src/ReadableRepository.php +++ b/packages/collections-contracts/src/ReadableRepository.php @@ -21,7 +21,6 @@ interface ReadableRepository extends ReadableRecollection { /** - * @param mixed $key * @return T */ public function reference(mixed $key): object; diff --git a/packages/collections-contracts/src/Recollection.php b/packages/collections-contracts/src/Recollection.php index 905c6c0..be04418 100644 --- a/packages/collections-contracts/src/Recollection.php +++ b/packages/collections-contracts/src/Recollection.php @@ -42,29 +42,21 @@ public function remove(mixed $key): mixed; #[\Override] public function set(mixed $key, mixed $value): void; - /** - * @param mixed $offset - */ #[\Override] public function offsetExists(mixed $offset): bool; /** - * @param mixed $offset * @return T|null */ #[\Override] public function offsetGet(mixed $offset): mixed; /** - * @param mixed $offset * @param T $value */ #[\Override] public function offsetSet(mixed $offset, mixed $value): void; - /** - * @param mixed $offset - */ #[\Override] public function offsetUnset(mixed $offset): void; } diff --git a/packages/collections-domain/src/ArrayCollection.php b/packages/collections-domain/src/ArrayCollection.php index 004adab..fac5a53 100644 --- a/packages/collections-domain/src/ArrayCollection.php +++ b/packages/collections-domain/src/ArrayCollection.php @@ -52,7 +52,7 @@ public function matching(Criteria $criteria): Collection&Selectable $orderings = $criteria->orderings(); - if ($orderings) { + if ($orderings !== []) { $next = null; foreach (array_reverse($orderings) as $field => $ordering) { /** @var \Closure(mixed,mixed):int */ diff --git a/packages/collections-domain/src/CriteriaPageable.php b/packages/collections-domain/src/CriteriaPageable.php index a7c49b8..ad4b186 100644 --- a/packages/collections-domain/src/CriteriaPageable.php +++ b/packages/collections-domain/src/CriteriaPageable.php @@ -51,6 +51,7 @@ class CriteriaPageable implements PageableRecollection private readonly Selectable $collection; private readonly Criteria $criteria; + private readonly ?string $indexBy; /** @@ -96,7 +97,6 @@ final private function __construct( * @template ST * @param ReadableCollection|Selectable $collection * @param int<1,max> $itemsPerPage - * @return static */ final public static function create( ReadableCollection|Selectable $collection, diff --git a/packages/collections-domain/src/CriteriaRecollection.php b/packages/collections-domain/src/CriteriaRecollection.php index f131812..c1dfe7f 100644 --- a/packages/collections-domain/src/CriteriaRecollection.php +++ b/packages/collections-domain/src/CriteriaRecollection.php @@ -67,6 +67,7 @@ class CriteriaRecollection implements ReadableRecollection private readonly Selectable $collection; private readonly Criteria $criteria; + private readonly ?string $indexBy; /** @@ -213,7 +214,7 @@ private function getOrderBy(): array { $ordering = $this->criteria->orderings(); - if (empty($ordering)) { + if ($ordering === []) { return ['id' => Order::Descending]; } diff --git a/packages/collections-domain/src/Internal/DirectClosureExpressionVisitor.php b/packages/collections-domain/src/Internal/DirectClosureExpressionVisitor.php index 098a644..85ed983 100644 --- a/packages/collections-domain/src/Internal/DirectClosureExpressionVisitor.php +++ b/packages/collections-domain/src/Internal/DirectClosureExpressionVisitor.php @@ -68,7 +68,7 @@ public static function getObjectFieldValue(object|array $object, string $field) */ public static function sortByField(string $name, int $orientation = 1, \Closure|null $next = null) { - if (!$next) { + if ($next === null) { $next = static fn (): int => 0; } @@ -184,6 +184,6 @@ private function orExpressions(array $expressions): \Closure /** @param callable[] $expressions */ private function notExpression(array $expressions): \Closure { - return static fn ($object) => !$expressions[0]($object); + return static fn ($object): bool => !$expressions[0]($object); } } diff --git a/packages/collections-domain/src/MinimalCriteriaRecollection.php b/packages/collections-domain/src/MinimalCriteriaRecollection.php index 517dc96..5f97da9 100644 --- a/packages/collections-domain/src/MinimalCriteriaRecollection.php +++ b/packages/collections-domain/src/MinimalCriteriaRecollection.php @@ -53,6 +53,7 @@ class MinimalCriteriaRecollection implements MinimalReadableRecollection private readonly Selectable $collection; private readonly Criteria $criteria; + private readonly ?string $indexBy; /** diff --git a/packages/collections-domain/src/MinimalRecollectionDecorator.php b/packages/collections-domain/src/MinimalRecollectionDecorator.php index 4a7d2c0..cc95ae2 100644 --- a/packages/collections-domain/src/MinimalRecollectionDecorator.php +++ b/packages/collections-domain/src/MinimalRecollectionDecorator.php @@ -56,6 +56,7 @@ class MinimalRecollectionDecorator implements MinimalRecollection private readonly array $orderBy; private readonly ?string $indexBy; + private readonly Criteria $criteria; /** @@ -209,7 +210,7 @@ final protected function createCriteriaRecollection( ?CountStrategy $count = null, ): MinimalCriteriaRecollection { // if $criteria has no orderings, add the current ordering - if (\count($criteria->orderings()) === 0) { + if ($criteria->orderings() === []) { $criteria = $criteria->orderBy($this->orderBy); } @@ -231,7 +232,7 @@ final protected function createCriteriaPageable( ?CountStrategy $count = null, ): PageableRecollection { // if $criteria has no orderings, add the current ordering - if (\count($criteria->orderings()) === 0) { + if ($criteria->orderings() === []) { $criteria = $criteria->orderBy($this->orderBy); } diff --git a/packages/collections-domain/src/RecollectionDecorator.php b/packages/collections-domain/src/RecollectionDecorator.php index e082ab8..a4454a1 100644 --- a/packages/collections-domain/src/RecollectionDecorator.php +++ b/packages/collections-domain/src/RecollectionDecorator.php @@ -76,6 +76,7 @@ class RecollectionDecorator implements Recollection private readonly array $orderBy; private readonly ?string $indexBy; + private readonly Criteria $criteria; /** diff --git a/packages/collections-domain/src/Trait/CriteriaReadableTrait.php b/packages/collections-domain/src/Trait/CriteriaReadableTrait.php index 0c30eb0..7dcf85c 100644 --- a/packages/collections-domain/src/Trait/CriteriaReadableTrait.php +++ b/packages/collections-domain/src/Trait/CriteriaReadableTrait.php @@ -42,9 +42,6 @@ final public function contains(mixed $element): bool return $this->getSafeCollection()->contains($element); } - /** - * @param mixed $key - */ final public function containsKey(mixed $key): bool { /** @var TKey */ @@ -54,7 +51,6 @@ final public function containsKey(mixed $key): bool } /** - * @param mixed $key * @return T|null */ final public function get(mixed $key): mixed diff --git a/packages/collections-domain/src/Trait/ReadableExtraLazyTrait.php b/packages/collections-domain/src/Trait/ReadableExtraLazyTrait.php index 619ee6a..6a80099 100644 --- a/packages/collections-domain/src/Trait/ReadableExtraLazyTrait.php +++ b/packages/collections-domain/src/Trait/ReadableExtraLazyTrait.php @@ -52,9 +52,6 @@ final public function contains(mixed $element): bool return $this->getSafeCollection()->contains($element); } - /** - * @param mixed $key - */ final public function containsKey(mixed $key): bool { /** @var TKey */ @@ -68,7 +65,6 @@ final public function containsKey(mixed $key): bool } /** - * @param mixed $key * @return T|null */ final public function get(mixed $key): mixed diff --git a/packages/collections-domain/src/Trait/RecollectionDxTrait.php b/packages/collections-domain/src/Trait/RecollectionDxTrait.php index b568bac..a810d2c 100644 --- a/packages/collections-domain/src/Trait/RecollectionDxTrait.php +++ b/packages/collections-domain/src/Trait/RecollectionDxTrait.php @@ -45,7 +45,7 @@ final protected function createCriteriaRecollection( ?CountStrategy $count = null, ): CriteriaRecollection { // if $criteria has no orderings, add the current ordering - if (\count($criteria->orderings()) === 0) { + if ($criteria->orderings() === []) { $criteria = $criteria->orderBy($this->getOrderBy()); } @@ -69,7 +69,7 @@ final protected function createCriteriaPageable( ?CountStrategy $count = null, ): PageableRecollection { // if $criteria has no orderings, add the current ordering - if (\count($criteria->orderings()) === 0) { + if ($criteria->orderings() === []) { $criteria = $criteria->orderBy($this->getOrderBy()); } diff --git a/packages/collections-domain/src/Trait/SafetyCheckTrait.php b/packages/collections-domain/src/Trait/SafetyCheckTrait.php index 47e5506..d59acb4 100644 --- a/packages/collections-domain/src/Trait/SafetyCheckTrait.php +++ b/packages/collections-domain/src/Trait/SafetyCheckTrait.php @@ -23,6 +23,7 @@ trait SafetyCheckTrait { private ?bool $isSafe = null; + private ?bool $isSafeWithIndex = null; /** diff --git a/packages/collections-orm/src/AbstractMinimalRepository.php b/packages/collections-orm/src/AbstractMinimalRepository.php index d64f37c..59962c8 100644 --- a/packages/collections-orm/src/AbstractMinimalRepository.php +++ b/packages/collections-orm/src/AbstractMinimalRepository.php @@ -57,6 +57,7 @@ abstract class AbstractMinimalRepository implements MinimalRepository private readonly array $orderBy; private readonly ?string $indexBy; + private ?EntityManagerInterface $entityManager = null; /** @@ -80,7 +81,7 @@ public function __construct( // set index by $identifiers = $this->getEntityManager() - ->getClassMetadata($this->getClass()) + ->getClassMetadata($this->class) ->getIdentifier(); if (\count($identifiers) !== 1) { diff --git a/packages/collections-orm/src/AbstractRepository.php b/packages/collections-orm/src/AbstractRepository.php index 1d70371..0ee19df 100644 --- a/packages/collections-orm/src/AbstractRepository.php +++ b/packages/collections-orm/src/AbstractRepository.php @@ -64,6 +64,7 @@ abstract class AbstractRepository implements Repository private readonly array $orderBy; private readonly ?string $indexBy; + private ?EntityManagerInterface $entityManager = null; /** @@ -92,7 +93,7 @@ public function __construct( // set index by $identifiers = $this->getEntityManager() - ->getClassMetadata($this->getClass()) + ->getClassMetadata($this->class) ->getIdentifier(); if (\count($identifiers) !== 1) { diff --git a/packages/collections-orm/src/QueryPageable.php b/packages/collections-orm/src/QueryPageable.php index 876d306..948a722 100644 --- a/packages/collections-orm/src/QueryPageable.php +++ b/packages/collections-orm/src/QueryPageable.php @@ -81,7 +81,6 @@ final public function getQueryBuilder(): QueryBuilder /** * @param \Closure(QueryBuilder):void $function - * @return static */ final public function updateQueryBuilder(\Closure $function): static { diff --git a/packages/collections-orm/src/QueryRecollection.php b/packages/collections-orm/src/QueryRecollection.php index 0bcf6b1..6355340 100644 --- a/packages/collections-orm/src/QueryRecollection.php +++ b/packages/collections-orm/src/QueryRecollection.php @@ -114,7 +114,6 @@ final public function getQueryBuilder(): QueryBuilder /** * @param \Closure(QueryBuilder):void $function - * @return static */ final public function updateQueryBuilder(\Closure $function): static { diff --git a/packages/collections-orm/src/Trait/MinimalReadableRepositoryTrait.php b/packages/collections-orm/src/Trait/MinimalReadableRepositoryTrait.php index c9414d0..7f1558d 100644 --- a/packages/collections-orm/src/Trait/MinimalReadableRepositoryTrait.php +++ b/packages/collections-orm/src/Trait/MinimalReadableRepositoryTrait.php @@ -47,7 +47,6 @@ abstract private function getEntityManager(): EntityManagerInterface; abstract private function getClass(): string; /** - * @param mixed $key * @return T */ public function reference(mixed $key): object @@ -71,16 +70,12 @@ public function contains(mixed $element): bool return $this->getEntityManager()->contains($element); } - /** - * @param mixed $key - */ public function containsKey(mixed $key): bool { return $this->get($key) !== null; } /** - * @param mixed $key * @return T|null */ public function get(mixed $key): mixed diff --git a/packages/collections-orm/src/Trait/MinimalRepositoryTrait.php b/packages/collections-orm/src/Trait/MinimalRepositoryTrait.php index 91e8592..a74b786 100644 --- a/packages/collections-orm/src/Trait/MinimalRepositoryTrait.php +++ b/packages/collections-orm/src/Trait/MinimalRepositoryTrait.php @@ -49,7 +49,6 @@ public function removeElement(mixed $element): bool } /** - * @param mixed $key * @return T|null */ public function remove(mixed $key): mixed diff --git a/packages/collections-orm/src/Trait/RepositoryDxTrait.php b/packages/collections-orm/src/Trait/RepositoryDxTrait.php index 8a07aeb..d22524c 100644 --- a/packages/collections-orm/src/Trait/RepositoryDxTrait.php +++ b/packages/collections-orm/src/Trait/RepositoryDxTrait.php @@ -80,7 +80,7 @@ final protected function createCriteriaRecollection( ?CountStrategy $count = null, ): CriteriaRecollection { // if $criteria has no orderings, add the current ordering - if (\count($criteria->orderings()) === 0) { + if ($criteria->orderings() === []) { $criteria = $criteria->orderBy($this->orderBy); } diff --git a/packages/collections-orm/src/Trait/RepositoryTrait.php b/packages/collections-orm/src/Trait/RepositoryTrait.php index 5925c57..0a7acad 100644 --- a/packages/collections-orm/src/Trait/RepositoryTrait.php +++ b/packages/collections-orm/src/Trait/RepositoryTrait.php @@ -41,9 +41,6 @@ final public function clear(): void } } - /** - * @param mixed $offset - */ final public function offsetExists(mixed $offset): bool { /** @var TKey */ @@ -53,7 +50,6 @@ final public function offsetExists(mixed $offset): bool } /** - * @param mixed $offset * @return T|null */ final public function offsetGet(mixed $offset): mixed @@ -65,7 +61,6 @@ final public function offsetGet(mixed $offset): mixed } /** - * @param mixed $offset * @param T $value */ final public function offsetSet(mixed $offset, mixed $value): void @@ -77,9 +72,6 @@ final public function offsetSet(mixed $offset, mixed $value): void $this->add($value); } - /** - * @param mixed $offset - */ final public function offsetUnset(mixed $offset): void { /** @var TKey */ @@ -89,7 +81,6 @@ final public function offsetUnset(mixed $offset): void } /** - * @param mixed $key * @param T $value */ final public function set(mixed $key, mixed $value): void diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..42283eb --- /dev/null +++ b/rector.php @@ -0,0 +1,94 @@ +withPaths([ + __DIR__ . '/packages', + __DIR__ . '/tests/bin', + __DIR__ . '/tests/config', + __DIR__ . '/tests/public', + __DIR__ . '/tests/src', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + strictBooleans: true, + symfonyCodeQuality: true, + doctrineCodeQuality: true, + ) + ->withPhpSets(php82: true) + ->withRules([ + // AddOverrideAttributeToOverriddenMethodsRector::class, + ]) + ->withSkip([ + RemoveUselessParamTagRector::class => [ + // static analysis tools don't like this + __DIR__ . '/packages/collections-contracts/src/ReadableRecollection.php', + __DIR__ . '/packages/collections-contracts/src/Recollection.php', + ], + RemoveUselessReturnTagRector::class => [ + // static analysis tools don't like this + __DIR__ . '/packages/collections-common/src/Trait/ReadableCollectionTrait.php', + __DIR__ . '/packages/collections-common/src/Trait/MinimalReadableRecollectionTrait.php', + __DIR__ . '/packages/collections-common/src/Trait/ReadableRecollectionTrait.php', + __DIR__ . '/packages/collections-contracts/src/MinimalReadableRecollection.php', + __DIR__ . '/packages/collections-domain/src/Trait/CriteriaReadableTrait.php', + __DIR__ . '/packages/collections-domain/src/Trait/ReadableExtraLazyTrait.php', + __DIR__ . '/packages/collections-orm/src/Trait/MinimalReadableRepositoryTrait.php', + ], + + RemoveUnusedPublicMethodParameterRector::class => [ + // @todo temporary + __DIR__ . '/packages/collections-domain/src/Internal/ExtraLazyDetector.php', + ], + + // static analysis tools don't like this + RemoveNonExistingVarAnnotationRector::class, + + RemoveExtraParametersRector::class => [ + // @todo temporary + __DIR__ . '/packages/collections-domain/src/Internal/ExtraLazyDetector.php', + ], + + // static analysis tools don't like this + RemoveUnusedVariableAssignRector::class, + + // cognitive burden to many people + SimplifyIfElseToTernaryRector::class, + + CombineIfRector::class => [ + // this 'fixes' symfony makerbundle boilerplate code + __DIR__ . '/tests/src/App/Entity/*', + ], + + // potential cognitive burden + FlipTypeControlToUseExclusiveTypeRector::class, + + // results in too long variables + CatchExceptionNameMatchingTypeRector::class, + + // makes code unreadable + DisallowedShortTernaryRuleFixerRector::class, + + // unsafe + SeparateMultiUseImportsRector::class, + ]); diff --git a/tests/src/App/DataFixtures/AppFixtures.php b/tests/src/App/DataFixtures/AppFixtures.php index 774598f..6f34917 100644 --- a/tests/src/App/DataFixtures/AppFixtures.php +++ b/tests/src/App/DataFixtures/AppFixtures.php @@ -37,17 +37,17 @@ public function load(ObjectManager $manager): void CitizenFactory::createMany(2020, [ 'country' => $countrySy, - 'age' => rand(1, 14), + 'age' => random_int(1, 14), ]); CitizenFactory::createMany(2020, [ 'country' => $countrySy, - 'age' => rand(16, 63), + 'age' => random_int(16, 63), ]); CitizenFactory::createMany(2020, [ 'country' => $countrySy, - 'age' => rand(65, 100), + 'age' => random_int(65, 100), ]); // medium set @@ -59,17 +59,17 @@ public function load(ObjectManager $manager): void CitizenFactory::createMany(550, [ 'country' => $countrySt, - 'age' => rand(1, 14), + 'age' => random_int(1, 14), ]); CitizenFactory::createMany(550, [ 'country' => $countrySt, - 'age' => rand(16, 63), + 'age' => random_int(16, 63), ]); CitizenFactory::createMany(550, [ 'country' => $countrySt, - 'age' => rand(65, 100), + 'age' => random_int(65, 100), ]); // small set @@ -81,17 +81,17 @@ public function load(ObjectManager $manager): void CitizenFactory::createMany(10, [ 'country' => $countrySd, - 'age' => rand(1, 14), + 'age' => random_int(1, 14), ]); CitizenFactory::createMany(10, [ 'country' => $countrySd, - 'age' => rand(16, 63), + 'age' => random_int(16, 63), ]); CitizenFactory::createMany(10, [ 'country' => $countrySd, - 'age' => rand(65, 100), + 'age' => random_int(65, 100), ]); $manager->flush(); diff --git a/tests/src/App/Entity/Country.php b/tests/src/App/Entity/Country.php index fa8ad86..17fdc08 100644 --- a/tests/src/App/Entity/Country.php +++ b/tests/src/App/Entity/Country.php @@ -77,7 +77,7 @@ public function getRawCitizens(): Collection return $this->citizens; } - private static function getWorkingAgeCriteria(): Criteria + private function getWorkingAgeCriteria(): Criteria { return Criteria::create() ->where(Criteria::expr()->gte('age', 15)) @@ -113,7 +113,7 @@ public function getWorkingAgeCitizensInRecollection(): ReadableRecollection { return CriteriaRecollection::create( collection: $this->citizens, - criteria: self::getWorkingAgeCriteria(), + criteria: $this->getWorkingAgeCriteria(), indexBy: 'id', instanceId: __METHOD__, ); @@ -126,7 +126,7 @@ public function getWorkingAgeCitizensInMinimalRecollection(): MinimalReadableRec { return MinimalCriteriaRecollection::create( collection: $this->citizens, - criteria: self::getWorkingAgeCriteria(), + criteria: $this->getWorkingAgeCriteria(), indexBy: 'id', instanceId: __METHOD__, ); diff --git a/tests/src/IntegrationTests/Base/BaseRecollectionTestCase.php b/tests/src/IntegrationTests/Base/BaseRecollectionTestCase.php index bead3d8..befadfe 100644 --- a/tests/src/IntegrationTests/Base/BaseRecollectionTestCase.php +++ b/tests/src/IntegrationTests/Base/BaseRecollectionTestCase.php @@ -28,8 +28,11 @@ abstract class BaseRecollectionTestCase extends KernelTestCase * @return R */ abstract protected function getObject(): mixed; + abstract protected function isSafe(): bool; + abstract protected function isSingleton(): bool; + abstract protected function getExpectedTotal(): int; protected function getEntityManager(): EntityManagerInterface diff --git a/tests/src/IntegrationTests/Trait/IteratorAggregateTestsTrait.php b/tests/src/IntegrationTests/Trait/IteratorAggregateTestsTrait.php index 4d80343..6a71357 100644 --- a/tests/src/IntegrationTests/Trait/IteratorAggregateTestsTrait.php +++ b/tests/src/IntegrationTests/Trait/IteratorAggregateTestsTrait.php @@ -39,6 +39,7 @@ public function testIteratorIteration(): void static::assertEquals($key, $value->getId()); $count++; } + static::assertGreaterThan(0, $count); } } diff --git a/tests/src/UnitTests/Collections/ArrayCollectionTest.php b/tests/src/UnitTests/Collections/ArrayCollectionTest.php index 4d755ba..42f7537 100644 --- a/tests/src/UnitTests/Collections/ArrayCollectionTest.php +++ b/tests/src/UnitTests/Collections/ArrayCollectionTest.php @@ -26,7 +26,7 @@ class ArrayCollectionTest extends TestCase /** * @return array */ - private static function createArray(): array + private function createArray(): array { $country = new Country('Khemed'); @@ -39,7 +39,7 @@ private static function createArray(): array public function testDoctrineArrayCollection(): void { - $citizens = new DoctrineArrayCollection(self::createArray()); + $citizens = new DoctrineArrayCollection($this->createArray()); $statelessCriteria = Criteria::create() ->where(Criteria::expr()->isNull('country')); @@ -49,7 +49,7 @@ public function testDoctrineArrayCollection(): void public function testOurArrayCollection(): void { - $citizens = new ArrayCollection(self::createArray()); + $citizens = new ArrayCollection($this->createArray()); $statelessCriteria = Criteria::create() ->where(Criteria::expr()->isNull('country')); diff --git a/tests/src/UnitTests/Collections/Fixtures/Citizen.php b/tests/src/UnitTests/Collections/Fixtures/Citizen.php index 4e2f972..a586a33 100644 --- a/tests/src/UnitTests/Collections/Fixtures/Citizen.php +++ b/tests/src/UnitTests/Collections/Fixtures/Citizen.php @@ -16,9 +16,9 @@ class Citizen { public function __construct( - private int $id, - private string $name, - private ?Country $country = null, + private readonly int $id, + private readonly string $name, + private readonly ?Country $country = null, ) { } diff --git a/tests/src/UnitTests/Collections/Fixtures/Country.php b/tests/src/UnitTests/Collections/Fixtures/Country.php index 3725de2..1f89abe 100644 --- a/tests/src/UnitTests/Collections/Fixtures/Country.php +++ b/tests/src/UnitTests/Collections/Fixtures/Country.php @@ -18,7 +18,7 @@ class Country private string $foo = 'bar'; public function __construct( - private string $name, + private readonly string $name, ) { }