Skip to content

Commit

Permalink
Rector tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi authored and rotimi committed Apr 14, 2021
1 parent 9eb947d commit d799749
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 463 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Run PHP Tests and Code Quality Tools

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
# Also run every Sunday at midnight
- cron: '0 0 * * 0'

jobs:
build:

runs-on: ${{ matrix.os }}

strategy:
matrix:
php: [8.0, 7.4, 7.3, 7.2]
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
# dependency-version: [prefer-lowest, prefer-stable]
dependency-version: [prefer-stable]
os: [ubuntu-18.04, ubuntu-20.04]
include:
- os: ubuntu-18.04
php: 7.2
- os: ubuntu-18.04
php: 7.3
- os: ubuntu-18.04
php: 7.4
- os: ubuntu-18.04
php: 8.0
- os: ubuntu-20.04
php: 7.4
- os: ubuntu-20.04
php: 8.0
exclude:
- os: ubuntu-20.04
php: 7.3

name: PHP-${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: pcre.jit=0, pcre.backtrack_limit=9999999, pcre.recursion_limit=9999999
coverage: none

- name: PHP version
run: php -v

- name: Composer version
run: composer --version

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install Dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Run PHPUnit Test Suite
run: vendor/bin/phpunit

- name: Run Rector
# Run rector for PHP 7.X but not 8.0, rector is currently blowing up with PHP 8.0
#if: matrix.php != '8.0'
run: vendor/bin/rector process src --dry-run

- name: Run Psalm
# Run psalm for PHP 7.4 & 8.0 but not 7.2 & 7.3, psalm is currently blowing up with PHP 7.2 & 7.3
#if: matrix.php != '7.2' && matrix.php != '7.3'
run: vendor/bin/psalm
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"laminas/laminas-escaper": "^2.6.1"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^9.0 || ^8.0",
"php-coveralls/php-coveralls": "^2.0",
"rector/rector": "^0.8.56"
"rector/rector": "^0.10.4 || ^0.8.56",
"vimeo/psalm": "^4.7"
},
"autoload": {
"classmap": ["src/"],
Expand All @@ -35,5 +36,8 @@
"Rotexsoft\\FileRenderer\\": "src/",
"Rotexsoft\\FileRenderer\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit --coverage-text"
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
156 changes: 7 additions & 149 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,167 +11,25 @@
return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::EXCLUDE_PATHS, [
// single file
//__DIR__ . '/src/ComplicatedFile.php',
// or directory
//__DIR__ . '/src/views/*/*',
]);

$parameters->set(Option::EXCLUDE_RECTORS, [

\Rector\CodeQuality\Rector\If_\MoveOutMethodCallInsideIfConditionRector::class,
\Rector\CodeQuality\Rector\Ternary\SimplifyTautologyTernaryRector::class,
\Rector\CodeQuality\Rector\FunctionLike\RemoveAlwaysTrueConditionSetInConstructorRector::class,
\Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector::class,
\Rector\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector::class,
\Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class,
\Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector::class,
\Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector::class,
\Rector\CodeQuality\Rector\Array_\ArrayThisCallToThisMethodCallRector::class,
\Rector\CodeQuality\Rector\New_\NewStaticToNewSelfRector::class,
\Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class,

\Rector\CodingStyle\Rector\Use_\RemoveUnusedAliasRector::class,
\Rector\CodingStyle\Rector\Include_\FollowRequireByDirRector::class,
\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
\Rector\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector::class,
\Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector::class,
\Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector::class,
\Rector\CodingStyle\Rector\Function_\CamelCaseFunctionNamingToUnderscoreRector::class,
\Rector\CodingStyle\Rector\ClassMethod\RemoveDoubleUnderscoreInMethodNameRector::class,

\Rector\CodingStyle\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector::class,

\Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector::class,
\Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector::class,
\Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector::class,
\Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateConstantRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector::class,
\Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector::class,
\Rector\DeadCode\Rector\MethodCall\RemoveDefaultArgumentValueRector::class,
\Rector\DeadCode\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector::class,
\Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
\Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector::class,
\Rector\DeadCode\Rector\Function_\RemoveUnusedFunctionRector::class,
\Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector::class,
\Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector::class,

\Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector::class,
\Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector::class,
\Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector::class,
\Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector::class,
\Rector\Naming\Rector\ClassMethod\MakeGetterClassMethodNameStartWithGetRector::class,
\Rector\Naming\Rector\ClassMethod\MakeIsserClassMethodNameStartWithIsRector::class,
\Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
\Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector::class,

\Rector\Php70\Rector\Assign\ListSwapArrayOrderRector::class,

\Rector\Php71\Rector\BinaryOp\BinaryOpBetweenNumberAndStringRector::class,

\Rector\Php72\Rector\ConstFetch\BarewordStringRector::class,

\Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class,

\Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector::class,

\Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector::class,
]);

