Skip to content

Commit

Permalink
[REFACTORING] Minor changes and code-quality improvements (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Semmler authored Jun 17, 2022
1 parent 0084127 commit ee63dbc
Show file tree
Hide file tree
Showing 25 changed files with 358 additions and 62 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);
};
5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
typo3: [ ^10.4, ^11.5 ]
php: [ '7.2', '7.3', '7.4' ]
php: [ '7.3', '7.4' ]
experimental: [false]
include:
- typo3: ^11.5
Expand All @@ -31,9 +31,6 @@ jobs:
php: '8.1'
experimental: true
exclude:
- typo3: ^11.5
php: '7.2'
experimental: false
- typo3: ^11.5
php: '7.3'
experimental: false
Expand Down
1 change: 1 addition & 0 deletions Classes/Controller/BeUserController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\RestlerExamples\Controller;

use Luracast\Restler\RestException;
Expand Down
1 change: 1 addition & 0 deletions Classes/Controller/CarController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\RestlerExamples\Controller;

use Aoe\RestlerExamples\Domain\Model\Car;
Expand Down
9 changes: 6 additions & 3 deletions Classes/Controller/ContentController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\RestlerExamples\Controller;

use Aoe\Restler\System\TYPO3\Loader as TYPO3Loader;
Expand Down Expand Up @@ -78,7 +79,8 @@ public function getContentElementByUidForAnyFeUser($pageId, $contentElementUid)
];

return [
'content' => $this->getCObject($pageId)->cObjGetSingle('RECORDS', $cConf)
'content' => $this->getCObject($pageId)
->cObjGetSingle('RECORDS', $cConf),
];
}

Expand All @@ -105,7 +107,8 @@ public function getContentElementByUidForLoggedInFeUser($pageId, $contentElement
'dontCheckPid' => 1,
];
return [
'content' => $this->getCObject($pageId)->cObjGetSingle('RECORDS', $cConf)
'content' => $this->getCObject($pageId)
->cObjGetSingle('RECORDS', $cConf),
];
}

Expand All @@ -115,7 +118,7 @@ public function getContentElementByUidForLoggedInFeUser($pageId, $contentElement
*/
private function getCObject($pageId)
{
if (null === $this->cObject) {
if ($this->cObject === null) {
$this->cObject = $this->initializeCObject($pageId);
}
return $this->cObject;
Expand Down
7 changes: 4 additions & 3 deletions Classes/Controller/ExtbaseExamples/ProductController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\RestlerExamples\Controller\ExtbaseExamples;

use Aoe\RestlerExamples\Domain\Model\Product;
Expand Down Expand Up @@ -86,7 +87,7 @@ public function getProductsAsExtbaseObject($pageUid)
*
* @url GET extbase-model-with-public-properties/pages/{pageUid}/products/{productUid}
* @param integer $pageUid {@min 1} The page-UID of your root-TYPO3-page
* @param integer $productId {@min 1}
* @param integer $productUid {@min 1}
* @return Product {@type Product}
*/
public function getProductAsExtbaseObject($pageUid, $productUid)
Expand Down Expand Up @@ -118,7 +119,7 @@ public function getProductsAsNoneExtbaseObject($pageUid)

$restProducts = [];
foreach ($this->productRepository->findAll() as $extbaseProduct) {
/* @var $extbaseProduct Product */
/** @var Product $extbaseProduct */
$restProduct = new stdClass();
$restProduct->uid = $extbaseProduct->getUid();
$restProduct->name = $extbaseProduct->getName();
Expand All @@ -137,7 +138,7 @@ public function getProductsAsNoneExtbaseObject($pageUid)
*
* @url GET extbase-model-with-none-public-properties/pages/{pageUid}/products/{productUid}
* @param integer $pageUid {@min 1} The page-UID of your root-TYPO3-page
* @param integer $productId {@min 1}
* @param integer $productUid {@min 1}
* @return stdClass
*/
public function getProductAsNoneExtbaseObject($pageUid, $productUid)
Expand Down
1 change: 1 addition & 0 deletions Classes/Controller/FeUserController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Aoe\RestlerExamples\Controller;

use Luracast\Restler\RestException;
Expand Down
Loading

0 comments on commit ee63dbc

Please sign in to comment.