Skip to content

Commit

Permalink
[REFACTORING] Minor changes and code-quality improvements (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Semmler authored Jun 17, 2022
1 parent 46b3414 commit 400cf45
Show file tree
Hide file tree
Showing 40 changed files with 516 additions and 197 deletions.
7 changes: 7 additions & 0 deletions .code-quality/configure-checkstyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

chmod +x .Build/vendor/symplify/easy-coding-standard/vendor/squizlabs/php_codesniffer/bin/phpcs
.Build/vendor/symplify/easy-coding-standard/vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths "$(pwd)/.Build/vendor/phpcompatibility/php-compatibility/PHPCompatibility"
.Build/vendor/symplify/easy-coding-standard/vendor/squizlabs/php_codesniffer/bin/phpcs --config-set ignore_warnings_on_exit 1 > /dev/null 2>&1
.Build/vendor/symplify/easy-coding-standard/vendor/squizlabs/php_codesniffer/bin/phpcs --config-set ignore_errors_on_exit 1 > /dev/null 2>&1
.Build/vendor/symplify/easy-coding-standard/vendor/squizlabs/php_codesniffer/bin/phpcs --config-set report_width 200 > /dev/null 2>&1
71 changes: 71 additions & 0 deletions .code-quality/ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\LineLength\DocBlockLineLengthFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
[
__DIR__ . '/../Classes',
__DIR__ . '/ecs.php',
]
);

$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);

$containerConfigurator->services()
->set(LineLengthFixer::class)
->call('configure', [[
LineLengthFixer::LINE_LENGTH => 140,
LineLengthFixer::INLINE_SHORT_LINES => false,
]]);

// Skip Rules and Sniffer
$parameters->set(
Option::SKIP,
[
// Default Skips
Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer::class => [
__DIR__ . '/ecs.php',
],
ArrayListItemNewlineFixer::class => null,
ArrayOpenerAndCloserNewlineFixer::class => null,
ClassAttributesSeparationFixer::class => null,
OrderedImportsFixer::class => null,
NotOperatorWithSuccessorSpaceFixer::class => null,
ExplicitStringVariableFixer::class => null,
ArrayIndentationFixer::class => null,
DocBlockLineLengthFixer::class => null,
'\SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff.DuplicateSpaces' => null,
'\SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff.PartialUse' => null,

// @todo for next upgrade
NoSuperfluousPhpdocTagsFixer::class => null,
// @todo strict php
DeclareStrictTypesFixer::class => null,
StrictComparisonFixer::class => null,
StrictParamFixer::class => null,
]
);
};
2 changes: 2 additions & 0 deletions .code-quality/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors:
39 changes: 39 additions & 0 deletions .code-quality/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
includes:
- phpstan-baseline.neon
- ../.Build/vendor/symplify/phpstan-rules/packages/cognitive-complexity/config/cognitive-complexity-rules.neon

rules:
- Symplify\PHPStanRules\Rules\NoDefaultExceptionRule

parameters:
level: max
paths:
- "../Classes/"

inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

services:
- class: Symplify\Astral\Naming\SimpleNameResolver
- class: Symplify\PHPStanRules\CognitiveComplexity\AstCognitiveComplexityAnalyzer
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeTraverser\ComplexityNodeTraverserFactory
- class: Symplify\PHPStanRules\CognitiveComplexity\DataCollector\CognitiveComplexityDataCollector
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\NestingNodeVisitor
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\ComplexityNodeVisitor
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeAnalyzer\ComplexityAffectingNodeFinder
- class: Symplify\PackageBuilder\Php\TypeChecker
- class: Symplify\PackageBuilder\Matcher\ArrayStringAndFnMatcher
- class: Symplify\PHPStanRules\TypeAnalyzer\ObjectTypeAnalyzer
- class: Symplify\PHPStanRules\TypeAnalyzer\TypeUnwrapper
-
class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule
tags: [phpstan.rules.rule]
arguments:
forbiddenFunctions:
- d
- dd
- die
- dump
- compact
- var_dump
30 changes: 30 additions & 0 deletions .code-quality/rector-8_0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
[
__DIR__ . '/../Classes',
__DIR__ . '/../Tests',
__DIR__ . '/rector.php',
__DIR__ . '/rector-8_0.php',
]
);

$containerConfigurator->import(SetList::PHP_81);

