Migrate to php-cs-fixer

This commit is contained in:
Daniel Siepmann 2023-04-26 17:29:23 +02:00
parent a0d577e89f
commit feeb7d4235
22 changed files with 99 additions and 366 deletions

3
.gitattributes vendored
View file

@ -5,8 +5,7 @@ shell.nix export-ignore
.gitattributes export-ignore .gitattributes export-ignore
.gitignore export-ignore .gitignore export-ignore
ecs.php export-ignore
phpcs.xml.dist export-ignore
phpstan-baseline.neon export-ignore phpstan-baseline.neon export-ignore
phpstan.neon export-ignore phpstan.neon export-ignore
phpunit.xml.dist export-ignore phpunit.xml.dist export-ignore
.php-cs-fixer.dist.php export-ignore

View file

@ -85,7 +85,7 @@ jobs:
- name: Install PHP - name: Install PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: "7.4" php-version: "8.2"
coverage: none coverage: none
tools: composer:v2 tools: composer:v2
env: env:
@ -95,7 +95,7 @@ jobs:
run: composer install --prefer-dist --no-progress run: composer install --prefer-dist --no-progress
- name: Coding Guideline - name: Coding Guideline
run: ./vendor/bin/ecs check run: ./vendor/bin/php-cs-fixer fix --dry-run --diff
tests-mysql: tests-mysql:
runs-on: ubuntu-latest runs-on: ubuntu-latest

63
.php-cs-fixer.dist.php Normal file
View file

@ -0,0 +1,63 @@
<?php
$finder = (new PhpCsFixer\Finder())
->ignoreVCSIgnored(true)
->in(realpath(__DIR__))
;
return (new \PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
'cast_spaces' => ['space' => 'none'],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
'function_typehint_space' => true,
'lowercase_cast' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'modernize_strpos' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'single_trait_insert_per_statement' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
])
->setFinder($finder);

View file

@ -102,16 +102,16 @@ class PageviewsPerDay implements ChartDataProviderInterface
$data = []; $data = [];
for ($daysBefore = $this->days; $daysBefore >= 0; $daysBefore--) { for ($daysBefore = $this->days; $daysBefore >= 0; $daysBefore--) {
$label = date($this->dateFormat, (int) strtotime('-' . $daysBefore . ' day')); $label = date($this->dateFormat, (int)strtotime('-' . $daysBefore . ' day'));
$labels[$label] = $label; $labels[$label] = $label;
$data[$label] = 0; $data[$label] = 0;
} }
$start = (int) strtotime('-' . $this->days . ' day 0:00:00'); $start = (int)strtotime('-' . $this->days . ' day 0:00:00');
$end = (int) strtotime('tomorrow midnight'); $end = (int)strtotime('tomorrow midnight');
foreach ($this->getPageviewsInPeriod($start, $end) as $day) { foreach ($this->getPageviewsInPeriod($start, $end) as $day) {
$data[$day['label']] = (int) $day['count']; $data[$day['label']] = (int)$day['count'];
} }
return [ return [

View file

@ -145,7 +145,7 @@ class PageviewsPerPage implements ChartDataProviderInterface
continue; continue;
} }
$labels[] = $this->getRecordTitle((int) $row['pid']); $labels[] = $this->getRecordTitle((int)$row['pid']);
$data[] = $row['total']; $data[] = $row['total'];
} }

View file

@ -119,7 +119,7 @@ class Recordviews implements ChartDataProviderInterface
continue; continue;
} }
$record = $this->getRecord( $record = $this->getRecord(
(int) $recordview['record_uid'], (int)$recordview['record_uid'],
$recordview['record_table_name'] $recordview['record_table_name']
); );

View file

