Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30e3162

Browse files
committed
Merge branch '2.2' into 2.3
# Conflicts: # src/Fixer/Basic/Psr0Fixer.php # tests/AutoReview/ProjectCodeTest.php
2 parents c2520fe + 4203c88 commit 30e3162

13 files changed

Lines changed: 112 additions & 19 deletions

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,8 @@ Choose from the list of available rules:
964964

965965
Configuration options:
966966

967-
- ``dir`` (``string``): the directory where the project code is placed; required
967+
- ``dir`` (``string``): the directory where the project code is placed; defaults
968+
to ``''``
968969

969970
* **psr4** [@Symfony:risky]
970971

src/AbstractFixer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function __construct()
6363

6464
final public function fix(\SplFileInfo $file, Tokens $tokens)
6565
{
66+
if ($this instanceof ConfigurableFixerInterface && null === $this->configuration) {
67+
throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
68+
}
69+
6670
if (0 < $tokens->count() && $this->isCandidate($tokens) && $this->supports($file)) {
6771
$this->applyFix($file, $tokens);
6872
}

src/Fixer/Basic/Psr0Fixer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public function getDefinition()
4141
'<?php
4242
namespace PhpCsFixer\FIXER\Basic;
4343
class InvalidName {}
44+
',
45+
new \SplFileInfo(__FILE__)
46+
),
47+
new FileSpecificCodeSample(
48+
'<?php
49+
namespace PhpCsFixer\FIXER\Basic;
50+
class InvalidName {}
4451
',
4552
new \SplFileInfo(__FILE__),
4653
['dir' => realpath(__DIR__.'/../..')]
@@ -92,7 +99,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
9299
$path = str_replace('\\', '/', $file->getRealPath());
93100
$dir = dirname($path);
94101

95-
if (isset($this->configuration['dir'])) {
102+
if ('' !== $this->configuration['dir']) {
96103
$dir = substr($dir, strlen(realpath($this->configuration['dir'])) + 1);
97104

98105
if (false === $dir) {
@@ -150,6 +157,7 @@ protected function createConfigurationDefinition()
150157
return new FixerConfigurationResolver([
151158
(new FixerOptionBuilder('dir', 'The directory where the project code is placed.'))
152159
->setAllowedTypes(['string'])
160+
->setDefault('')
153161
->getOption(),
154162
]);
155163
}

src/Fixer/Comment/HeaderCommentFixer.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace PhpCsFixer\Fixer\Comment;
1414

1515
use PhpCsFixer\AbstractFixer;
16-
use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
1716
use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
1817
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
1918
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
@@ -113,10 +112,6 @@ public function isCandidate(Tokens $tokens)
113112
*/
114113
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
115114
{
116-
if (null === $this->configuration['header']) {
117-
throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
118-
}
119-
120115
// figure out where the comment should be placed
121116
$headerNewIndex = $this->findHeaderCommentInsertionIndex($tokens);
122117

src/Fixer/Phpdoc/PhpdocSeparationFixer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PhpCsFixer\DocBlock\Annotation;
1717
use PhpCsFixer\DocBlock\DocBlock;
1818
use PhpCsFixer\DocBlock\TagComparator;
19-
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
2019
use PhpCsFixer\FixerDefinition\CodeSample;
2120
use PhpCsFixer\FixerDefinition\FixerDefinition;
2221
use PhpCsFixer\Tokenizer\Token;
@@ -25,7 +24,7 @@
2524
/**
2625
* @author Graham Campbell <[email protected]>
2726
*/
28-
final class PhpdocSeparationFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
27+
final class PhpdocSeparationFixer extends AbstractFixer
2928
{
3029
/**
3130
* {@inheritdoc}

src/Tokenizer/Transformer/SquareBraceTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getCustomTokens()
5050
public function getRequiredPhpVersionId()
5151
{
5252
// Short array syntax was introduced in PHP 5.4, but the fixer is smart
53-
// enough to handel it even before 5.4.
53+
// enough to handle it even before 5.4.
5454
// Same for array destructing syntax sugar `[` introduced in PHP 7.1.
5555
return 50000;
5656
}

tests/AutoReview/FixerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,29 @@ public function provideFixerDefinitionsCases()
146146
*/
147147
public function testFixerConfigurationDefinitions(ConfigurationDefinitionFixerInterface $fixer)
148148
{
149+
// do not modify this structure without prior discussion
150+
static $allowedRequiredOptions = [
151+
'header_comment' => ['header' => true],
152+
];
153+
149154
$configurationDefinition = $fixer->getConfigurationDefinition();
150155

151156
$this->assertInstanceOf(\PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface::class, $configurationDefinition);
152157

153158
foreach ($configurationDefinition->getOptions() as $option) {
154159
$this->assertNotEmpty($option->getDescription());
160+
161+
$this->assertSame(
162+
!isset($allowedRequiredOptions[$fixer->getName()][$option->getName()]),
163+
$option->hasDefault(),
164+
sprintf(
165+
$option->hasDefault()
166+
? 'Option `%s` of fixer `%s` is wrongly listed in `$allowedRequiredOptions` structure, as it is not required. If you just changed that option to not be required anymore, please adjust mentioned structure.'
167+
: 'Option `%s` of fixer `%s` shall not be required. If you want to introduce new required option please adjust `$allowedRequiredOptions` structure.',
168+
$option->getName(),
169+
$fixer->getName()
170+
)
171+
);
155172
}
156173
}
157174

tests/AutoReview/ProjectCodeTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ final class ProjectCodeTest extends TestCase
4141
\PhpCsFixer\Doctrine\Annotation\Tokens::class,
4242
\PhpCsFixer\FileRemoval::class,
4343
\PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator::class,
44-
\PhpCsFixer\FixerDefinition\FileSpecificCodeSample::class,
4544
\PhpCsFixer\FixerFileProcessedEvent::class,
4645
\PhpCsFixer\Fixer\Operator\AlignDoubleArrowFixerHelper::class,
4746
\PhpCsFixer\Fixer\Operator\AlignEqualsFixerHelper::class,
@@ -136,7 +135,6 @@ function (\ReflectionClass $interface) {
136135
$exceptionMethodsPerClass = [
137136
\PhpCsFixer\Config::class => ['create'],
138137
\PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => ['fixSpace'],
139-
\PhpCsFixer\Fixer\Import\OrderedImportsFixer::class => ['sortingCallBack'],
140138
];
141139

142140
$definedMethods = $this->getPublicMethodNames($rc);
@@ -172,7 +170,10 @@ public function testThatSrcClassesNotExposeProperties($className)
172170
$rc = new \ReflectionClass($className);
173171

174172
if (\PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer::class === $className) {
175-
$this->markTestIncomplete('Public properties of fixer \'PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer\' will be remove on 3.0.');
173+
$this->markTestIncomplete(sprintf(
174+
'Public properties of fixer `%s` will be remove on 3.0.',
175+
\PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer::class
176+
));
176177
}
177178

178179
$this->assertEmpty(

tests/ConfigurationException/InvalidConfigurationExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testIsInvalidConfigurationException()
3232
'I cannot do that, Dave.'
3333
);
3434

35-
$this->assertInstanceOf('PhpCsFixer\ConfigurationException\InvalidConfigurationException', $exception);
35+
$this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class, $exception);
3636
}
3737

3838
public function testDefaults()

tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testIsInvalidFixerConfigurationException()
3232
'I cannot do that, Dave.'
3333
);
3434

35-
$this->assertInstanceOf('PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException', $exception);
35+
$this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class, $exception);
3636
}
3737

3838
public function testDefaults()

0 commit comments

Comments
 (0)