$parameters->set(Option::AUTO_IMPORT_NAMES, false);
$parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/../Classes']);
$parameters->set(Option::SKIP, []);

$services = $containerConfigurator->services();
$services->set(RemoveUnusedPrivatePropertyRector::class);
};
113 changes: 113 additions & 0 deletions .code-quality/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodeQualityStrict\Rector\If_\MoveOutMethodCallInsideIfConditionRector;
use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector;
use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Defluent\Rector\Return_\ReturnFluentChainMethodCallToNormalMethodCallRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector;
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryAndToEarlyReturnRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector;
use Rector\Privatization\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {

$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::PRIVATIZATION);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::PSR_4);
$containerConfigurator->import(SetList::MYSQL_TO_MYSQLI);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::UNWRAP_COMPAT);

$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::PHP_74);
$containerConfigurator->import(SetList::PHP_80);

$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);

$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
[
__DIR__ . '/../Classes',
__DIR__ . '/rector.php',
]
);

$parameters->set(Option::AUTO_IMPORT_NAMES, false);
$parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/../Classes']);
$parameters->set(
Option::SKIP,
[
RecastingRemovalRector::class,
ConsistentPregDelimiterRector::class,
PostIncDecToPreIncDecRector::class,
FinalizeClassesWithoutChildrenRector::class,
ChangeOrIfReturnToEarlyReturnRector::class,
ChangeAndIfToEarlyReturnRector::class,
ReturnBinaryAndToEarlyReturnRector::class,
MakeBoolPropertyRespectIsHasWasMethodNamingRector::class,
MoveOutMethodCallInsideIfConditionRector::class,
ReturnArrayClassMethodToYieldRector::class,
AddArrayParamDocTypeRector::class,
AddArrayReturnDocTypeRector::class,
ReturnFluentChainMethodCallToNormalMethodCallRector::class,
IssetOnPropertyObjectToPropertyExistsRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
RepeatedLiteralToClassConstantRector::class,
RenameVariableToMatchNewTypeRector::class,
AddLiteralSeparatorToNumberRector::class,
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
ChangeReadOnlyVariableWithDefaultValueToConstantRector::class,
PrivatizeLocalPropertyToPrivatePropertyRector::class,
RemoveDelegatingParentCallRector::class,

// @todo strict php
ArgumentAdderRector::class,
ParamTypeDeclarationRector::class,
ReturnTypeDeclarationRector::class,
RemoveExtraParametersRector::class,
EncapsedStringsToSprintfRector::class,
AddFalseDefaultToBoolPropertyRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,
UseIdenticalOverEqualWithSameTypeRector::class,
]
);

$services = $containerConfigurator->services();
$services->set(RemoveUnusedPrivatePropertyRector::class);
};
3 changes: 2 additions & 1 deletion Classes/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Command;

/***************************************************************
Expand Down Expand Up @@ -51,7 +52,7 @@ public function __construct(FeatureFlagService $featureFlagService)

/**
* Enable or disable features. $features can be a comma-separated list of feature names
* @param String $features
* @param string $features
* @param boolean $enabled
* @throws FeatureNotFoundException
* @throws IllegalObjectTypeException
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/ActivateFeatureFlagCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Command;

/***************************************************************
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/DeactivateFeatureFlagCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Command;

/***************************************************************
Expand Down
1 change: 1 addition & 0 deletions Classes/Command/ToggleRecordsCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Command;

/***************************************************************
Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Model/FeatureFlag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Domain\Model;

/***************************************************************
Expand Down
9 changes: 5 additions & 4 deletions Classes/Domain/Model/Mapping.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\FeatureFlag\Domain\Model;

/***************************************************************
Expand Down Expand Up @@ -89,7 +90,7 @@ public function setFeatureFlag(FeatureFlag $featureFlag)
}

/**
* @return \Aoe\FeatureFlag\Domain\Model\FeatureFlag $featureFlag
* @return \Aoe\FeatureFlag\Domain\Model\FeatureFlag
*/
public function getFeatureFlag()
{
Expand Down Expand Up @@ -165,14 +166,14 @@ public function getTstamp()
*/
public function setBehavior($behavior)
{
$this->behavior = (int)$behavior;
$this->behavior = (int) $behavior;
}

/**
* @return string
* @return int
*/
public function getBehavior()
{
return (int)$this->behavior;
return (int) $this->behavior;
}
}
Loading

0 comments on commit 400cf45

Please sign in to comment.