Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/test-rector.yml
Original file line number Diff line number Diff line change
@@ -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: ['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: vendor/bin/rector process --dry-run --no-progress-bar
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require-dev": {
"fakerphp/faker": "^1.9",
"mikey179/vfsstream": "^1.6",
"phpdevsr/rector-codeigniter4": "dev-main",
"phpunit/phpunit": "^9.1"
},
"autoload": {
Expand Down
58 changes: 58 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/**
* This file is part of PHPDevsr/recaptcha-codeigniter4.
*
* (c) 2023 Denny Septian Panggabean <xamidimura@gmail.com>
*
* 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\Caching\ValueObject\Storage\FileCacheStorage;
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 RectorConfig::configure()
->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',
])
// Are there files or rules you need to skip?
->withSkip([
__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,
]);