mirror of
https://github.com/elyby/php-code-style.git
synced 2025-05-31 14:12:05 +05:30
First implementation
This commit is contained in:
39
src/Fixers.php
Normal file
39
src/Fixers.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ely\CS;
|
||||
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use PhpCsFixer\Finder;
|
||||
use PhpCsFixer\Fixer\FixerInterface;
|
||||
use ReflectionClass;
|
||||
use Traversable;
|
||||
|
||||
class Fixers implements IteratorAggregate {
|
||||
|
||||
public function getIterator(): Traversable {
|
||||
$finder = new Finder();
|
||||
$finder->in(__DIR__ . '/Fixer')->name('*.php');
|
||||
$classes = [];
|
||||
foreach ($finder as $file) {
|
||||
$class = '\\Ely\\CS' . str_replace('/', '\\', mb_substr($file->getPathname(), mb_strlen(__DIR__), -4));
|
||||
if (!class_exists($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$rfl = new ReflectionClass($class);
|
||||
if (!$rfl->implementsInterface(FixerInterface::class) || $rfl->isAbstract()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[] = $class;
|
||||
}
|
||||
|
||||
return new ArrayIterator(array_map(function($class) {
|
||||
return new $class();
|
||||
}, $classes));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user