Skip to content

Commit 1ff5263

Browse files
l-vojulienfalque
authored andcommittedNov 23, 2019
Allow Symfony 5 components
1 parent 55d576c commit 1ff5263

12 files changed

+125
-16
lines changed
 

‎.composer-require-checker.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"symbol-whitelist" : [
3+
"Symfony\\Contracts\\EventDispatcher\\Event",
34
"Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
5+
"Symfony\\Component\\EventDispatcher\\Event",
46
"PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
57
"PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",
68
"PHPUnit\\Framework\\Constraint\\IsIdentical",

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
<<: *STANDARD_TEST_JOB
8989
stage: Test
9090
php: 7.2
91+
env: SYMFONY_DEPRECATIONS_HELPER=disabled PHP_CS_FIXER_TEST_USE_LEGACY_TOKENIZER=1 SYMFONY_VERSION="^5.0"
9192

9293
-
9394
<<: *STANDARD_TEST_JOB

‎composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"composer/xdebug-handler": "^1.2",
2222
"doctrine/annotations": "^1.2",
2323
"php-cs-fixer/diff": "^1.3",
24-
"symfony/console": "^3.4.17 || ^4.1.6",
25-
"symfony/event-dispatcher": "^3.0 || ^4.0",
26-
"symfony/filesystem": "^3.0 || ^4.0",
27-
"symfony/finder": "^3.0 || ^4.0",
28-
"symfony/options-resolver": "^3.0 || ^4.0",
24+
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",
25+
"symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0",
26+
"symfony/filesystem": "^3.0 || ^4.0 || ^5.0",
27+
"symfony/finder": "^3.0 || ^4.0 || ^5.0",
28+
"symfony/options-resolver": "^3.0 || ^4.0 || ^5.0",
2929
"symfony/polyfill-php70": "^1.0",
3030
"symfony/polyfill-php72": "^1.4",
31-
"symfony/process": "^3.0 || ^4.0",
32-
"symfony/stopwatch": "^3.0 || ^4.0"
31+
"symfony/process": "^3.0 || ^4.0 || ^5.0",
32+
"symfony/stopwatch": "^3.0 || ^4.0 || ^5.0"
3333
},
3434
"require-dev": {
3535
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
@@ -42,8 +42,8 @@
4242
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
4343
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
4444
"phpunitgoodpractices/traits": "^1.8",
45-
"symfony/phpunit-bridge": "^4.3",
46-
"symfony/yaml": "^3.0 || ^4.0"
45+
"symfony/phpunit-bridge": "^4.3 || ^5.0",
46+
"symfony/yaml": "^3.0 || ^4.0 || ^5.0"
4747
},
4848
"suggest": {
4949
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",

‎phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ parameters:
1313
- '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
1414
## cannot analyse out of PHP 7.4
1515
- '/^Constant T_FN not found\.$/'
16+
- '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'

‎src/Console/ConfigurationResolver.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,15 @@ public function getDirectory()
302302
{
303303
if (null === $this->directory) {
304304
$path = $this->getCacheFile();
305-
$filesystem = new Filesystem();
305+
if (null === $path) {
306+
$absolutePath = $this->cwd;
307+
} else {
308+
$filesystem = new Filesystem();
306309

307-
$absolutePath = $filesystem->isAbsolutePath($path)
308-
? $path
309-
: $this->cwd.\DIRECTORY_SEPARATOR.$path;
310+
$absolutePath = $filesystem->isAbsolutePath($path)
311+
? $path
312+
: $this->cwd.\DIRECTORY_SEPARATOR.$path;
313+
}
310314

311315
$this->directory = new Directory(\dirname($absolutePath));
312316
}

‎src/Event/Event.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Event;
14+
15+
// Since PHP-CS-FIXER is PHP 5.6 compliant we can't always use Symfony Contracts (currently needs PHP ^7.1.3)
16+
// This conditionnal inheritance will be useless when PHP-CS-FIXER no longer supports PHP versions
17+
// inferior to Symfony/Contracts PHP minimal version
18+
if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
19+
class Event extends \Symfony\Contracts\EventDispatcher\Event
20+
{
21+
}
22+
} else {
23+
class Event extends \Symfony\Component\EventDispatcher\Event
24+
{
25+
}
26+
}

‎src/FixerFileProcessedEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace PhpCsFixer;
1414

15-
use Symfony\Component\EventDispatcher\Event;
15+
use PhpCsFixer\Event\Event;
1616

1717
/**
1818
* Event that is fired when file was processed by Fixer.

‎src/Runner/FileFilterIterator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
namespace PhpCsFixer\Runner;
1414

1515
use PhpCsFixer\Cache\CacheManagerInterface;
16+
use PhpCsFixer\Event\Event;
1617
use PhpCsFixer\FileReader;
1718
use PhpCsFixer\FixerFileProcessedEvent;
18-
use Symfony\Component\EventDispatcher\Event;
1919
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2020

2121
/**

‎src/Runner/Runner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
use PhpCsFixer\Differ\DifferInterface;
2020
use PhpCsFixer\Error\Error;
2121
use PhpCsFixer\Error\ErrorsManager;
22+
use PhpCsFixer\Event\Event;
2223
use PhpCsFixer\FileReader;
2324
use PhpCsFixer\Fixer\FixerInterface;
2425
use PhpCsFixer\FixerFileProcessedEvent;
2526
use PhpCsFixer\Linter\LinterInterface;
2627
use PhpCsFixer\Linter\LintingException;
2728
use PhpCsFixer\Linter\LintingResultInterface;
2829
use PhpCsFixer\Tokenizer\Tokens;
29-
use Symfony\Component\EventDispatcher\Event;
3030
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3131
use Symfony\Component\Filesystem\Exception\IOException;
3232

‎tests/AutoReview/ProjectCodeTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function (\ReflectionClass $interface) {
114114
// @TODO: 3.0 should be removed
115115
$exceptionMethodsPerClass = [
116116
\PhpCsFixer\Config::class => ['create'],
117+
\PhpCsFixer\Event\Event::class => ['stopPropagation'],
117118
\PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => ['fixSpace'],
118119
];
119120

‎tests/Console/ConfigurationResolverTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,47 @@ public function provideDeprecatedFixerConfiguredCases()
11421142
];
11431143
}
11441144

1145+
public function provideGetDirectoryCases()
1146+
{
1147+
return [
1148+
[null, '/my/path/my/file', 'path/my/file'],
1149+
['/my/path2/dir/.php_cs.cache', '/my/path2/dir/dir2/file', 'dir2/file'],
1150+
['dir/.php_cs.cache', '/my/path/dir/dir3/file', 'dir3/file'],
1151+
];
1152+
}
1153+
1154+
/**
1155+
* @dataProvider provideGetDirectoryCases
1156+
*
1157+
* @param null|string $cacheFile
1158+
* @param string $file
1159+
* @param string $expectedPathRelativeToFile
1160+
*/
1161+
public function testGetDirectory($cacheFile, $file, $expectedPathRelativeToFile)
1162+
{
1163+
if (null !== $cacheFile) {
1164+
$cacheFile = $this->normalizePath($cacheFile);
1165+
}
1166+
$file = $this->normalizePath($file);
1167+
$expectedPathRelativeToFile = $this->normalizePath($expectedPathRelativeToFile);
1168+
1169+
$config = new Config();
1170+
if (null === $cacheFile) {
1171+
$config->setUsingCache(false);
1172+
} else {
1173+
$config->setCacheFile($cacheFile);
1174+
}
1175+
1176+
$resolver = new ConfigurationResolver($config, [], $this->normalizePath('/my/path'), new ToolInfo());
1177+
$directory = $resolver->getDirectory();
1178+
static::assertSame($expectedPathRelativeToFile, $directory->getRelativePathTo($file));
1179+
}
1180+
1181+
private function normalizePath($path)
1182+
{
1183+
return str_replace('/', \DIRECTORY_SEPARATOR, $path);
1184+
}
1185+
11451186
private static function assertSameRules(array $expected, array $actual, $message = '')
11461187
{
11471188
ksort($expected);

‎tests/Event/EventTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Tests\Event;
14+
15+
use PhpCsFixer\Event\Event;
16+
use PhpCsFixer\Tests\TestCase;
17+
18+
/**
19+
* @internal
20+
* @covers \PhpCsFixer\Event\Event
21+
*/
22+
final class EventTest extends TestCase
23+
{
24+
public function testInheritance()
25+
{
26+
$event = new Event();
27+
if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
28+
static::assertInstanceOf(\Symfony\Contracts\EventDispatcher\Event::class, $event);
29+
} else {
30+
static::assertInstanceOf(\Symfony\Component\EventDispatcher\Event::class, $event);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.