Skip to content

Commit

Permalink
build: rector (#125)
Browse files Browse the repository at this point in the history
* build: rector

* remove mixedtype

* php 8.2

* type coverage 10

* type declaration

* dead code 16

* dead code 17

* deadcode 19

* dead code 20

* dead code

* code quality 25

* fix extra lazy

* code quality 60

* code quality 65

* code quality 70

* code quality

* NewlineAfterStatementRector

* coding style

* privatization

* finalize rector
  • Loading branch information
priyadi authored Jul 18, 2024
1 parent eb38ace commit 28ac382
Show file tree
Hide file tree
Showing 47 changed files with 161 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor
.phpunit.cache
tools
.php-cs-fixer.cache
.vscode
.vscode
rector.log
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.3

* build: add rector

## 0.9.2

* fix(orm): `getQueryBuilder()` now clones the query builder
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions packages/collections-common/src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion packages/collections-common/src/Internal/ParameterUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
9 changes: 1 addition & 8 deletions packages/collections-common/src/Trait/ArrayAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ trait ArrayAccessTrait
* @return Collection<TKey,T>
*/
abstract private function getSafeCollection(): Collection;

abstract private function ensureSafety(): void;

/**
* @return Collection<TKey,T>
*/
abstract private function getRealCollection(): Collection;

/**
* @param mixed $offset
*/
final public function offsetExists(mixed $offset): bool
{
/** @var TKey */
Expand All @@ -47,7 +45,6 @@ final public function offsetExists(mixed $offset): bool
}

/**
* @param mixed $offset
* @return T|null
*/
final public function offsetGet(mixed $offset): mixed
Expand All @@ -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
Expand All @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions packages/collections-common/src/Trait/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ abstract private function getRealCollection(): Collection;
* @return Collection<TKey,T>
*/
abstract private function getSafeCollection(): Collection;

abstract private function ensureSafety(): void;

/**
Expand All @@ -58,7 +59,6 @@ final public function clear(): void
}

/**
* @param mixed $key
* @return T|null
*/
final public function remove(mixed $key): mixed
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/collections-common/src/Trait/FetchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
trait FetchTrait
{
/**
* @param mixed $key
* @return T
* @throws NotFoundException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -61,7 +58,6 @@ final public function containsKey(mixed $key): bool
}

/**
* @param mixed $key
* @return T|null
*/
final public function get(mixed $key): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -67,7 +64,6 @@ final public function containsKey(mixed $key): bool
}

/**
* @param mixed $key
* @return T|null
*/
final public function get(mixed $key): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
trait RefreshCountTrait
{
abstract private function getCountStrategy(): CountStrategy;

abstract private function getUnderlyingCountable(): ?\Countable;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
interface MinimalReadableRepository extends MinimalReadableRecollection
{
/**
* @param mixed $key
* @return T
*/
public function reference(mixed $key): object;
Expand Down
1 change: 0 additions & 1 deletion packages/collections-contracts/src/MinimalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
interface MinimalRepository extends MinimalReadableRepository, MinimalRecollection
{
/**
* @param mixed $key
* @return T|null
*/
public function remove(mixed $key): mixed;
Expand Down
4 changes: 0 additions & 4 deletions packages/collections-contracts/src/ReadableRecollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,9 +45,7 @@ public function get(mixed $key): mixed;
//
// Methods
//

/**
* @param mixed $key
* @return T
* @throws NotFoundException
*/
Expand Down
1 change: 0 additions & 1 deletion packages/collections-contracts/src/ReadableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
interface ReadableRepository extends ReadableRecollection
{
/**
* @param mixed $key
* @return T
*/
public function reference(mixed $key): object;
Expand Down
8 changes: 0 additions & 8 deletions packages/collections-contracts/src/Recollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion packages/collections-domain/src/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion packages/collections-domain/src/CriteriaPageable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CriteriaPageable implements PageableRecollection
private readonly Selectable $collection;

private readonly Criteria $criteria;

private readonly ?string $indexBy;

/**
Expand Down Expand Up @@ -96,7 +97,6 @@ final private function __construct(
* @template ST
* @param ReadableCollection<STKey,ST>|Selectable<STKey,ST> $collection
* @param int<1,max> $itemsPerPage
* @return static
*/
final public static function create(
ReadableCollection|Selectable $collection,
Expand Down
3 changes: 2 additions & 1 deletion packages/collections-domain/src/CriteriaRecollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CriteriaRecollection implements ReadableRecollection
private readonly Selectable $collection;

private readonly Criteria $criteria;

private readonly ?string $indexBy;

/**
Expand Down Expand Up @@ -213,7 +214,7 @@ private function getOrderBy(): array
{
$ordering = $this->criteria->orderings();

if (empty($ordering)) {
if ($ordering === []) {
return ['id' => Order::Descending];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MinimalCriteriaRecollection implements MinimalReadableRecollection
private readonly Selectable $collection;

private readonly Criteria $criteria;

private readonly ?string $indexBy;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MinimalRecollectionDecorator implements MinimalRecollection
private readonly array $orderBy;

private readonly ?string $indexBy;

private readonly Criteria $criteria;

/**
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Loading

0 comments on commit 28ac382

Please sign in to comment.