Skip to content

Commit

Permalink
Add rector (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Nov 7, 2022
1 parent de7e85e commit 70d4505
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 25 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
@@ -0,0 +1,21 @@
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
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -30,6 +30,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
22 changes: 22 additions & 0 deletions rector.php
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
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,
]);
};
14 changes: 6 additions & 8 deletions src/AssignmentsStorage.php
Expand Up @@ -14,19 +14,17 @@
final class AssignmentsStorage implements AssignmentsStorageInterface
{
private DatabaseInterface $database;
/**
* @psalm-var non-empty-string
*/
private string $tableName;

/**
* @param non-empty-string $tableName
* @param DatabaseProviderInterface $dbal
*/
public function __construct(string $tableName, DatabaseProviderInterface $dbal)
{
public function __construct(/**
* @psalm-var non-empty-string
*/
private string $tableName,
DatabaseProviderInterface $dbal
) {
$this->database = $dbal->database();
$this->tableName = $tableName;
}

/**
Expand Down
13 changes: 5 additions & 8 deletions src/Command/RbacCycleInit.php
Expand Up @@ -16,16 +16,13 @@
final class RbacCycleInit extends Command
{
protected static $defaultName = 'rbac/cycle/init';
private DatabaseProviderInterface $dbal;
/**

public function __construct(/**
* @psalm-var array{itemsTable: non-empty-string, assignmentsTable: non-empty-string, itemsChildrenTable?: non-empty-string}
*/
private array $config;

public function __construct(array $config, DatabaseProviderInterface $dbal)
{
$this->dbal = $dbal;
$this->config = $config;
private array $config,
private DatabaseProviderInterface $dbal
) {
parent::__construct();
}

Expand Down
15 changes: 7 additions & 8 deletions src/ItemsStorage.php
Expand Up @@ -17,24 +17,23 @@
final class ItemsStorage implements ItemsStorageInterface
{
private DatabaseInterface $database;
/**
* @psalm-var non-empty-string
*/
private string $tableName;
/**
* @psalm-var non-empty-string
*/
private string $childrenTableName;

/**
* @param non-empty-string $tableName
* @param DatabaseProviderInterface $dbal
* @param non-empty-string|null $childrenTableName
*/
public function __construct(string $tableName, DatabaseProviderInterface $dbal, ?string $childrenTableName = null)
{
public function __construct(/**
* @psalm-var non-empty-string
*/
private string $tableName,
DatabaseProviderInterface $dbal,
?string $childrenTableName = null
) {
$this->database = $dbal->database();
$this->tableName = $tableName;
$this->childrenTableName = $childrenTableName ?? $tableName . '_child';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Expand Up @@ -22,7 +22,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
{
private ?DatabaseManager $databaseManager = null;

private $tables = [
private array $tables = [
'itemsChildTable' => 'auth_item_child',
'assignmentsTable' => 'auth_assignment',
'itemsTable' => 'auth_item',
Expand Down

0 comments on commit 70d4505

Please sign in to comment.