diff --git a/admin/pre-commit b/admin/pre-commit index 9bed769..ad61c32 100644 --- a/admin/pre-commit +++ b/admin/pre-commit @@ -19,21 +19,6 @@ if [ "$STAGED_PHP_FILES" != "" ]; then done fi -if [ "$FILES" != "" ]; then - echo "Running PHPStan..." - - if [ -d /proc/cygdrive ]; then - XDEBUG_MODE=off ./vendor/bin/phpstan analyse - else - XDEBUG_MODE=off php ./vendor/bin/phpstan analyse - fi - - if [ $? != 0 ]; then - echo "Fix the phpstan error(s) before commit." - exit 1 - fi -fi - if [ "$FILES" != "" ]; then echo "Running PHP CS Fixer..." diff --git a/rector.php b/rector.php index 31b0b6f..25e98ab 100644 --- a/rector.php +++ b/rector.php @@ -14,7 +14,6 @@ use Rector\CodeQuality\Rector\Assign\CombinedAssignRector; use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; use Rector\CodeQuality\Rector\BooleanNot\ReplaceMultipleBooleanNotRector; -use Rector\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector; use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector; use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector; @@ -29,7 +28,6 @@ use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\If_\CombineIfRector; -use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector; use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; @@ -39,7 +37,6 @@ use Rector\CodeQuality\Rector\LogicalAnd\AndAssignsToSeparateLinesRector; use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector; use Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector; -use Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector; use Rector\CodeQuality\Rector\Ternary\NumberCompareToMaxFuncCallRector; use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector; use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector; @@ -75,10 +72,8 @@ use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; -use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector; -use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector; -use Rector\Php81\Rector\Array_\FirstClassCallableRector; -use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector; +use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -88,14 +83,15 @@ SetList::DEAD_CODE, SetList::CODE_QUALITY, SetList::STRICT_BOOLEANS, - LevelSetList::UP_TO_PHP_82, + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, + PHPUnitSetList::PHPUNIT_100, ]); - $rectorConfig->parallel(120, 16, 15); - // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ - __DIR__ . '/app', + __DIR__ . '/src', + __DIR__ . '/tests', ]); // Include Composer's autoload - required for global execution, remove if running locally @@ -120,11 +116,7 @@ // Are there files or rules you need to skip? $rectorConfig->skip([ - __DIR__ . '/app/Common.php', - __DIR__ . '/app/Config', - __DIR__ . '/app/Database', - __DIR__ . '/app/Language', - __DIR__ . '/app/Views', + __DIR__ . '/src/Views', JsonThrowOnErrorRector::class, StringifyStrNeedlesRector::class, @@ -134,72 +126,75 @@ // May load view files directly when detecting classes StringClassNameToClassConstantRector::class, + + AnnotationToAttributeRector::class, ]); + // auto import fully qualified class names $rectorConfig->importNames(); - $rectorConfig->rule(RemoveDeadZeroAndOneOperationRector::class); + // Code Quality + $rectorConfig->rule(JoinStringConcatRector::class); + $rectorConfig->rule(CombinedAssignRector::class); + $rectorConfig->rule(ReplaceMultipleBooleanNotRector::class); $rectorConfig->rule(InlineArrayReturnAssignRector::class); - $rectorConfig->rule(LogicalToBooleanRector::class); - $rectorConfig->rule(AndAssignsToSeparateLinesRector::class); - $rectorConfig->rule(SwitchNegatedTernaryRector::class); - $rectorConfig->rule(ArrayKeyExistsTernaryThenValueToCoalescingRector::class); - $rectorConfig->rule(TernaryFalseExpressionToIfRector::class); + $rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class); $rectorConfig->rule(UseIdenticalOverEqualWithSameTypeRector::class); - $rectorConfig->rule(ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class); + $rectorConfig->rule(TernaryFalseExpressionToIfRector::class); + $rectorConfig->rule(ArrayMergeOfNonArraysToSimpleArrayRector::class); $rectorConfig->rule(ExplicitBoolCompareRector::class); - $rectorConfig->rule(SimplifyIfNullableReturnRector::class); $rectorConfig->rule(SimplifyIfNotNullReturnRector::class); - $rectorConfig->rule(ArrayMergeOfNonArraysToSimpleArrayRector::class); - $rectorConfig->rule(SimplifyDeMorganBinaryRector::class); + $rectorConfig->rule(SimplifyIfNullableReturnRector::class); + $rectorConfig->rule(SimplifyUselessVariableRector::class); + $rectorConfig->rule(AndAssignsToSeparateLinesRector::class); + $rectorConfig->rule(LogicalToBooleanRector::class); $rectorConfig->rule(CommonNotEqualRector::class); - $rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class); - $rectorConfig->rule(JoinStringConcatRector::class); - $rectorConfig->rule(SimplifyMirrorAssignRector::class); - $rectorConfig->rule(RemoveDeadStmtRector::class); - $rectorConfig->rule(RemovePhpVersionIdCheckRector::class); - $rectorConfig->rule(RemoveConcatAutocastRector::class); - $rectorConfig->rule(RemoveUnusedPrivateMethodRector::class); - $rectorConfig->rule(RemoveUnusedPrivateMethodParameterRector::class); - $rectorConfig->rule(RemoveUnusedConstructorParamRector::class); - $rectorConfig->rule(RemoveEmptyClassMethodRector::class); - $rectorConfig->rule(RemoveUselessParamTagRector::class); - $rectorConfig->rule(RemoveUnusedPrivateClassConstantRector::class); - $rectorConfig->rule(RemoveAndTrueRector::class); - $rectorConfig->rule(RecastingRemovalRector::class); - $rectorConfig->rule(RemoveDeadTryCatchRector::class); - $rectorConfig->rule(ReplaceMultipleBooleanNotRector::class); - $rectorConfig->rule(CombinedAssignRector::class); $rectorConfig->rule(NumberCompareToMaxFuncCallRector::class); - $rectorConfig->rule(RemoveDeadConditionAboveReturnRector::class); - $rectorConfig->rule(RemoveUselessReturnTagRector::class); - $rectorConfig->rule(RemoveDuplicatedArrayKeyRector::class); - $rectorConfig->rule(RemoveDoubleAssignRector::class); - $rectorConfig->rule(RemoveUnusedVariableAssignRector::class); - $rectorConfig->rule(SimplifyUselessVariableRector::class); - $rectorConfig->rule(RemoveAlwaysElseRector::class); - $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); - $rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class); - $rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class); + $rectorConfig->rule(SwitchNegatedTernaryRector::class); + $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); + $rectorConfig->rule(InlineIfToExplicitIfRector::class); + $rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class); + $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class); + $rectorConfig->rule(SimplifyRegexPatternRector::class); $rectorConfig->rule(SimplifyStrposLowerRector::class); $rectorConfig->rule(CombineIfRector::class); - $rectorConfig->rule(SimplifyIfReturnBoolRector::class); - $rectorConfig->rule(InlineIfToExplicitIfRector::class); - $rectorConfig->rule(PreparedValueToEarlyReturnRector::class); $rectorConfig->rule(ShortenElseIfRector::class); $rectorConfig->rule(SimplifyIfElseToTernaryRector::class); - $rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class); - $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class); + $rectorConfig->rule(SimplifyIfReturnBoolRector::class); $rectorConfig->rule(UnnecessaryTernaryExpressionRector::class); - $rectorConfig->rule(SimplifyRegexPatternRector::class); + + // Coding Stlye $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); - $rectorConfig->rule(RemoveUnusedVariableInCatchRector::class); - $rectorConfig->rule(ChangeSwitchToMatchRector::class); - $rectorConfig->rule(FirstClassCallableRector::class); $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); - $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); + $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); + + // Dead Code + $rectorConfig->rule(RemoveDuplicatedArrayKeyRector::class); + $rectorConfig->rule(RemoveDoubleAssignRector::class); + $rectorConfig->rule(RemoveUnusedVariableAssignRector::class); + $rectorConfig->rule(RemoveAndTrueRector::class); + $rectorConfig->rule(RecastingRemovalRector::class); + $rectorConfig->rule(RemoveUnusedPrivateClassConstantRector::class); + $rectorConfig->rule(RemoveEmptyClassMethodRector::class); + $rectorConfig->rule(RemoveUnusedConstructorParamRector::class); + $rectorConfig->rule(RemoveUnusedPrivateMethodParameterRector::class); + $rectorConfig->rule(RemoveUnusedPrivateMethodRector::class); + $rectorConfig->rule(RemoveUselessParamTagRector::class); + $rectorConfig->rule(RemoveUselessReturnTagRector::class); + $rectorConfig->rule(RemoveConcatAutocastRector::class); + $rectorConfig->rule(RemovePhpVersionIdCheckRector::class); + $rectorConfig->rule(RemoveDeadStmtRector::class); + $rectorConfig->rule(SimplifyMirrorAssignRector::class); + $rectorConfig->rule(RemoveDeadZeroAndOneOperationRector::class); + $rectorConfig->rule(RemoveDeadConditionAboveReturnRector::class); + $rectorConfig->rule(RemoveDeadTryCatchRector::class); + + // Another + $rectorConfig->rule(RemoveAlwaysElseRector::class); + $rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class); + $rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class); + $rectorConfig->rule(PreparedValueToEarlyReturnRector::class); $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); - $rectorConfig->rule(CompleteDynamicPropertiesRector::class); - $rectorConfig->rule(Utf8DecodeEncodeToMbConvertEncodingRector::class); }; diff --git a/src/Commands/PublishConfig.php b/src/Commands/PublishConfig.php index f092fb6..3f595ea 100644 --- a/src/Commands/PublishConfig.php +++ b/src/Commands/PublishConfig.php @@ -54,9 +54,9 @@ public function run(array $params) */ protected function determineSourcePath() { - $this->sourcePath = realpath(__DIR__ . '/../'); + $this->sourcePath = realpath(__DIR__ . '/..'); - if ($this->sourcePath === '/' || empty($this->sourcePath)) { + if (in_array($this->sourcePath, ['/', ''], true) || $this->sourcePath === false) { CLI::error('[-] Unable to determine the correct source directory.'); exit();