Skip to content

Commit 468ff27

Browse files
committed
bug #1654 Revert #1575 (Use a PHP-CS-Fixer shim rather than an external PHAR) (kbond)
This PR was merged into the 1.x-dev branch. Discussion ---------- Revert #1575 (Use a PHP-CS-Fixer shim rather than an external PHAR) This reverts #1575. This PR has caused a lot of trouble as it made php-cs-fixer a required dep which installs a recipe. See #1644, #1653, #1651, #1648. We can't have php-cs-fixer (or the shim) as a required dependency. I think we need to have this bundle only use php-cs-fixer if available/configured (or drop it entirely). I'm not sure why it is used at all - feels like a lot of added complexity... Commits ------- 41744d7 Revert "feature #1575 [make:*] Use a PHP-CS-Fixer shim rather than an external PHAR"
2 parents 495b7d6 + 41744d7 commit 468ff27

File tree

12 files changed

+23
-31
lines changed

12 files changed

+23
-31
lines changed

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"php": ">=8.1",
1717
"doctrine/inflector": "^2.0",
1818
"nikic/php-parser": "^4.18|^5.0",
19-
"php-cs-fixer/shim": "^v3.64",
2019
"symfony/config": "^6.4|^7.0",
2120
"symfony/console": "^6.4|^7.0",
2221
"symfony/dependency-injection": "^6.4|^7.0",

config/services.xml

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
</service>
4242

4343
<service id="maker.template_linter" class="Symfony\Bundle\MakerBundle\Util\TemplateLinter">
44-
<argument type="service" id="maker.file_manager" />
4544
<argument>%env(default::string:MAKER_PHP_CS_FIXER_BINARY_PATH)%</argument>
4645
<argument>%env(default::string:MAKER_PHP_CS_FIXER_CONFIG_PATH)%</argument>
4746
</service>
2.69 MB
Binary file not shown.

src/Util/TemplateLinter.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\MakerBundle\Util;
1313

