diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml index 3b1265e..6e9c639 100644 --- a/.github/workflows/phpcsfixer.yml +++ b/.github/workflows/phpcsfixer.yml @@ -34,13 +34,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 6bdd00f..26a6e20 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 5e6ccf6..274b154 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -39,13 +39,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 36d6d2c..d91db3c 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -63,5 +62,5 @@ jobs: - name: Analyze for refactoring run: | - composer global require --dev rector/rector:^0.13.8 + composer global require --dev rector/rector:^0.15.1 rector process --dry-run --no-progress-bar diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ac7cd76..d5b03cb 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,7 +10,10 @@ __DIR__ . '/src/', ]) ->exclude('build') - ->append([__FILE__]); + ->append([ + __FILE__, + __DIR__ . '/rector.php', + ]); $overrides = []; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b712dd6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contributing to CodeIgniter4 + +CodeIgniter is a community driven project and accepts contributions of +code and documentation from the community. + +If you'd like to contribute, please read [Contributing to CodeIgniter](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/README.md) +in the [main repository](https://github.com/codeigniter4/CodeIgniter4). + +If you are going to contribute to this repository, please report bugs or send PRs +to this repository instead of the main repository. diff --git a/composer.json b/composer.json index 87c03c6..2596b47 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "devkit", "toolkit", "development", - "tools" + "tools", + "static analysis" ], "authors": [ { @@ -22,10 +23,10 @@ "homepage": "https://github.com/codeigniter4/devkit", "require": { "php": "^7.4 || ^8.0", - "codeigniter/coding-standard": "^1.1", + "codeigniter/coding-standard": "^1.5", "fakerphp/faker": "^1.9", "mikey179/vfsstream": "^1.6", - "nexusphp/cs-config": "^3.1", + "nexusphp/cs-config": "^3.6", "nexusphp/tachycardia": "^1.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.0", @@ -33,12 +34,12 @@ "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.3", "roave/security-advisories": "dev-latest", - "vimeo/psalm": "^4.22" + "vimeo/psalm": "^5.0" }, "require-dev": { "codeigniter4/framework": "^4.1", "icanhazstring/composer-unused": "^0.8.2", - "rector/rector": "0.14.0" + "rector/rector": "0.15.1" }, "minimum-stability": "dev", "prefer-stable": true, @@ -63,10 +64,11 @@ "@test" ], "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff", - "cs-fix": "php-cs-fixer fix --ansi --verbose --diff --using-cache=yes", + "cs-fix": "php-cs-fixer fix --ansi --verbose --diff", "style": "@cs-fix", "deduplicate": "phpcpd app/ src/", "inspect": "deptrac analyze --cache-file=build/deptrac.cache", - "mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit" + "mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit", + "test": "phpunit" } } diff --git a/psalm_autoload.php b/psalm_autoload.php index 5a25347..214c9fb 100644 --- a/psalm_autoload.php +++ b/psalm_autoload.php @@ -18,3 +18,5 @@ require_once $filePath; } } + +chdir(__DIR__); diff --git a/rector.php b/rector.php index 448606c..3e8ab23 100644 --- a/rector.php +++ b/rector.php @@ -1,7 +1,7 @@ sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]); + $rectorConfig->sets([ + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, + PHPUnitSetList::PHPUNIT_100, + ]); + $rectorConfig->parallel(); + // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ __DIR__ . '/src/', @@ -78,7 +87,7 @@ __DIR__ . '/tests', ], - // Ignore files that should not be namespaced + // Ignore files that should not be namespaced to their folder NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [ __DIR__ . '/src/Helpers', ], @@ -89,6 +98,10 @@ // May be uninitialized on purpose AddDefaultValueForUndefinedVariableRector::class, ]); + + // auto import fully qualified class names + $rectorConfig->importNames(); + $rectorConfig->rule(SimplifyUselessVariableRector::class); $rectorConfig->rule(RemoveAlwaysElseRector::class); $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); @@ -112,8 +125,14 @@ $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); $rectorConfig - ->ruleWithConfiguration(TypedPropertyRector::class, [ - // Set to false if you use in libraries, or it does create breaking changes. - TypedPropertyRector::INLINE_PUBLIC => true, + ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ + /** + * The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74 + * Set to true for projects that allow BC break + */ + TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, ]); + $rectorConfig->rule(StringClassNameToClassConstantRector::class); + $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); }; diff --git a/src/Template/.github/workflows/deptrac.yml b/src/Template/.github/workflows/deptrac.yml index c077f72..ca471f0 100644 --- a/src/Template/.github/workflows/deptrac.yml +++ b/src/Template/.github/workflows/deptrac.yml @@ -39,13 +39,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/infection.yml b/src/Template/.github/workflows/infection.yml index 7f16938..8d2c1dc 100644 --- a/src/Template/.github/workflows/infection.yml +++ b/src/Template/.github/workflows/infection.yml @@ -45,13 +45,12 @@ jobs: uses: mheap/phpunit-matcher-action@v1 - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/phpcsfixer.yml b/src/Template/.github/workflows/phpcsfixer.yml index 3b1265e..6e9c639 100644 --- a/src/Template/.github/workflows/phpcsfixer.yml +++ b/src/Template/.github/workflows/phpcsfixer.yml @@ -34,13 +34,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/phpstan.yml b/src/Template/.github/workflows/phpstan.yml index 6bdd00f..26a6e20 100644 --- a/src/Template/.github/workflows/phpstan.yml +++ b/src/Template/.github/workflows/phpstan.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/phpunit.yml b/src/Template/.github/workflows/phpunit.yml index c875e33..c8caa4a 100644 --- a/src/Template/.github/workflows/phpunit.yml +++ b/src/Template/.github/workflows/phpunit.yml @@ -42,13 +42,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/psalm.yml b/src/Template/.github/workflows/psalm.yml index 5e6ccf6..274b154 100644 --- a/src/Template/.github/workflows/psalm.yml +++ b/src/Template/.github/workflows/psalm.yml @@ -39,13 +39,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.github/workflows/rector.yml b/src/Template/.github/workflows/rector.yml index c09365d..d91db3c 100644 --- a/src/Template/.github/workflows/rector.yml +++ b/src/Template/.github/workflows/rector.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -63,5 +62,5 @@ jobs: - name: Analyze for refactoring run: | - composer global require --dev rector/rector:^0.14 + composer global require --dev rector/rector:^0.15.1 rector process --dry-run --no-progress-bar diff --git a/src/Template/.github/workflows/unused.yml b/src/Template/.github/workflows/unused.yml index b83ccb9..53a0d03 100644 --- a/src/Template/.github/workflows/unused.yml +++ b/src/Template/.github/workflows/unused.yml @@ -37,13 +37,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/src/Template/.php-cs-fixer.dist.php b/src/Template/.php-cs-fixer.dist.php index 26b8ac2..8fc31b3 100644 --- a/src/Template/.php-cs-fixer.dist.php +++ b/src/Template/.php-cs-fixer.dist.php @@ -10,10 +10,19 @@ __DIR__ . '/app/', __DIR__ . '/tests/', ]) - ->exclude('build') - ->append([__FILE__]); + ->exclude([ + 'build', + 'Views', + ]) + ->append([ + __FILE__, + __DIR__ . '/rector.php', + ]); -$overrides = []; +$overrides = [ + // 'declare_strict_types' => true, + // 'void_return' => true, +]; $options = [ 'finder' => $finder, diff --git a/src/Template/psalm_autoload.php b/src/Template/psalm_autoload.php index 2a9c211..4c33092 100644 --- a/src/Template/psalm_autoload.php +++ b/src/Template/psalm_autoload.php @@ -10,11 +10,11 @@ ]; foreach ($helperDirs as $dir) { + $dir = __DIR__ . '/' . $dir; if (! is_dir($dir)) { continue; } - $dir = __DIR__ . '/' . $dir; chdir($dir); foreach (glob('*_helper.php') as $filename) { @@ -23,3 +23,5 @@ require_once $filePath; } } + +chdir(__DIR__); diff --git a/src/Template/rector.php b/src/Template/rector.php index 5d05999..6b236dc 100644 --- a/src/Template/rector.php +++ b/src/Template/rector.php @@ -1,6 +1,7 @@ sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]); + $rectorConfig->sets([ + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, + PHPUnitSetList::PHPUNIT_100, + ]); + $rectorConfig->parallel(); + // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ __DIR__ . '/app/', @@ -79,7 +88,7 @@ __DIR__ . '/tests', ], - // Ignore files that should not be namespaced + // Ignore files that should not be namespaced to their folder NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [ __DIR__ . '/app/Helpers', ], @@ -90,6 +99,10 @@ // May be uninitialized on purpose AddDefaultValueForUndefinedVariableRector::class, ]); + + // auto import fully qualified class names + $rectorConfig->importNames(); + $rectorConfig->rule(SimplifyUselessVariableRector::class); $rectorConfig->rule(RemoveAlwaysElseRector::class); $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); @@ -113,8 +126,14 @@ $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); $rectorConfig - ->ruleWithConfiguration(TypedPropertyRector::class, [ - // Set to false if you use in libraries, or it does create breaking changes. - TypedPropertyRector::INLINE_PUBLIC => true, + ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ + /** + * The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74 + * Set to true for projects that allow BC break + */ + TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, ]); + $rectorConfig->rule(StringClassNameToClassConstantRector::class); + $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); };