Skip to content

Commit

Permalink
Differentiate rule sets
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaudo committed Mar 6, 2024
1 parent 6ed5c4f commit 826d387
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CodingStyle::LIBRARIES,
])
->withPaths([
__DIR__ . '/sets',
__DIR__ . '/src',
__DIR__.'/sets',
__DIR__.'/src',
])
->withRootFiles();
23 changes: 13 additions & 10 deletions sets/libraries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

declare(strict_types=1);

use Hereldar\CodingStyle\Rules\ClarifyingParenthesesAroundComparisonsFixer;
use Hereldar\CodingStyle\Rules\MultilineWhitespaceBeforeDoubleColonFixer;
use Hereldar\CodingStyle;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig
::configure()
->withPhpCsFixerSets(
per: true,
php80Migration: true,
php80MigrationRisky: true,
->withSets([
CodingStyle::PROJECTS,
])
->withConfiguredRule(
GlobalNamespaceImportFixer::class,
['import_classes' => true, 'import_constants' => false, 'import_functions' => false]
)
->withRules([
ClarifyingParenthesesAroundComparisonsFixer::class,
MultilineWhitespaceBeforeDoubleColonFixer::class,
]);
->withConfiguredRule(
YodaStyleFixer::class,
['equal' => true, 'identical' => true, 'less_and_greater' => true],
);
16 changes: 14 additions & 2 deletions sets/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@

use Hereldar\CodingStyle\Rules\ClarifyingParenthesesAroundComparisonsFixer;
use Hereldar\CodingStyle\Rules\MultilineWhitespaceBeforeDoubleColonFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig
::configure()
->withPhpCsFixerSets(
per: true,
php80Migration: true,
php80MigrationRisky: true,
per: true,
perRisky: true,
symfony: true,
)
->withRules([
ClarifyingParenthesesAroundComparisonsFixer::class,
MultilineWhitespaceBeforeDoubleColonFixer::class,
]);
])
->withConfiguredRule(
PhpdocAlignFixer::class,
['align' => 'left'],
)
->withConfiguredRule(
YodaStyleFixer::class,
['equal' => false, 'identical' => false, 'less_and_greater' => false],
);
4 changes: 2 additions & 2 deletions src/CodingStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

final class CodingStyle
{
public const PROJECTS = __DIR__ . '/../sets/projects.php';
public const LIBRARIES = __DIR__ . '/../sets/libraries.php';
public const PROJECTS = __DIR__.'/../sets/projects.php';
public const LIBRARIES = __DIR__.'/../sets/libraries.php';
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
* @var Token $token
*/
foreach ($tokens as $index => $token) {

if (!$token->isGivenKind(self::TARGET_KINDS)
|| $token->equalsAny(self::TARGET_TOKENS)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use PhpCsFixer\Tokenizer\Tokens;
use SplFileInfo;

use function count;

final class MultilineWhitespaceBeforeDoubleColonFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
{
public function getDefinition(): FixerDefinitionInterface
Expand Down Expand Up @@ -55,7 +53,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
{
$lineEnding = $this->whitespacesConfig->getLineEnding();

for ($index = 0, $count = count($tokens); $index < $count; ++$index) {
for ($index = 0, $count = \count($tokens); $index < $count; ++$index) {
if (!$tokens[$index]->isGivenKind(T_DOUBLE_COLON)) {
continue;
}
Expand All @@ -65,7 +63,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
continue;
}

$newline = new Token([T_WHITESPACE, $lineEnding . $indent]);
$newline = new Token([T_WHITESPACE, $lineEnding.$indent]);

$previousIndex = $index - 1;
$previous = $tokens[$previousIndex];
Expand All @@ -86,7 +84,7 @@ private function findIndentBeforeNextObjectOperators(int $index, Tokens $tokens)
while (true) {
$index = $tokens->getNextMeaningfulToken($index);

if ($index === null) {
if (null === $index) {
return null;
}

Expand Down

0 comments on commit 826d387

Please sign in to comment.