diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml
index 63bb03f82c..17c12bd257 100644
--- a/.github/workflows/code_analysis.yaml
+++ b/.github/workflows/code_analysis.yaml
@@ -34,7 +34,7 @@ jobs:
-
name: 'Check Active Classes'
- run: vendor/bin/class-leak check bin src --ansi
+ run: vendor/bin/class-leak check bin src --skip-type "Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface" --ansi
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
diff --git a/README.md b/README.md
index 342e76abf7..5ebb21f3d5 100644
--- a/README.md
+++ b/README.md
@@ -89,37 +89,37 @@ return ECSConfig::configure()
-Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)?
+### Gradual Adoption with Levels
-You can:
+Want to adopt a coding standard step by step instead of all at once? Use `with*Level()` methods to start from the safest rules and raise the level as your codebase catches up:
```php
use Symplify\EasyCodingStandard\Config\ECSConfig;
return ECSConfig::configure()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
- ->withPhpCsFixerSets(perCS20: true, doctrineAnnotation: true);
+ ->withSpacesLevel(0)
+ ->withArrayLevel(0)
+ ->withControlStructuresLevel(0)
+ ->withDocblockLevel(0);
```
+Each level enables the first N+1 rules from a curated list, ordered from safest to most invasive. Bump the number once your codebase is clean on the current level.
+
-### Gradual Adoption with Levels
+Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)?
-Want to adopt a coding standard step by step instead of all at once? Use `with*Level()` methods to start from the safest rules and raise the level as your codebase catches up:
+You can:
```php
use Symplify\EasyCodingStandard\Config\ECSConfig;
return ECSConfig::configure()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
- ->withSpacesLevel(0)
- ->withArrayLevel(0)
- ->withControlStructuresLevel(0)
- ->withDocblockLevel(0);
+ ->withPhpCsFixerSets(perCS20: true, doctrineAnnotation: true);
```
-Each level enables the first N+1 rules from a curated list, ordered from safest to most invasive. Bump the number once your codebase is clean on the current level.
-
### How to Skip Files/Rules?
@@ -203,12 +203,16 @@ For information on how each of these behave, refer to their respective
## FAQ
+
+
### How do I clear cache?
```bash
vendor/bin/ecs --clear-cache
```
+
+
### How can I see all used rules?
```bash
diff --git a/bin/ecs.php b/bin/ecs.php
index e51020001f..eb9e89d348 100755
--- a/bin/ecs.php
+++ b/bin/ecs.php
@@ -9,7 +9,7 @@
use Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication;
use Symplify\EasyCodingStandard\Console\Style\SymfonyStyleFactory;
use Symplify\EasyCodingStandard\DependencyInjection\EasyCodingStandardContainerFactory;
-use Symplify\EasyCodingStandard\DependencyInjection\LazyContainerFactory;
+use Symplify\EasyCodingStandard\DependencyInjection\ServiceContainerFactory;
// performance boost
gc_disable();
@@ -64,7 +64,7 @@ public function includeCwdVendorAutoloadIfExists(): void
public function includeDependencyOrRepositoryVendorAutoloadIfExists(): void
{
// ECS' vendor is already loaded
- if (class_exists(LazyContainerFactory::class)) {
+ if (class_exists(ServiceContainerFactory::class)) {
return;
}
diff --git a/composer.json b/composer.json
index 9be5eb1f88..854fabe7c3 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "symplify/easy-coding-standard",
- "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer.",
+ "description": "ECS runs PHP-CS-Fixer and PHP_CodeSniffer as a single, parallel, fast tool, zero dependencies, requiring only PHP 7.2+. Configure with prepared sets, gradual levels via, plug-in and keep it running for years with zero maintenance",
"license": "MIT",
"keywords": [
"static analysis",
diff --git a/src/DependencyInjection/EasyCodingStandardContainerFactory.php b/src/DependencyInjection/EasyCodingStandardContainerFactory.php
index 00183d5437..ed6b6f01e6 100644
--- a/src/DependencyInjection/EasyCodingStandardContainerFactory.php
+++ b/src/DependencyInjection/EasyCodingStandardContainerFactory.php
@@ -16,7 +16,7 @@ final class EasyCodingStandardContainerFactory
public function createFromFromInput(ArgvInput $argvInput): ECSConfig
{
// $easyCodingStandardKernel = new EasyCodingStandardKernel();
- $lazyContainerFactory = new LazyContainerFactory();
+ $serviceContainerFactory = new ServiceContainerFactory();
$inputConfigFiles = [];
$rootECSConfig = getcwd() . DIRECTORY_SEPARATOR . 'ecs.php';
@@ -31,7 +31,7 @@ public function createFromFromInput(ArgvInput $argvInput): ECSConfig
$inputConfigFiles[] = $rootECSConfig;
}
- $ecsConfig = $lazyContainerFactory->create($inputConfigFiles);
+ $ecsConfig = $serviceContainerFactory->create($inputConfigFiles);
$ecsConfig->boot();
if ($inputConfigFiles !== []) {
diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/ServiceContainerFactory.php
similarity index 77%
rename from src/DependencyInjection/LazyContainerFactory.php
rename to src/DependencyInjection/ServiceContainerFactory.php
index 9aecfc35db..8acdf519b1 100644
--- a/src/DependencyInjection/LazyContainerFactory.php
+++ b/src/DependencyInjection/ServiceContainerFactory.php
@@ -13,32 +13,15 @@
use Symplify\EasyCodingStandard\Caching\Cache;
use Symplify\EasyCodingStandard\Caching\CacheFactory;
use Symplify\EasyCodingStandard\Config\ECSConfig;
-use Symplify\EasyCodingStandard\Console\Output\CheckstyleOutputFormatter;
-use Symplify\EasyCodingStandard\Console\Output\ConsoleOutputFormatter;
-use Symplify\EasyCodingStandard\Console\Output\GitlabOutputFormatter;
-use Symplify\EasyCodingStandard\Console\Output\JsonOutputFormatter;
-use Symplify\EasyCodingStandard\Console\Output\JUnitOutputFormatter;
use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyle;
use Symplify\EasyCodingStandard\Console\Style\EasyCodingStandardStyleFactory;
use Symplify\EasyCodingStandard\Console\Style\SymfonyStyleFactory;
+use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface;
use Symplify\EasyCodingStandard\FixerRunner\WhitespacesFixerConfigFactory;
use Webmozart\Assert\Assert;
-final class LazyContainerFactory
+final class ServiceContainerFactory
{
- /**
- * Output formatters are registered explicitly, so they can be collected by contract.
- *
- * @var array
- */
- private const array OUTPUT_FORMATTER_CLASSES = [
- GitlabOutputFormatter::class,
- CheckstyleOutputFormatter::class,
- ConsoleOutputFormatter::class,
- JsonOutputFormatter::class,
- JUnitOutputFormatter::class,
- ];
-
/**
* @param string[] $configFiles
*/
@@ -76,10 +59,9 @@ static function (Container $container): EasyCodingStandardStyle {
// diffing
$ecsConfig->service(DifferInterface::class, static fn (): DifferInterface => new UnifiedDiffer());
- // output formatters - autowired eagerly so OutputFormatterCollector can find them by contract
- foreach (self::OUTPUT_FORMATTER_CLASSES as $outputFormatterClass) {
- $ecsConfig->make($outputFormatterClass);
- }
+ // output formatters - autodiscovered, then collected by contract for OutputFormatterCollector
+ $ecsConfig->autodiscover(__DIR__ . '/..');
+ $ecsConfig->findByContract(OutputFormatterInterface::class);
// load default config first
$configFiles = [__DIR__ . '/../../config/config.php', ...$configFiles];
diff --git a/src/Testing/PHPUnit/AbstractTestCase.php b/src/Testing/PHPUnit/AbstractTestCase.php
index f442d7d08c..96fbc6b50e 100644
--- a/src/Testing/PHPUnit/AbstractTestCase.php
+++ b/src/Testing/PHPUnit/AbstractTestCase.php
@@ -6,7 +6,7 @@
use PHPUnit\Framework\TestCase;
use Symplify\EasyCodingStandard\Config\ECSConfig;
-use Symplify\EasyCodingStandard\DependencyInjection\LazyContainerFactory;
+use Symplify\EasyCodingStandard\DependencyInjection\ServiceContainerFactory;
use Webmozart\Assert\Assert;
abstract class AbstractTestCase extends TestCase
@@ -15,9 +15,9 @@ abstract class AbstractTestCase extends TestCase
protected function setUp(): void
{
- $lazyContainerFactory = new LazyContainerFactory();
+ $serviceContainerFactory = new ServiceContainerFactory();
- $this->ecsConfig = $lazyContainerFactory->create();
+ $this->ecsConfig = $serviceContainerFactory->create();
$this->ecsConfig->boot();
}
@@ -29,8 +29,8 @@ protected function createContainerWithConfigs(array $configs): void
Assert::allString($configs);
Assert::allFile($configs);
- $lazyContainerFactory = new LazyContainerFactory();
- $this->ecsConfig = $lazyContainerFactory->create($configs);
+ $serviceContainerFactory = new ServiceContainerFactory();
+ $this->ecsConfig = $serviceContainerFactory->create($configs);
$this->ecsConfig->boot();
}
diff --git a/tests/Console/Output/OutputFormatterCollectorTest.php b/tests/Console/Output/OutputFormatterCollectorTest.php
new file mode 100644
index 0000000000..246163718c
--- /dev/null
+++ b/tests/Console/Output/OutputFormatterCollectorTest.php
@@ -0,0 +1,49 @@
+outputFormatterCollector = $this->make(OutputFormatterCollector::class);
+ }
+
+ public function test(): void
+ {
+ $this->assertInstanceOf(
+ ConsoleOutputFormatter::class,
+ $this->outputFormatterCollector->getByName(ConsoleOutputFormatter::getName())
+ );
+ $this->assertInstanceOf(
+ JsonOutputFormatter::class,
+ $this->outputFormatterCollector->getByName(JsonOutputFormatter::getName())
+ );
+ $this->assertInstanceOf(
+ JUnitOutputFormatter::class,
+ $this->outputFormatterCollector->getByName(JUnitOutputFormatter::getName())
+ );
+ $this->assertInstanceOf(
+ GitlabOutputFormatter::class,
+ $this->outputFormatterCollector->getByName(GitlabOutputFormatter::getName())
+ );
+ $this->assertInstanceOf(
+ CheckstyleOutputFormatter::class,
+ $this->outputFormatterCollector->getByName(CheckstyleOutputFormatter::getName())
+ );
+ }
+}