@ -49,8 +49,8 @@ class Factory
$this->getRouting($request)->getPageId(), $this->getRouting($request)->getPageId(),
$this->getLanguage($request), $this->getLanguage($request),
new DateTimeImmutable(), new DateTimeImmutable(),
(int) $this->getRouting($request)->getPageType(), (int)$this->getRouting($request)->getPageType(),
(string) $request->getUri(), (string)$request->getUri(),
$request->getHeader('User-Agent')[0] ?? '' $request->getHeader('User-Agent')[0] ?? ''
); );
} }
@ -58,13 +58,13 @@ class Factory
public function fromDbRow(array $dbRow): Pageview public function fromDbRow(array $dbRow): Pageview
{ {
return new Pageview( return new Pageview(
(int) $dbRow['pid'], (int)$dbRow['pid'],
$this->siteFinder->getSiteByPageId((int) $dbRow['pid'])->getLanguageById((int) $dbRow['sys_language_uid']), $this->siteFinder->getSiteByPageId((int)$dbRow['pid'])->getLanguageById((int)$dbRow['sys_language_uid']),
new DateTimeImmutable('@' . $dbRow['crdate']), new DateTimeImmutable('@' . $dbRow['crdate']),
(int) $dbRow['type'], (int)$dbRow['type'],
$dbRow['url'], $dbRow['url'],
$dbRow['user_agent'], $dbRow['user_agent'],
(int) $dbRow['uid'] (int)$dbRow['uid']
); );
} }

View file

@ -69,9 +69,9 @@ class Factory
self::getRouting($request)->getPageId(), self::getRouting($request)->getPageId(),
self::getLanguage($request), self::getLanguage($request),
new DateTimeImmutable(), new DateTimeImmutable(),
(string) $request->getUri(), (string)$request->getUri(),
$request->getHeader('User-Agent')[0] ?? '', $request->getHeader('User-Agent')[0] ?? '',
(int) $recordUid, (int)$recordUid,
$rule->getTableName() $rule->getTableName()
); );
} }

View file

@ -59,7 +59,7 @@ class Pageview
; ;
if (is_numeric($result)) { if (is_numeric($result)) {
return (int) $result; return (int)$result;
} }
return 0; return 0;

View file

