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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=8.4",
"composer/pcre": "^3.3.2",
"composer/pcre": "^3.4",
"composer/xdebug-handler": "^3.0.5",
"entropy/entropy": "^0.4",
"friendsofphp/php-cs-fixer": "^3.95.5",
Expand All @@ -37,7 +37,7 @@
"symplify/phpstan-rules": "^14.11",
"symplify/vendor-patches": "^11.5",
"tomasvotruba/class-leak": "^2.1.7",
"tomasvotruba/type-coverage": "^2.1",
"tomasvotruba/type-coverage": "^2.2",
"tomasvotruba/unused-public": "^2.2",
"tracy/tracy": "^2.12"
},
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ parameters:
checkMissingCallableSignature: true

# symplify - see https://github.com/symplify/phpstan-rules#usage
pathStrings: true
symplify:
pathStrings: true

paths:
- packages
Expand Down
13 changes: 13 additions & 0 deletions src/DependencyInjection/ServiceContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Symplify\EasyCodingStandard\DependencyInjection;

use Closure;
use Entropy\Container\Container;
use PHP_CodeSniffer\Util\Tokens;
use PhpCsFixer\Differ\DifferInterface;
Expand Down Expand Up @@ -68,6 +69,18 @@ static function (Container $container): EasyCodingStandardStyle {
$configClosure = require $configFile;
Assert::isCallable($configClosure);

if ($configClosure instanceof Closure && ! defined('PHPUNIT_COMPOSER_INSTALL')) {
/** @var SymfonyStyle $symfonyStyle */
$symfonyStyle = $ecsConfig->make(SymfonyStyle::class);
$symfonyStyle->warning(sprintf(
'The "return function (ECSConfig $ecsConfig): void {}" config format is deprecated. Use "return ECSConfig::configure()" fluent API instead in "%s".',
$configFile
));

// give the user a moment to notice the deprecation warning
sleep(5);
}

$configClosure($ecsConfig);
}

Expand Down
9 changes: 8 additions & 1 deletion templates/ecs.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ return ECSConfig::configure()
->withPaths([
__PATHS__
])
// include *.php files in the root directory
->withRootFiles()

// add a single rule
->withRules([
Expand All @@ -18,4 +20,9 @@ __PATHS__
// add sets - group of rules, from easiest to more complex ones
// uncomment one, apply one, commit, PR, merge and repeat
__PREPARED_SETS__
;

// ...but first: take it step by step
->withSpacesLevel(0)
->withArrayLevel(0)
->withControlStructuresLevel(0)
->withDocblockLevel(0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
};
9 changes: 9 additions & 0 deletions tests/DependencyInjection/ConfigurationFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ public function testIncludeConfig(): void
$sniffFileProcessor = $this->make(SniffFileProcessor::class);
$this->assertCount(1, $sniffFileProcessor->getCheckers());
}

public function testDeprecatedClosureConfig(): void
{
// the old closure config format is deprecated, but still loads
$this->createContainerWithConfigs([__DIR__ . '/ConfigurationFileSource/deprecated-closure-config.php']);

$fixerFileProcessor = $this->make(FixerFileProcessor::class);
$this->assertCount(0, $fixerFileProcessor->getCheckers());
}
}
Loading