Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rules rector #21

Merged
merged 1 commit into from
Sep 20, 2023
Merged
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
15 changes: 0 additions & 15 deletions admin/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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..."

Expand Down
125 changes: 60 additions & 65 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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);
};
4 changes: 2 additions & 2 deletions src/Commands/PublishConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down