1414
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
15-
use Symfony\Bundle\MakerBundle\FileManager;
1615
use Symfony\Component\Console\Output\OutputInterface;
1716
use Symfony\Component\Process\ExecutableFinder;
1817
use Symfony\Component\Process\Process;
@@ -26,12 +25,14 @@
2625
*/
2726
final class TemplateLinter
2827
{
28+
// Version must match bundled version file name. e.g. php-cs-fixer-v3.49.9.phar
29+
public const BUNDLED_PHP_CS_FIXER_VERSION = '3.49.0';
30+
2931
private bool $usingBundledPhpCsFixer = true;
3032
private bool $usingBundledPhpCsFixerConfig = true;
3133
private bool $needsPhpCmdPrefix = true;
3234

3335
public function __construct(
34-
private FileManager $fileManager,
3536
private ?string $phpCsFixerBinaryPath = null,
3637
private ?string $phpCsFixerConfigPath = null,
3738
) {
@@ -97,15 +98,9 @@ public function writeLinterMessage(OutputInterface $output): void
9798

9899
private function setBinary(): void
99100
{
100-
// Use Bundled (shim) PHP-CS-Fixer
101+
// Use Bundled PHP-CS-Fixer
101102
if (null === $this->phpCsFixerBinaryPath) {
102-
$shimLocation = \sprintf('%s/vendor/bin/php-cs-fixer', \dirname(__DIR__, 2));
103-
104-
if (is_file($shimLocation)) {
105-
$this->phpCsFixerBinaryPath = $shimLocation;
106-
107-
return;
108-
}
103+
$this->phpCsFixerBinaryPath = \sprintf('%s/Resources/bin/php-cs-fixer-v%s.phar', \dirname(__DIR__), self::BUNDLED_PHP_CS_FIXER_VERSION);
109104

110105
return;
111106
}
@@ -134,8 +129,7 @@ private function setBinary(): void
134129
private function setConfig(): void
135130
{
136131
// No config provided, but there is a dist config file in the project dir
137-
$defaultConfigPath = \sprintf('%s/.php-cs-fixer.dist.php', $this->fileManager->getRootDirectory());
138-
if (null === $this->phpCsFixerConfigPath && file_exists($defaultConfigPath)) {
132+
if (null === $this->phpCsFixerConfigPath && file_exists($defaultConfigPath = '.php-cs-fixer.dist.php')) {
139133
$this->phpCsFixerConfigPath = $defaultConfigPath;
140134

141135
$this->usingBundledPhpCsFixerConfig = false;

tests/Command/MakerCommandTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testExceptionOnMissingDependencies(): void
4040

4141
$fileManager = $this->createMock(FileManager::class);
4242

43-
$command = new MakerCommand($maker, $fileManager, new Generator($fileManager, 'App'), new TemplateLinter($fileManager));
43+
$command = new MakerCommand($maker, $fileManager, new Generator($fileManager, 'App'), new TemplateLinter());
4444
// needed because it's normally set by the Application
4545
$command->setName('make:foo');
4646
$tester = new CommandTester($command);
@@ -53,7 +53,7 @@ public function testExceptionOnUnknownRootNamespace(): void
5353

5454
$fileManager = $this->createMock(FileManager::class);
5555

56-
$command = new MakerCommand($maker, $fileManager, new Generator($fileManager, 'Unknown'), new TemplateLinter($fileManager));
56+
$command = new MakerCommand($maker, $fileManager, new Generator($fileManager, 'Unknown'), new TemplateLinter());
5757
// needed because it's normally set by the Application
5858
$command->setName('make:foo');
5959
$tester = new CommandTester($command);

tests/Maker/TemplateLinterTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protected function getMakerClass(): string
3333
public function getTestDetails(): \Generator
3434
{
3535
yield 'lints_templates_with_custom_php_cs_fixer_and_config' => [$this->createMakerTest()
36+
->addExtraDependencies('php-cs-fixer/shim')
3637
->run(function (MakerTestRunner $runner) {
3738
$runner->copy('template-linter/php-cs-fixer.test.php', 'php-cs-fixer.test.php');
3839

@@ -52,12 +53,13 @@ public function getTestDetails(): \Generator
5253

5354
self::assertStringContainsString('Linted by custom php-cs-config', $generatedTemplate);
5455

55-
$expectedOutput = 'System PHP-CS-Fixer (bin/php-cs-fixer) & System PHP-CS-Fixer Configuration';
56+
$expectedOutput = 'System PHP-CS-Fixer (bin/php-cs-fixer) & System PHP-CS-Fixer Configuration (php-cs-fixer.test.php)';
5657
self::assertStringContainsString($expectedOutput, $output);
5758
}),
5859
];
5960

6061
yield 'lints_templates_with_flex_generated_config_file' => [$this->createMakerTest()
62+
->addExtraDependencies('php-cs-fixer/shim')
6163
->run(function (MakerTestRunner $runner) {
6264
$runner->replaceInFile(
6365
'.php-cs-fixer.dist.php',
@@ -77,14 +79,13 @@ public function getTestDetails(): \Generator
7779

7880
self::assertStringContainsString('Linted with stock php-cs-config', $generatedTemplate);
7981

80-
$expectedOutput = 'Bundled PHP-CS-Fixer & System PHP-CS-Fixer Configuration';
82+
$expectedOutput = 'Bundled PHP-CS-Fixer & System PHP-CS-Fixer Configuration (.php-cs-fixer.dist.php)';
8183
self::assertStringContainsString($expectedOutput, $output);
8284
}),
8385
];
8486

8587
yield 'lints_templates_with_bundled_php_cs_fixer' => [$this->createMakerTest()
8688
->run(function (MakerTestRunner $runner) {
87-
$runner->deleteFile('.php-cs-fixer.dist.php');
8889
// Voter class name
8990
$output = $runner->runMaker(['FooBar']);
9091

tests/Util/TemplateLinterTest.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Tests\Util;
1313

14-
use Composer\InstalledVersions;
1514
use PHPUnit\Framework\TestCase;
16-
use Symfony\Bundle\MakerBundle\FileManager;
1715
use Symfony\Bundle\MakerBundle\Util\TemplateLinter;
1816
use Symfony\Component\Process\Process;
1917

@@ -30,30 +28,27 @@ public function testExceptionBinaryPathDoesntExist(): void
3028
{
3129
$this->expectExceptionMessage('The MAKER_PHP_CS_FIXER_BINARY_PATH provided: /some/bad/path does not exist.');
3230

33-
new TemplateLinter($this->createMock(FileManager::class), phpCsFixerBinaryPath: '/some/bad/path');
31+
new TemplateLinter(phpCsFixerBinaryPath: '/some/bad/path');
3432
}
3533

3634
public function testExceptionThrownIfConfigPathDoesntExist(): void
3735
{
3836
$this->expectExceptionMessage('The MAKER_PHP_CS_FIXER_CONFIG_PATH provided: /bad/config/path does not exist.');
3937

40-
new TemplateLinter($this->createMock(FileManager::class), phpCsFixerConfigPath: '/bad/config/path');
38+
new TemplateLinter(phpCsFixerConfigPath: '/bad/config/path');
4139
}
4240

4341
public function testPhpCsFixerVersion(): void
4442
{
4543
$this->markTestSkippedOnWindows();
4644

47-
$fixerPath = \sprintf('%s/vendor/php-cs-fixer/shim/php-cs-fixer', \dirname(__DIR__, 2));
48-
49-
// Get the installed version and remove the preceding "v"
50-
$expectedVersion = ltrim(InstalledVersions::getPrettyVersion('php-cs-fixer/shim'), 'v');
45+
$fixerPath = \sprintf('%s/src/Resources/bin/php-cs-fixer-v%s.phar', \dirname(__DIR__, 2), TemplateLinter::BUNDLED_PHP_CS_FIXER_VERSION);
5146

5247
$process = Process::fromShellCommandline(\sprintf('%s -V', $fixerPath));
5348

5449
$process->run();
5550

56-
self::assertStringContainsString($expectedVersion, $process->getOutput());
51+
self::assertStringContainsString(TemplateLinter::BUNDLED_PHP_CS_FIXER_VERSION, $process->getOutput());
5752
}
5853

5954
private function markTestSkippedOnWindows(): void

tests/fixtures/make-serializer-normalizer/EntityFixtureNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class EntityFixtureNormalizer implements NormalizerInterface
1010
{
1111
public function __construct(
1212
#[Autowire(service: 'serializer.normalizer.object')]
13-
private NormalizerInterface $normalizer,
13+
private NormalizerInterface $normalizer
1414
) {
1515
}
1616

tests/fixtures/make-serializer-normalizer/FooBarNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class FooBarNormalizer implements NormalizerInterface
99
{
1010
public function __construct(
1111
#[Autowire(service: 'serializer.normalizer.object')]
12-
private NormalizerInterface $normalizer,
12+
private NormalizerInterface $normalizer
1313
) {
1414
}
1515

tests/fixtures/make-validator/expected/FooBar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class FooBar extends Constraint
1414
public function __construct(
1515
public string $mode = 'strict',
1616
?array $groups = null,
17-
mixed $payload = null,
17+
mixed $payload = null
1818
) {
1919
parent::__construct([], $groups, $payload);
2020
}

tests/fixtures/make-voter/expected/FooBarVoter.php

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected function supports(string $attribute, mixed $subject): bool
2222
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
2323
{
2424
$user = $token->getUser();
25+
2526
// if the user is anonymous, do not grant access
2627
if (!$user instanceof UserInterface) {
2728
return false;
@@ -33,6 +34,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter
3334
// logic to determine if the user can EDIT
3435
// return true or false
3536
break;
37+
3638
case self::VIEW:
3739
// logic to determine if the user can VIEW
3840
// return true or false

tests/fixtures/make-voter/expected/not_final_FooBarVoter.php

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected function supports(string $attribute, mixed $subject): bool
2222
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
2323
{
2424
$user = $token->getUser();
25+
2526
// if the user is anonymous, do not grant access
2627
if (!$user instanceof UserInterface) {
2728
return false;
@@ -33,6 +34,7 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter
3334
// logic to determine if the user can EDIT
3435
// return true or false
3536
break;
37+
3638
case self::VIEW:
3739
// logic to determine if the user can VIEW
3840
// return true or false

0 commit comments

Comments
 (0)