From 4057104b9638c735dbbbe5445c326deae256bd37 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:48:38 +0700 Subject: [PATCH 01/12] Create rector.php --- rector.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..af2f91c --- /dev/null +++ b/rector.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +use PHPDevsr\Rector\Codeigniter4\Set\CodeigniterSetList; +use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; +use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; +use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; +use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; +use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; + +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->withSets([ + CodeigniterSetList::CODEIGNITER_44 + ]); + + // The paths to refactor (can also be supplied with CLI arguments) + $rectorConfig->paths([ + __DIR__ . '/app', + __DIR__ . '/tests', + ]); + + // Include Composer's autoload - required for global execution, remove if running locally + $rectorConfig->autoloadPaths([ + __DIR__ . '/vendor/autoload.php', + ]); + + // Do you need to include constants, class aliases, or a custom autoloader? + $rectorConfig->bootstrapFiles([ + realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', + ]); + + if (is_file(__DIR__ . '/phpstan.neon.dist')) { + $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); + } + + // Are there files or rules you need to skip? + $rectorConfig->skip([ + __DIR__ . '/app/Views', + + JsonThrowOnErrorRector::class, + StringifyStrNeedlesRector::class, + + // Note: requires php 8 + RemoveUnusedPromotedPropertyRector::class, + + // May load view files directly when detecting classes + StringClassNameToClassConstantRector::class, + + AnnotationToAttributeRector::class, + ]); +}; From 5acf94897e9b5b8172db1af8d33c4fa8f9a56df2 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:50:04 +0700 Subject: [PATCH 02/12] Update composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c7b0232..d3511b0 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "require-dev": { "fakerphp/faker": "^1.9", "mikey179/vfsstream": "^1.6", + "phpdevsr/rector-codeigniter4": "dev-main", "phpunit/phpunit": "^9.1" }, "autoload": { From 9883bc145b4094b3c2816183a555ffa34e6880bb Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:52:33 +0700 Subject: [PATCH 03/12] Create test-rector.yml --- .github/workflows/test-rector.yml | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/test-rector.yml diff --git a/.github/workflows/test-rector.yml b/.github/workflows/test-rector.yml new file mode 100644 index 0000000..dcec4ce --- /dev/null +++ b/.github/workflows/test-rector.yml @@ -0,0 +1,78 @@ +# When a PR is opened or a push is made, perform +# a static analysis check on the code using Rector. +name: Rector + +on: + pull_request: + paths: + - 'app/**.php' + - 'tests/**.php' + - '.github/workflows/test-rector.yml' + - composer.json + - rector.php + - '**.neon.dist' + + push: + paths: + - 'app/**.php' + - 'tests/**.php' + - '.github/workflows/test-rector.yml' + - composer.json + - rector.php + - '**.neon.dist' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + name: PHP ${{ matrix.php-versions }} Analyze code (Rector) + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: intl + + - name: Use latest Composer + run: composer self-update + + - name: Validate composer.json + run: composer validate --strict + + - name: Get composer cache directory + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer update --ansi --no-interaction + + - name: Rector Cache + uses: actions/cache@v4 + with: + path: /tmp/rector + key: ${{ runner.os }}-rector-${{ github.run_id }} + restore-keys: ${{ runner.os }}-rector- + + - run: mkdir -p /tmp/rector + + - name: Run static analysis + run: composer rector From a4ca8e65358c18ecb0ff342b768c78fe79320998 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:53:52 +0700 Subject: [PATCH 04/12] Update test-rector.yml --- .github/workflows/test-rector.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-rector.yml b/.github/workflows/test-rector.yml index dcec4ce..65a2051 100644 --- a/.github/workflows/test-rector.yml +++ b/.github/workflows/test-rector.yml @@ -75,4 +75,4 @@ jobs: - run: mkdir -p /tmp/rector - name: Run static analysis - run: composer rector + run: vendor/bin/rector process --dry-run --no-progress-bar From 83c1421f67bc8f8f3271076bae4189c2d7384be2 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:55:13 +0700 Subject: [PATCH 05/12] Update rector.php --- rector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rector.php b/rector.php index af2f91c..5b37812 100644 --- a/rector.php +++ b/rector.php @@ -20,7 +20,7 @@ use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->withSets([ + $rectorConfig->sets([ CodeigniterSetList::CODEIGNITER_44 ]); From 88786ea4922504a16a5d4653be8d6e2381c5ea1e Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:13:17 +0700 Subject: [PATCH 06/12] Update rector.php --- rector.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 5b37812..097f571 100644 --- a/rector.php +++ b/rector.php @@ -21,9 +21,13 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ - CodeigniterSetList::CODEIGNITER_44 + CodeigniterSetList::CODEIGNITER_44, ]); + // auto import fully qualified class names + $rectorConfig->importNames(); + $rectorConfig->removeUnusedImports(); + // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ __DIR__ . '/app', From 150eb27316941e3a9b16f89c3181cb2c4c1639aa Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:31:14 +0700 Subject: [PATCH 07/12] Update rector.php --- rector.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/rector.php b/rector.php index 097f571..5d6dc5e 100644 --- a/rector.php +++ b/rector.php @@ -19,37 +19,36 @@ use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([ +return RectorConfig::configure() + ->withSets([ CodeigniterSetList::CODEIGNITER_44, ]); // auto import fully qualified class names - $rectorConfig->importNames(); - $rectorConfig->removeUnusedImports(); + ->withImportNames(removeUnusedImports: true) // The paths to refactor (can also be supplied with CLI arguments) - $rectorConfig->paths([ + ->withPaths([ __DIR__ . '/app', __DIR__ . '/tests', - ]); + ]) // Include Composer's autoload - required for global execution, remove if running locally - $rectorConfig->autoloadPaths([ + ->withAutoloadPaths([ __DIR__ . '/vendor/autoload.php', - ]); + ]) // Do you need to include constants, class aliases, or a custom autoloader? - $rectorConfig->bootstrapFiles([ + ->withBootstrapFiles([ realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', ]); if (is_file(__DIR__ . '/phpstan.neon.dist')) { - $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); + ->withPHPStanConfigs(__DIR__ . '/phpstan.neon.dist') } // Are there files or rules you need to skip? - $rectorConfig->skip([ + ->withSkip([ __DIR__ . '/app/Views', JsonThrowOnErrorRector::class, @@ -63,4 +62,3 @@ AnnotationToAttributeRector::class, ]); -}; From 5dfb35320376aadd7b72cd62fc03f044bf766bff Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:32:47 +0700 Subject: [PATCH 08/12] Update rector.php --- rector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rector.php b/rector.php index 5d6dc5e..81a005c 100644 --- a/rector.php +++ b/rector.php @@ -22,7 +22,7 @@ return RectorConfig::configure() ->withSets([ CodeigniterSetList::CODEIGNITER_44, - ]); + ]) // auto import fully qualified class names ->withImportNames(removeUnusedImports: true) @@ -41,7 +41,7 @@ // Do you need to include constants, class aliases, or a custom autoloader? ->withBootstrapFiles([ realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', - ]); + ]) if (is_file(__DIR__ . '/phpstan.neon.dist')) { ->withPHPStanConfigs(__DIR__ . '/phpstan.neon.dist') From 47f879db68ac0345df1dc14be3fbf1566808a4ab Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Tue, 2 Apr 2024 09:03:22 +0700 Subject: [PATCH 09/12] Update rector.php --- rector.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/rector.php b/rector.php index 81a005c..cfc7a7f 100644 --- a/rector.php +++ b/rector.php @@ -12,6 +12,7 @@ */ use PHPDevsr\Rector\Codeigniter4\Set\CodeigniterSetList; +use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; @@ -23,30 +24,23 @@ ->withSets([ CodeigniterSetList::CODEIGNITER_44, ]) - // auto import fully qualified class names ->withImportNames(removeUnusedImports: true) - // The paths to refactor (can also be supplied with CLI arguments) ->withPaths([ __DIR__ . '/app', __DIR__ . '/tests', ]) - + ->withParallel(120, 8, 10) + ->withCache('/tmp/rector', FileCacheStorage::class) // Include Composer's autoload - required for global execution, remove if running locally ->withAutoloadPaths([ __DIR__ . '/vendor/autoload.php', ]) - // Do you need to include constants, class aliases, or a custom autoloader? ->withBootstrapFiles([ realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', ]) - - if (is_file(__DIR__ . '/phpstan.neon.dist')) { - ->withPHPStanConfigs(__DIR__ . '/phpstan.neon.dist') - } - // Are there files or rules you need to skip? ->withSkip([ __DIR__ . '/app/Views', From fa587546ae089ad102d56cf88b615b951b2b2150 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 20 May 2024 09:29:26 +0700 Subject: [PATCH 10/12] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d3511b0..6916828 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require-dev": { "fakerphp/faker": "^1.9", "mikey179/vfsstream": "^1.6", - "phpdevsr/rector-codeigniter4": "dev-main", + "phpdevsr/rector-codeigniter4": "^1.0", "phpunit/phpunit": "^9.1" }, "autoload": { From fbd15d380a496d195741a051af2bb315b2fb06de Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 20 May 2024 09:33:40 +0700 Subject: [PATCH 11/12] Update test-rector.yml --- .github/workflows/test-rector.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-rector.yml b/.github/workflows/test-rector.yml index 65a2051..8eb4483 100644 --- a/.github/workflows/test-rector.yml +++ b/.github/workflows/test-rector.yml @@ -35,7 +35,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3'] steps: - name: Checkout uses: actions/checkout@v4 From f853fc75103fcbd6c84f3075043b1b5690883f25 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Mon, 20 May 2024 09:34:01 +0700 Subject: [PATCH 12/12] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6916828..d3511b0 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require-dev": { "fakerphp/faker": "^1.9", "mikey179/vfsstream": "^1.6", - "phpdevsr/rector-codeigniter4": "^1.0", + "phpdevsr/rector-codeigniter4": "dev-main", "phpunit/phpunit": "^9.1" }, "autoload": {