@ -88,7 +88,7 @@ class Pageview implements MiddlewareInterface
ServerRequestInterface $request, ServerRequestInterface $request,
Context $context Context $context
): bool { ): bool {
return (bool) $this->expressionFactory->create( return (bool)$this->expressionFactory->create(
$this->rule, $this->rule,
[ [
'request' => $request, 'request' => $request,

View file

@ -93,7 +93,7 @@ class Recordview implements MiddlewareInterface
Context $context, Context $context,
RecordRule $rule RecordRule $rule
): bool { ): bool {
return (bool) $this->expressionFactory->create( return (bool)$this->expressionFactory->create(
$rule->getMatchesExpression(), $rule->getMatchesExpression(),
[ [
'request' => $request, 'request' => $request,

View file

@ -1,4 +1,5 @@
<?php <?php
return [ return [
'tracking' => [ 'tracking' => [
'title' => 'LLL:EXT:tracking/Resources/Private/Language/locallang.xlf:dashboard.widget.group.tracking', 'title' => 'LLL:EXT:tracking/Resources/Private/Language/locallang.xlf:dashboard.widget.group.tracking',

View file

@ -2,6 +2,7 @@
use DanielSiepmann\Tracking\Middleware\Pageview; use DanielSiepmann\Tracking\Middleware\Pageview;
use DanielSiepmann\Tracking\Middleware\Recordview; use DanielSiepmann\Tracking\Middleware\Recordview;
return [ return [
'frontend' => [ 'frontend' => [
'danielsiepmann/tracking/pageview' => [ 'danielsiepmann/tracking/pageview' => [

View file

@ -39,7 +39,7 @@ return [
], ],
'sys_language_uid' => [ 'sys_language_uid' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.sys_language', 'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.sys_language',
'config' => ['type' => 'language'] 'config' => ['type' => 'language'],
], ],
'user_agent' => [ 'user_agent' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.user_agent', 'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.user_agent',

View file

@ -39,7 +39,7 @@ return [
], ],
'sys_language_uid' => [ 'sys_language_uid' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.recordview.sys_language', 'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.recordview.sys_language',
'config' => ['type' => 'language'] 'config' => ['type' => 'language'],
], ],
'user_agent' => [ 'user_agent' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.recordview.user_agent', 'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.recordview.user_agent',

View file

@ -30,6 +30,9 @@ Tasks
* Remove leftovers of rector * Remove leftovers of rector
We don't need to carry those files if we don't use them right now. We don't need to carry those files if we don't use them right now.
* Migrate to php-cs-fixer
That way this projects follows best practices and is streamlined to other projects.
Deprecation Deprecation
----------- -----------

View file

@ -64,12 +64,12 @@ class PageviewTest extends TestCase
$records = $this->getAllRecords('tx_tracking_pageview'); $records = $this->getAllRecords('tx_tracking_pageview');
self::assertCount(1, $records); self::assertCount(1, $records);
self::assertSame('1', (string) $records[0]['pid']); self::assertSame('1', (string)$records[0]['pid']);
self::assertSame('1', (string) $records[0]['uid']); self::assertSame('1', (string)$records[0]['uid']);
self::assertSame('http://localhost/?id=1', $records[0]['url']); self::assertSame('http://localhost/?id=1', $records[0]['url']);
self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']);
self::assertSame('Macintosh', $records[0]['operating_system']); self::assertSame('Macintosh', $records[0]['operating_system']);
self::assertSame('0', (string) $records[0]['type']); self::assertSame('0', (string)$records[0]['type']);
} }
/** /**

View file

@ -73,13 +73,13 @@ class RecordviewTest extends TestCase
$records = $this->getAllRecords('tx_tracking_recordview'); $records = $this->getAllRecords('tx_tracking_recordview');
self::assertCount(1, $records); self::assertCount(1, $records);
self::assertSame('1', (string) $records[0]['pid']); self::assertSame('1', (string)$records[0]['pid']);
self::assertSame('1', (string) $records[0]['uid']); self::assertSame('1', (string)$records[0]['uid']);
self::assertSame('http://localhost/?id=1&topic_id=1', $records[0]['url']); self::assertSame('http://localhost/?id=1&topic_id=1', $records[0]['url']);
self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']);
self::assertSame('Macintosh', $records[0]['operating_system']); self::assertSame('Macintosh', $records[0]['operating_system']);
self::assertSame('sys_category_1', $records[0]['record']); self::assertSame('sys_category_1', $records[0]['record']);
self::assertSame('1', (string) $records[0]['record_uid']); self::assertSame('1', (string)$records[0]['record_uid']);
self::assertSame('sys_category', $records[0]['record_table_name']); self::assertSame('sys_category', $records[0]['record_table_name']);
} }

View file

@ -40,12 +40,12 @@
}, },
"require-dev": { "require-dev": {
"cweagans/composer-patches": "^1.7", "cweagans/composer-patches": "^1.7",
"friendsofphp/php-cs-fixer": "^3.14",
"jangregor/phpstan-prophecy": "^1.0", "jangregor/phpstan-prophecy": "^1.0",
"phpspec/prophecy-phpunit": "^2.0", "phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1", "phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8.7", "phpstan/phpstan": "^1.8.7",
"phpunit/phpunit": "^9.0", "phpunit/phpunit": "^9.0",
"symplify/easy-coding-standard": "^11.1",
"typo3/testing-framework": "^7.0" "typo3/testing-framework": "^7.0"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",

312
ecs.php
View file

@ -1,312 +0,0 @@
<?php
use PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\ArrayIndentSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff;
use PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff;
use PHP_CodeSniffer\Standards\PSR12\Sniffs\ControlStructures\ControlStructureSpacingSniff as PSR12ControlStructureSpacingSniff;
use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff;
use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
use PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer;
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer;
use PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer;
use PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer;
use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer;
use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer;
use PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer;
use PhpCsFixer\Fixer\Basic\NonPrintableCharacterFixer;
use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer;
use PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer;
use PhpCsFixer\Fixer\CastNotation\NoUnsetCastFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer;
use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer;
use PhpCsFixer\Fixer\Comment\MultilineCommentOpeningClosingFixer;
use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer;
use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer;
use PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer;
use PhpCsFixer\Fixer\ControlStructure\NoSuperfluousElseifFixer;
use PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer;
use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer;
use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer;
use PhpCsFixer\Fixer\ControlStructure\SimplifiedIfReturnFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\FunctionNotation\NoTrailingCommaInSinglelineFunctionCallFixer;
use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer;
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\RegularCallableCallFixer;
use PhpCsFixer\Fixer\FunctionNotation\StaticLambdaFixer;
use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer;
use PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAfterConstructFixer;
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
use PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer;
use PhpCsFixer\Fixer\Naming\NoHomoglyphNamesFixer;
use PhpCsFixer\Fixer\Operator\IncrementStyleFixer;
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer;
use PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer;
use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer;
use PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer;
use PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer;
use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer;
use PhpCsFixer\Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer;
use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitFqcnAnnotationFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockShortWillReturnFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitNamespacedFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitSetUpTearDownVisibilityFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer;
use PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer;
use PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer;
use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer;
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
use PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer;
use PhpCsFixer\Fixer\StringNotation\NoTrailingWhitespaceInStringFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\StringNotation\StringLengthToEmptyFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer;
use PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([
SetList::PSR_12,
]);
$ecsConfig->paths([
__DIR__ . '/Classes',
__DIR__ . '/Tests',
__DIR__ . '/ecs.php',
__DIR__ . '/ext_emconf.php',
__DIR__ . '/ext_localconf.php',
__DIR__ . '/rector.php',
]);
$ecsConfig->skip([
CamelCapsMethodNameSniff::class => [
__DIR__ . '/Classes/Hooks/DataHandler.php',
],
]);
// Alias
$ecsConfig->rule(MbStrFunctionsFixer::class);
$ecsConfig->rule(NoAliasFunctionsFixer::class);
// ArrayNotation
$ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [
'syntax' => 'short',
]);
$ecsConfig->rule(NoMultilineWhitespaceAroundDoubleArrowFixer::class);
$ecsConfig->rule(NormalizeIndexBraceFixer::class);
$ecsConfig->rule(NoTrailingCommaInSinglelineArrayFixer::class);
$ecsConfig->rule(NoWhitespaceBeforeCommaInArrayFixer::class);
$ecsConfig->rule(TrimArraySpacesFixer::class);
// Basic
$ecsConfig->rule(NoMultipleStatementsPerLineFixer::class);
$ecsConfig->rule(NonPrintableCharacterFixer::class);
// Casing
$ecsConfig->rule(NativeFunctionCasingFixer::class);
$ecsConfig->rule(NativeFunctionTypeDeclarationCasingFixer::class);
// CastNotation
$ecsConfig->rule(CastSpacesFixer::class);
$ecsConfig->rule(ModernizeTypesCastingFixer::class);
$ecsConfig->rule(NoUnsetCastFixer::class);
// ClassNotation
$ecsConfig->ruleWithConfiguration(ClassAttributesSeparationFixer::class, [
'elements' => [
'const' => 'one',
'method' => 'one',
'property' => 'one',
'trait_import' => 'one',
],
]);
$ecsConfig->rule(NoNullPropertyInitializationFixer::class);
$ecsConfig->rule(SelfAccessorFixer::class);
$ecsConfig->rule(MultilineCommentOpeningClosingFixer::class);
$ecsConfig->rule(NoEmptyCommentFixer::class);
$ecsConfig->rule(SinglelineCommentSpacingFixer::class);
$ecsConfig->rule(SingleLineCommentStyleFixer::class);
// ControlStructure
$ecsConfig->rule(NoSuperfluousElseifFixer::class);
$ecsConfig->rule(NoTrailingCommaInListCallFixer::class);
$ecsConfig->rule(NoUnneededControlParenthesesFixer::class);
$ecsConfig->rule(NoUselessElseFixer::class);
$ecsConfig->rule(SimplifiedIfReturnFixer::class);
$ecsConfig->rule(TrailingCommaInMultilineFixer::class);
$ecsConfig->rule(PSR12ControlStructureSpacingSniff::class);
// FunctionNotation
$ecsConfig->rule(NoTrailingCommaInSinglelineFunctionCallFixer::class);
$ecsConfig->rule(NoUnreachableDefaultArgumentValueFixer::class);
$ecsConfig->rule(NoUselessSprintfFixer::class);
$ecsConfig->rule(NullableTypeDeclarationForDefaultNullValueFixer::class);
$ecsConfig->rule(RegularCallableCallFixer::class);
$ecsConfig->rule(StaticLambdaFixer::class);
// Import
$ecsConfig->rule(FullyQualifiedStrictTypesFixer::class);
$ecsConfig->rule(GlobalNamespaceImportFixer::class);
$ecsConfig->rule(NoUnneededImportAliasFixer::class);
$ecsConfig->rule(NoUnusedImportsFixer::class);
$ecsConfig->ruleWithConfiguration(OrderedImportsFixer::class, [
'sort_algorithm' => 'alpha',
]);
// LanguageConstruct
$ecsConfig->rule(CombineConsecutiveIssetsFixer::class);
$ecsConfig->rule(CombineConsecutiveUnsetsFixer::class);
$ecsConfig->rule(SingleSpaceAfterConstructFixer::class);
// ListNotation
$ecsConfig->rule(ListSyntaxFixer::class);
// NamespaceNotation
$ecsConfig->rule(SingleBlankLineBeforeNamespaceFixer::class);
// Naming
$ecsConfig->rule(CamelCapsMethodNameSniff::class);
$ecsConfig->rule(NoHomoglyphNamesFixer::class);
$ecsConfig->rule(UpperCaseConstantNameSniff::class);
// Operator
$ecsConfig->ruleWithConfiguration(IncrementStyleFixer::class, [
'style' => 'post',
]);
$ecsConfig->ruleWithConfiguration(NewWithBracesFixer::class, [
'anonymous_class' => false,
'named_class' => true,
]);
$ecsConfig->rule(ObjectOperatorWithoutWhitespaceFixer::class);
$ecsConfig->ruleWithConfiguration(OperatorLinebreakFixer::class, [
'position' => 'beginning',
]);
$ecsConfig->rule(StandardizeIncrementFixer::class);
$ecsConfig->rule(TernaryToElvisOperatorFixer::class);
$ecsConfig->rule(TernaryToNullCoalescingFixer::class);
$ecsConfig->rule(UnaryOperatorSpacesFixer::class);
// Phpdoc
$ecsConfig->rule(NoBlankLinesAfterPhpdocFixer::class);
$ecsConfig->rule(NoEmptyPhpdocFixer::class);
$ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, [
'allow_mixed' => true,
]);
$ecsConfig->ruleWithConfiguration(PhpdocAlignFixer::class, [
'align' => 'left',
]);
$ecsConfig->rule(PhpdocIndentFixer::class);
$ecsConfig->rule(PhpdocLineSpanFixer::class);
$ecsConfig->rule(PhpdocNoAccessFixer::class);
$ecsConfig->ruleWithConfiguration(PhpdocOrderByValueFixer::class, [
'annotations' => [
'covers',
'throws',
],
]);
$ecsConfig->rule(PhpdocOrderFixer::class);
$ecsConfig->rule(PhpdocScalarFixer::class);
$ecsConfig->rule(PhpdocSeparationFixer::class);
$ecsConfig->rule(PhpdocToCommentFixer::class);
$ecsConfig->rule(PhpdocTrimConsecutiveBlankLineSeparationFixer::class);
$ecsConfig->rule(PhpdocTrimFixer::class);
$ecsConfig->rule(PhpdocTypesFixer::class);
$ecsConfig->rule(PhpdocTypesOrderFixer::class);
$ecsConfig->rule(PhpdocVarAnnotationCorrectOrderFixer::class);
$ecsConfig->rule(PhpdocVarWithoutNameFixer::class);
// PhpUnit
$ecsConfig->rule(PhpUnitConstructFixer::class);
$ecsConfig->rule(PhpUnitDedicateAssertFixer::class);
$ecsConfig->rule(PhpUnitDedicateAssertInternalTypeFixer::class);
$ecsConfig->rule(PhpUnitFqcnAnnotationFixer::class);
$ecsConfig->rule(PhpUnitMethodCasingFixer::class);
$ecsConfig->rule(PhpUnitMockFixer::class);
$ecsConfig->rule(PhpUnitMockShortWillReturnFixer::class);
$ecsConfig->rule(PhpUnitNamespacedFixer::class);
$ecsConfig->rule(PhpUnitNoExpectationAnnotationFixer::class);
$ecsConfig->rule(PhpUnitSetUpTearDownVisibilityFixer::class);
$ecsConfig->rule(PhpUnitStrictFixer::class);
$ecsConfig->ruleWithConfiguration(PhpUnitTestAnnotationFixer::class, [
'style' => 'annotation',
]);
$ecsConfig->ruleWithConfiguration(PhpUnitTestCaseStaticMethodCallsFixer::class, [
'call_type' => 'self',
]);
$ecsConfig->rule(PhpUnitTestClassRequiresCoversFixer::class);
// ReturnNotation
$ecsConfig->rule(NoUselessReturnFixer::class);
// Semicolon
$ecsConfig->ruleWithConfiguration(MultilineWhitespaceBeforeSemicolonsFixer::class, [
'strategy' => 'new_line_for_chained_calls',
]);
$ecsConfig->rule(NoEmptyStatementFixer::class);
$ecsConfig->rule(NoSinglelineWhitespaceBeforeSemicolonsFixer::class);
$ecsConfig->rule(SemicolonAfterInstructionFixer::class);
// StringNotation
$ecsConfig->rule(NoTrailingWhitespaceInStringFixer::class);
$ecsConfig->rule(SingleQuoteFixer::class);
$ecsConfig->rule(StringLengthToEmptyFixer::class);
// Whitespace
$ecsConfig->rule(ArrayIndentationFixer::class);
$ecsConfig->rule(ArrayIndentSniff::class);
$ecsConfig->rule(CompactNullableTypehintFixer::class);
$ecsConfig->rule(MethodChainingIndentationFixer::class);
$ecsConfig->rule(NoExtraBlankLinesFixer::class);
$ecsConfig->rule(NoSpacesAroundOffsetFixer::class);
$ecsConfig->ruleWithConfiguration(OperatorSpacingSniff::class, [
'ignoreSpacingBeforeAssignments' => false,
'ignoreNewlines' => true,
]);
$ecsConfig->rule(StatementIndentationFixer::class);
$ecsConfig->rule(TypesSpacesFixer::class);
};

View file

@ -1,22 +0,0 @@
<?xml version="1.0"?>
<ruleset name="project">
<description>This project coding standard</description>
<file>Classes/</file>
<file>Tests/</file>
<!-- Set default settings -->
<arg value="sp"/>
<arg name="colors"/>
<arg name="encoding" value="utf-8" />
<arg name="extensions" value="php" />
<!-- Base rules -->
<rule ref="PSR12" />
<rule ref="Generic.Files.LineLength.TooLong">
<exclude-pattern>/Tests/*</exclude-pattern>
</rule>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>/Classes/Hooks/DataHandler.php</exclude-pattern>
</rule>
</ruleset>

View file

@ -55,7 +55,7 @@ let
php php
]; ];
text = '' text = ''
./vendor/bin/ecs check ./vendor/bin/php-cs-fixer fix --dry-run --diff
''; '';
}; };
projectCglFix = pkgs.writeShellApplication { projectCglFix = pkgs.writeShellApplication {
@ -64,7 +64,7 @@ let
php php
]; ];
text = '' text = ''
./vendor/bin/ecs check --fix ./vendor/bin/php-cs-fixer fix --diff
''; '';
}; };