Skip to content

Commit

Permalink
Add rector and apply suggestions (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
xepozz and vjik committed Nov 21, 2023
1 parent 2cc323c commit 42a3986
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 22 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.2']
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.18.10",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.14"
Expand Down
29 changes: 29 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
JsonThrowOnErrorRector::class,
]);
};
5 changes: 1 addition & 4 deletions src/AbstractQueryDataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
*/
abstract class AbstractQueryDataReader implements QueryDataReaderInterface
{
private QueryInterface $query;
private ?Sort $sort = null;
private ?FilterInterface $filter = null;
private ?FilterInterface $having = null;
Expand All @@ -65,9 +64,8 @@ abstract class AbstractQueryDataReader implements QueryDataReaderInterface
*/
protected array $filterHandlers = [];

public function __construct(QueryInterface $query)
public function __construct(private QueryInterface $query)
{
$this->query = $query;
$this->filterHandlers = $this->prepareHandlers(
new AllHandler(),
new AnyHandler(),
Expand Down Expand Up @@ -311,7 +309,6 @@ public function withFilterHandlers(FilterHandlerInterface ...$filterHandlers): s
}

/**
* @param QueryHandlerInterface ...$queryHandlers
* @return QueryHandlerInterface[]
*/
private function prepareHandlers(QueryHandlerInterface ...$queryHandlers): array
Expand Down
1 change: 0 additions & 1 deletion src/Filter/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static function getOperator(): string
}

/**
* @param mixed $value
* @return bool
*/
private static function isEmpty(mixed $value): bool
Expand Down
8 changes: 1 addition & 7 deletions src/Filter/CompareFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ abstract class CompareFilter implements FilterInterface

public static string $mainDateTimeFormat = 'Y-m-d H:i:s';

protected mixed $value;

protected bool $ignoreNull = false;
protected ?string $dateTimeFormat = null;

Expand All @@ -25,9 +23,8 @@ abstract class CompareFilter implements FilterInterface
* @param mixed $value
* @param string|null $table
*/
public function __construct(string|ExpressionInterface $column, mixed $value, ?string $table = null)
public function __construct(string|ExpressionInterface $column, protected mixed $value, ?string $table = null)
{
$this->value = $value;
$this->setColumn($column, $table);
}

Expand All @@ -48,7 +45,6 @@ public function withDateTimeFormat(?string $format): static
}

/**
* @param mixed $value
* @return mixed
*/
protected function formatValue(mixed $value): mixed
Expand All @@ -63,9 +59,7 @@ protected function formatValue(mixed $value): mixed
}

/**
* @param array $values
* @psalm-param array<int, mixed> $values
*
* @return array
*/
protected function formatValues(array $values): array
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

final class Exists implements FilterInterface
{
private QueryInterface $query;

public function __construct(QueryInterface $query)
public function __construct(private QueryInterface $query)
{
$this->query = $query;
}

public static function getOperator(): string
Expand Down
5 changes: 1 addition & 4 deletions src/Filter/Not.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

final class Not implements FilterInterface
{
private FilterInterface $filter;
private array $operators = [
'IS' => 'IS NOT',
'IN' => 'NOT IN',
Expand All @@ -27,10 +26,8 @@ final class Not implements FilterInterface
'=' => '!=',
];

public function __construct(FilterInterface $filter, ?array $operators = null)
public function __construct(private FilterInterface $filter, ?array $operators = null)
{
$this->filter = $filter;

if ($operators !== null) {
$this->operators = $operators;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ public function equalsEmptyDataProvider(): array
}

/**
* @param EqualsEmpty $filter
* @param array $expected
* @dataProvider equalsEmptyDataProvider
*/
public function testEqualsEmpty(EqualsEmpty $filter, array $expected): void
Expand Down

0 comments on commit 42a3986

Please sign in to comment.