diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..5c54f2a --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,48 @@ +name: PHP-CS-Fixer + +on: + pull_request: + push: + branches: + - "main" + workflow_dispatch: + +concurrency: + group: php-cs-fixer-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 + + - name: Setup PHP + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2 + with: + php-version: 8.4 + coverage: none + extensions: mbstring + + - name: Get Composer cache directory + id: composer-cache + run: | + echo "composer_dir={$(composer config cache-files-dir)}" >> $GITHUB_OUTPUT + + - name: Retrieve Composer‘s cache + uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6 + with: + path: ${{ steps.composer-cache.outputs.composer_dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install composer dependencies + run: "composer install --no-interaction --no-progress --no-scripts" + + # Dogfood: lint this package with its own shared PHP-CS-Fixer config. + # A hard gate (not auto-fixed) so a renamed/removed rule from a dependency bump fails loudly. + - name: Run PHP-CS-Fixer + run: composer php-cs-fixer:check diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..30484d4 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,16 @@ +in(__DIR__) + ->exclude(['vendor', '.cache']) + // Sniff test fixtures are intentionally malformed; reformatting them would shift line numbers and break the sniff tests. + ->notPath('#^tests/Sniffs/#') + ->name('*.php'); + +// mb_str_functions targets user-facing application strings. This package only processes ASCII PHP tokens, +// so keep the plain byte-string functions and avoid pulling in an ext-mbstring runtime dependency. +return Config::create(__DIR__, ruleOverrides: ['mb_str_functions' => false], finder: $finder); diff --git a/IxDFCodingStandard/Helpers/ClassHelper.php b/IxDFCodingStandard/Helpers/ClassHelper.php index fcace7d..cf04bb5 100644 --- a/IxDFCodingStandard/Helpers/ClassHelper.php +++ b/IxDFCodingStandard/Helpers/ClassHelper.php @@ -2,7 +2,7 @@ namespace IxDFCodingStandard\Helpers; -/** Created based on \SlevomatCodingStandard\Helpers to have a SSoT for this internal API */ -final class ClassHelper extends \SlevomatCodingStandard\Helpers\ClassHelper -{ -} +/** + * Created based on \SlevomatCodingStandard\Helpers to have a SSoT for this internal API + */ +final class ClassHelper extends \SlevomatCodingStandard\Helpers\ClassHelper {} diff --git a/IxDFCodingStandard/Helpers/TokenHelper.php b/IxDFCodingStandard/Helpers/TokenHelper.php index 716d735..33c320f 100644 --- a/IxDFCodingStandard/Helpers/TokenHelper.php +++ b/IxDFCodingStandard/Helpers/TokenHelper.php @@ -2,7 +2,9 @@ namespace IxDFCodingStandard\Helpers; -/** Created based on \SlevomatCodingStandard\Helpers to have a SSoT for this internal API */ +/** + * Created based on \SlevomatCodingStandard\Helpers to have a SSoT for this internal API + */ final class TokenHelper extends \SlevomatCodingStandard\Helpers\TokenHelper { public const array NAME_TOKEN_CODES = parent::NAME_TOKEN_CODES; diff --git a/IxDFCodingStandard/Sniffs/Files/BemCasedFilenameSniff.php b/IxDFCodingStandard/Sniffs/Files/BemCasedFilenameSniff.php index 18c34ca..605a298 100644 --- a/IxDFCodingStandard/Sniffs/Files/BemCasedFilenameSniff.php +++ b/IxDFCodingStandard/Sniffs/Files/BemCasedFilenameSniff.php @@ -5,7 +5,9 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; -/** Checks that all file names are BEM-cased. */ +/** + * Checks that all file names are BEM-cased. + */ final class BemCasedFilenameSniff implements Sniff { private const ERROR_TOO_MANY_DELIMITERS = 'TooManyElementModifiers'; diff --git a/IxDFCodingStandard/Sniffs/Functions/MissingOptionalArgumentSniff.php b/IxDFCodingStandard/Sniffs/Functions/MissingOptionalArgumentSniff.php index b22080b..49ff7e3 100644 --- a/IxDFCodingStandard/Sniffs/Functions/MissingOptionalArgumentSniff.php +++ b/IxDFCodingStandard/Sniffs/Functions/MissingOptionalArgumentSniff.php @@ -7,7 +7,9 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; -/** Inspired by {@see \SlevomatCodingStandard\Sniffs\Functions\StrictCallSniff}. */ +/** + * Inspired by {@see \SlevomatCodingStandard\Sniffs\Functions\StrictCallSniff}. + */ final class MissingOptionalArgumentSniff implements Sniff { public const CODE_MISSING_OPTIONAL_ARGUMENT = 'MissingOptionalArgument'; @@ -50,7 +52,7 @@ public function process(File $phpcsFile, $stringPointer): void // phpcs:ignore S if ($isMethodCall) { $fqcn = $this->getClassNameOfMethodCall($phpcsFile, $stringPointer); - $fullyQualifiedFunctionName = "$fqcn::$functionName"; + $fullyQualifiedFunctionName = "{$fqcn}::{$functionName}"; if (! array_key_exists($fullyQualifiedFunctionName, $this->staticMethods)) { return; diff --git a/IxDFCodingStandard/Sniffs/Laravel/BladeTemplateExtractor.php b/IxDFCodingStandard/Sniffs/Laravel/BladeTemplateExtractor.php index 19e18f3..b149e46 100644 --- a/IxDFCodingStandard/Sniffs/Laravel/BladeTemplateExtractor.php +++ b/IxDFCodingStandard/Sniffs/Laravel/BladeTemplateExtractor.php @@ -4,7 +4,7 @@ use BadMethodCallException; -/** phpcs:disable IxDFCodingStandard.Laravel.NonExistingBladeTemplate.TemplateNotFound */ +// phpcs:disable IxDFCodingStandard.Laravel.NonExistingBladeTemplate.TemplateNotFound -- directive, kept as a line comment so PHP-CS-Fixer does not turn it into a multi-line doc block final class BladeTemplateExtractor { private const INVALID_METHOD_CALL = 'Invalid method call'; diff --git a/IxDFCodingStandard/Sniffs/Laravel/DisallowGuardedAttributeSniff.php b/IxDFCodingStandard/Sniffs/Laravel/DisallowGuardedAttributeSniff.php index 55683f0..4dd2981 100644 --- a/IxDFCodingStandard/Sniffs/Laravel/DisallowGuardedAttributeSniff.php +++ b/IxDFCodingStandard/Sniffs/Laravel/DisallowGuardedAttributeSniff.php @@ -24,7 +24,7 @@ public function __construct() } /** @inheritDoc */ - protected function processTokenWithinScope(File $phpcsFile, $varPointer, $currScope) + protected function processTokenWithinScope(File $phpcsFile, $varPointer, $currScope): void { $varToken = $phpcsFile->getTokens()[$varPointer]; @@ -57,7 +57,7 @@ protected function processTokenWithinScope(File $phpcsFile, $varPointer, $currSc } /** @inheritDoc */ - protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr): void { // nothing to do here } diff --git a/IxDFCodingStandard/Sniffs/Laravel/PhpViewExtractor.php b/IxDFCodingStandard/Sniffs/Laravel/PhpViewExtractor.php index e676397..bcdde77 100644 --- a/IxDFCodingStandard/Sniffs/Laravel/PhpViewExtractor.php +++ b/IxDFCodingStandard/Sniffs/Laravel/PhpViewExtractor.php @@ -15,10 +15,10 @@ public function isViewFunction(array $tokens, int $position): bool return false; } - return $tokens[$position - 1]['type'] === 'T_WHITESPACE' && - $tokens[$position]['content'] === 'view' && - $tokens[$position + 1]['content'] === '(' && - $tokens[$position + 2]['type'] === 'T_CONSTANT_ENCAPSED_STRING'; + return $tokens[$position - 1]['type'] === 'T_WHITESPACE' + && $tokens[$position]['content'] === 'view' + && $tokens[$position + 1]['content'] === '(' + && $tokens[$position + 2]['type'] === 'T_CONSTANT_ENCAPSED_STRING'; } /** @param array> $tokens */ diff --git a/IxDFCodingStandard/TokenHelper.php b/IxDFCodingStandard/TokenHelper.php index 0fc1578..ec9ed1a 100644 --- a/IxDFCodingStandard/TokenHelper.php +++ b/IxDFCodingStandard/TokenHelper.php @@ -2,7 +2,7 @@ namespace IxDFCodingStandard; -/** Just a wrapper for the parent class that is marked as internal */ -final class TokenHelper extends \SlevomatCodingStandard\Helpers\TokenHelper -{ -} +/** + * Just a wrapper for the parent class that is marked as internal + */ +final class TokenHelper extends \SlevomatCodingStandard\Helpers\TokenHelper {} diff --git a/composer.json b/composer.json index 2406556..3bcddb8 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,8 @@ "cs": "@cs:fix", "cs:check": "phpcs -p -s --colors --report-full --report-summary --cache=.cache/phpcs", "cs:fix": "phpcbf -p --colors --cache=.cache/phpcs", + "php-cs-fixer": "php-cs-fixer fix --no-interaction --ansi", + "php-cs-fixer:check": "php-cs-fixer fix --dry-run --diff --no-interaction --ansi", "sa": "@psalm", "psalm": "psalm --config=psalm.xml", "psalm:bl": "@psalm --set-baseline=psalm-baseline.xml --long-progress --no-cache", diff --git a/tests/TestCase.php b/tests/TestCase.php index 14deb77..0db37b0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,4 @@ namespace IxDFCodingStandard; -abstract class TestCase extends \SlevomatCodingStandard\Sniffs\TestCase -{ -} +abstract class TestCase extends \SlevomatCodingStandard\Sniffs\TestCase {}