Skip to content

Commit

Permalink
feature: make dump fixer php cs fixer compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
rugbymauri committed May 23, 2024
1 parent e25e2f4 commit 1736750
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Fixer/DumpFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
final class DumpFixer extends AbstractFunctionReferenceFixer
{
use FixerTrait;

private array $functions = ['dump', 'var_dump', 'dd'];

public function isCandidate(Tokens $tokens): bool
Expand Down
26 changes: 26 additions & 0 deletions src/Fixer/FixerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace whatwedo\PhpCodingStandard\Fixer;

use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Preg;

trait FixerTrait
{
final public static function name(): string
{
$name = Preg::replace('/(?<!^)(?=[A-Z])/', '_', \substr(static::class, 33, -5));

return 'WhatwedoPhpCodingStandards/' . \strtolower($name);
}

final public function getName(): string
{
return self::name();
}

final public function supports(\SplFileInfo $file): bool
{
return true;
}
}
35 changes: 35 additions & 0 deletions src/Fixers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace whatwedo\PhpCodingStandard;

use PhpCsFixer\Fixer\FixerInterface;

/**
* @implements \IteratorAggregate<FixerInterface>
*/
final class Fixers implements \IteratorAggregate
{
/**
* @return \Generator<FixerInterface>
*/
public function getIterator(): \Generator
{
$classNames = [];
foreach (new \DirectoryIterator(__DIR__ . '/Fixer') as $fileInfo) {
$fileName = $fileInfo->getBasename('.php');
if (\in_array($fileName, ['.', '..', 'FixerTrait'], true)) {
continue;
}
$classNames[] = __NAMESPACE__ . '\\Fixer\\' . $fileName;
}

\sort($classNames);

foreach ($classNames as $className) {
$fixer = new $className();
\assert($fixer instanceof FixerInterface);

yield $fixer;
}
}
}

0 comments on commit 1736750

Please sign in to comment.