From 5036fcad63c4cf30a3a7c9adbe8442166e80c8f0 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Sep 2022 16:20:28 +0300 Subject: [PATCH 1/4] Add rector files https://github.com/yiisoft/yii-dev-tool/pull/232 --- .github/workflows/rector.yml | 65 ++++++++++++++++++++++++++++++++++++ rector.php | 22 ++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/rector.yml create mode 100644 rector.php diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..b235fb0 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,65 @@ +on: + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.env.example' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + +name: rector + +jobs: + rector: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + tools: composer:v2 + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Update composer + run: composer self-update + + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - run: vendor/bin/rector process --ansi + + - name: Check for Rector modified files + id: rector-git-check + run: echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi) + + - name: Git config + if: steps.rector-git-check.outputs.modified == 'true' + run: | + git config --global user.name 'rector-bot' + git config --global user.email 'rector@yiiframework.com' + + - name: Commit Rector changes + if: steps.rector-git-check.outputs.modified == 'true' + run: git commit -am "[rector] Apply fixes" + + - name: Push changes + if: steps.rector-git-check.outputs.modified == 'true' + run: git push + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..63713ce --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); +}; From 7242ed6739add2d3a91b07dd16c65863f2424e0f Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Sep 2022 16:37:56 +0300 Subject: [PATCH 2/4] Add rector/rector dependecy --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index bf410ca..d76f6c1 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ }, "require-dev": { "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" From 680d917fca22573a88da72a7b8af69af9d91d4f1 Mon Sep 17 00:00:00 2001 From: rector-bot Date: Tue, 27 Sep 2022 15:21:54 +0000 Subject: [PATCH 3/4] [rector] Apply fixes --- src/PgsqlMutex.php | 4 +--- src/PgsqlMutexFactory.php | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/PgsqlMutex.php b/src/PgsqlMutex.php index c178491..12dc178 100644 --- a/src/PgsqlMutex.php +++ b/src/PgsqlMutex.php @@ -18,17 +18,15 @@ final class PgsqlMutex extends Mutex { private array $lockKeys; - private PDO $connection; /** * @param string $name Mutex name. * @param PDO $connection PDO connection instance to use. */ - public function __construct(string $name, PDO $connection) + public function __construct(string $name, private PDO $connection) { // Converts a string into two 16-bit integer keys using the SHA1 hash function. $this->lockKeys = array_values(unpack('n2', sha1($name, true))); - $this->connection = $connection; /** @var string $driverName */ $driverName = $connection->getAttribute(PDO::ATTR_DRIVER_NAME); diff --git a/src/PgsqlMutexFactory.php b/src/PgsqlMutexFactory.php index ca6b96b..393a69a 100644 --- a/src/PgsqlMutexFactory.php +++ b/src/PgsqlMutexFactory.php @@ -13,14 +13,11 @@ */ final class PgsqlMutexFactory extends MutexFactory { - private PDO $connection; - /** * @param PDO $connection PDO connection instance to use. */ - public function __construct(PDO $connection) + public function __construct(private PDO $connection) { - $this->connection = $connection; } public function create(string $name): MutexInterface From 64c96951182ecf935c45fc26edaf8aa981f29835 Mon Sep 17 00:00:00 2001 From: Dmitrii Derepko Date: Tue, 27 Sep 2022 21:39:09 +0300 Subject: [PATCH 4/4] Use predefined rector action --- .github/workflows/rector.yml | 60 +++++------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index b235fb0..adacd73 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -1,65 +1,21 @@ on: - push: + pull_request: paths-ignore: - 'docs/**' - 'README.md' - 'CHANGELOG.md' - '.gitignore' - - '.env.example' - '.gitattributes' - 'infection.json.dist' - - 'phpunit.xml.dist' + - 'psalm.xml' name: rector jobs: rector: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.0 - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Update composer - run: composer self-update - - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - run: vendor/bin/rector process --ansi - - - name: Check for Rector modified files - id: rector-git-check - run: echo ::set-output name=modified::$(if git diff --exit-code --no-patch; then echo "false"; else echo "true"; fi) - - - name: Git config - if: steps.rector-git-check.outputs.modified == 'true' - run: | - git config --global user.name 'rector-bot' - git config --global user.email 'rector@yiiframework.com' - - - name: Commit Rector changes - if: steps.rector-git-check.outputs.modified == 'true' - run: git commit -am "[rector] Apply fixes" - - - name: Push changes - if: steps.rector-git-check.outputs.modified == 'true' - run: git push - + uses: yiisoft/actions/.github/workflows/rector.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['8.0']