// Define what rule sets will be applied
$parameters->set(Option::SETS, [
SetList::DEAD_CODE,
// No Rector
// \Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector::class,
// \Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector::class
// \Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector::class,
// \Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateConstantRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector::class,
// \Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector::class,
// \Rector\DeadCode\Rector\MethodCall\RemoveDefaultArgumentValueRector::class,
// \Rector\DeadCode\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector::class,
// \Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
// \Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector::class,
// \Rector\DeadCode\Rector\Function_\RemoveUnusedFunctionRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveDeadRecursiveClassMethodRector::class,
// \Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector::class,
SetList::PERFORMANCE,
SetList::CODE_QUALITY,
// No Rector:
// \Rector\CodeQuality\Rector\Ternary\SimplifyTautologyTernaryRector::class,
// \Rector\CodeQuality\Rector\FunctionLike\RemoveAlwaysTrueConditionSetInConstructorRector::class,
// \Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector::class,
// \Rector\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector::class,
// \Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class,
// \Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector::class,
// \Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector::class,
// \Rector\CodeQuality\Rector\Array_\ArrayThisCallToThisMethodCallRector::class,
// \Rector\CodeQuality\Rector\New_\NewStaticToNewSelfRector::class,
// \Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class,
SetList::CODE_QUALITY_STRICT,
// No Rector:
// \Rector\CodeQuality\Rector\If_\MoveOutMethodCallInsideIfConditionRector::class,
SetList::CODING_STYLE,
// No Rector:
// \Rector\CodingStyle\Rector\Use_\RemoveUnusedAliasRector::class,
// \Rector\CodingStyle\Rector\Include_\FollowRequireByDirRector::class,
// \Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
// \Rector\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector::class,
// \Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector::class,
// \Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector::class,
// \Rector\CodingStyle\Rector\Function_\CamelCaseFunctionNamingToUnderscoreRector::class,
// \Rector\CodingStyle\Rector\ClassMethod\RemoveDoubleUnderscoreInMethodNameRector::class, //only use in projects where you really wanna do this
SetList::CODING_STYLE_ADVANCED,
// No Rector:
// \Rector\CodingStyle\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector::class,
//SetList::LARAVEL_STATIC_TO_INJECTION, // only in laravel projects
//SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL, // only in laravel projects
SetList::MYSQL_TO_MYSQLI, // only use in web-apps with db access and db / orm packages
SetList::NAMING,
// No Rector:
// \Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector::class,
// \Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector::class,
// \Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector::class,
// \Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector::class,
// \Rector\Naming\Rector\ClassMethod\MakeGetterClassMethodNameStartWithGetRector::class,
// \Rector\Naming\Rector\ClassMethod\MakeIsserClassMethodNameStartWithIsRector::class,
// \Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
// \Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector::class,
SetList::PERFORMANCE,
SetList::PHPEXCEL_TO_PHPSPREADSHEET, // only use in projects that use phpexcel
SetList::PHP_52,
SetList::PHP_53,
SetList::PHP_54,
SetList::PHP_55,
SetList::PHP_56,
SetList::PHP_70,
// No Rector
// \Rector\Php70\Rector\Assign\ListSwapArrayOrderRector::class,
SetList::PHP_71,
// No Rector
// \Rector\Php71\Rector\BinaryOp\BinaryOpBetweenNumberAndStringRector::class,
SetList::PHP_72,
// No Rector
// \Rector\Php72\Rector\ConstFetch\BarewordStringRector::class,
SetList::PHP_73,
SetList::PHP_74,
// No Rector
// \Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class,
//SetList::PHP_80
// No Rector
// \Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector::class,
//SetList::PSR_4,
SetList::DEAD_CODE,
//SetList::PHP_73,
//SetList::PHP_74,
//SetList::PHP_80,
SetList::DEAD_CODE,
SetList::PSR_4,
SetList::TYPE_DECLARATION,
// No Rector
// \Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector::class,
SetList::TYPE_DECLARATION_STRICT,
]);

// get services (needed for register a single rule)
Expand Down
Loading

0 comments on commit d799749

Please sign in to comment.