Skip to content
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
48 changes: 48 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

use IxDFCodingStandard\PhpCsFixer\Config;
use PhpCsFixer\Finder;

// Dogfood: lint this package with its own shared PHP-CS-Fixer configuration.
$finder = Finder::create()
->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);
8 changes: 4 additions & 4 deletions IxDFCodingStandard/Helpers/ClassHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
4 changes: 3 additions & 1 deletion IxDFCodingStandard/Helpers/TokenHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion IxDFCodingStandard/Sniffs/Files/BemCasedFilenameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions IxDFCodingStandard/Sniffs/Laravel/PhpViewExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array<string>> $tokens */
Expand Down
8 changes: 4 additions & 4 deletions IxDFCodingStandard/TokenHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace IxDFCodingStandard;

abstract class TestCase extends \SlevomatCodingStandard\Sniffs\TestCase
{
}
abstract class TestCase extends \SlevomatCodingStandard\Sniffs\TestCase {}