Browse Source

Merge branch '2.2' into 2.3

# Conflicts:
#	src/Fixer/Basic/Psr0Fixer.php
#	tests/AutoReview/ProjectCodeTest.php
Dariusz Ruminski 7 years ago
parent
commit
30e31622d0

+ 2 - 1
README.rst

@@ -964,7 +964,8 @@ Choose from the list of available rules:
 
   Configuration options:
 
-  - ``dir`` (``string``): the directory where the project code is placed; required
+  - ``dir`` (``string``): the directory where the project code is placed; defaults
+    to ``''``
 
 * **psr4** [@Symfony:risky]
 

+ 4 - 0
src/AbstractFixer.php

@@ -63,6 +63,10 @@ abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
 
     final public function fix(\SplFileInfo $file, Tokens $tokens)
     {
+        if ($this instanceof ConfigurableFixerInterface && null === $this->configuration) {
+            throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
+        }
+
         if (0 < $tokens->count() && $this->isCandidate($tokens) && $this->supports($file)) {
             $this->applyFix($file, $tokens);
         }

+ 9 - 1
src/Fixer/Basic/Psr0Fixer.php

@@ -41,6 +41,13 @@ final class Psr0Fixer extends AbstractPsrAutoloadingFixer implements Configurati
                     '<?php
 namespace PhpCsFixer\FIXER\Basic;
 class InvalidName {}
+',
+                    new \SplFileInfo(__FILE__)
+                ),
+                new FileSpecificCodeSample(
+                    '<?php
+namespace PhpCsFixer\FIXER\Basic;
+class InvalidName {}
 ',
                     new \SplFileInfo(__FILE__),
                     ['dir' => realpath(__DIR__.'/../..')]
@@ -92,7 +99,7 @@ class InvalidName {}
             $path = str_replace('\\', '/', $file->getRealPath());
             $dir = dirname($path);
 
-            if (isset($this->configuration['dir'])) {
+            if ('' !== $this->configuration['dir']) {
                 $dir = substr($dir, strlen(realpath($this->configuration['dir'])) + 1);
 
                 if (false === $dir) {
@@ -150,6 +157,7 @@ class InvalidName {}
         return new FixerConfigurationResolver([
             (new FixerOptionBuilder('dir', 'The directory where the project code is placed.'))
                 ->setAllowedTypes(['string'])
+                ->setDefault('')
                 ->getOption(),
         ]);
     }

+ 0 - 5
src/Fixer/Comment/HeaderCommentFixer.php

@@ -13,7 +13,6 @@
 namespace PhpCsFixer\Fixer\Comment;
 
 use PhpCsFixer\AbstractFixer;
-use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
 use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
 use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
 use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
@@ -113,10 +112,6 @@ echo 1;
      */
     protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     {
-        if (null === $this->configuration['header']) {
-            throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
-        }
-
         // figure out where the comment should be placed
         $headerNewIndex = $this->findHeaderCommentInsertionIndex($tokens);
 

+ 1 - 2
src/Fixer/Phpdoc/PhpdocSeparationFixer.php

@@ -16,7 +16,6 @@ use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\DocBlock\Annotation;
 use PhpCsFixer\DocBlock\DocBlock;
 use PhpCsFixer\DocBlock\TagComparator;
-use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
 use PhpCsFixer\FixerDefinition\CodeSample;
 use PhpCsFixer\FixerDefinition\FixerDefinition;
 use PhpCsFixer\Tokenizer\Token;
@@ -25,7 +24,7 @@ use PhpCsFixer\Tokenizer\Tokens;
 /**
  * @author Graham Campbell <graham@alt-three.com>
  */
-final class PhpdocSeparationFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
+final class PhpdocSeparationFixer extends AbstractFixer
 {
     /**
      * {@inheritdoc}

+ 1 - 1
src/Tokenizer/Transformer/SquareBraceTransformer.php

@@ -50,7 +50,7 @@ final class SquareBraceTransformer extends AbstractTransformer
     public function getRequiredPhpVersionId()
     {
         // Short array syntax was introduced in PHP 5.4, but the fixer is smart
-        // enough to handel it even before 5.4.
+        // enough to handle it even before 5.4.
         // Same for array destructing syntax sugar `[` introduced in PHP 7.1.
         return 50000;
     }

+ 17 - 0
tests/AutoReview/FixerTest.php

@@ -146,12 +146,29 @@ final class FixerTest extends TestCase
      */
     public function testFixerConfigurationDefinitions(ConfigurationDefinitionFixerInterface $fixer)
     {
+        // do not modify this structure without prior discussion
+        static $allowedRequiredOptions = [
+            'header_comment' => ['header' => true],
+        ];
+
         $configurationDefinition = $fixer->getConfigurationDefinition();
 
         $this->assertInstanceOf(\PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface::class, $configurationDefinition);
 
         foreach ($configurationDefinition->getOptions() as $option) {
             $this->assertNotEmpty($option->getDescription());
+
+            $this->assertSame(
+                !isset($allowedRequiredOptions[$fixer->getName()][$option->getName()]),
+                $option->hasDefault(),
+                sprintf(
+                    $option->hasDefault()
+                        ? '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.'
+                        : 'Option `%s` of fixer `%s` shall not be required. If you want to introduce new required option please adjust `$allowedRequiredOptions` structure.',
+                    $option->getName(),
+                    $fixer->getName()
+                )
+            );
         }
     }
 

+ 4 - 3
tests/AutoReview/ProjectCodeTest.php

@@ -41,7 +41,6 @@ final class ProjectCodeTest extends TestCase
         \PhpCsFixer\Doctrine\Annotation\Tokens::class,
         \PhpCsFixer\FileRemoval::class,
         \PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator::class,
-        \PhpCsFixer\FixerDefinition\FileSpecificCodeSample::class,
         \PhpCsFixer\FixerFileProcessedEvent::class,
         \PhpCsFixer\Fixer\Operator\AlignDoubleArrowFixerHelper::class,
         \PhpCsFixer\Fixer\Operator\AlignEqualsFixerHelper::class,
@@ -136,7 +135,6 @@ final class ProjectCodeTest extends TestCase
         $exceptionMethodsPerClass = [
             \PhpCsFixer\Config::class => ['create'],
             \PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => ['fixSpace'],
-            \PhpCsFixer\Fixer\Import\OrderedImportsFixer::class => ['sortingCallBack'],
         ];
 
         $definedMethods = $this->getPublicMethodNames($rc);
@@ -172,7 +170,10 @@ final class ProjectCodeTest extends TestCase
         $rc = new \ReflectionClass($className);
 
         if (\PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer::class === $className) {
-            $this->markTestIncomplete('Public properties of fixer \'PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer\' will be remove on 3.0.');
+            $this->markTestIncomplete(sprintf(
+                'Public properties of fixer `%s` will be remove on 3.0.',
+                \PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer::class
+            ));
         }
 
         $this->assertEmpty(

+ 1 - 1
tests/ConfigurationException/InvalidConfigurationExceptionTest.php

@@ -32,7 +32,7 @@ final class InvalidConfigurationExceptionTest extends TestCase
             'I cannot do that, Dave.'
         );
 
-        $this->assertInstanceOf('PhpCsFixer\ConfigurationException\InvalidConfigurationException', $exception);
+        $this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class, $exception);
     }
 
     public function testDefaults()

+ 1 - 1
tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php

@@ -32,7 +32,7 @@ final class RequiredFixerConfigurationExceptionTest extends TestCase
             'I cannot do that, Dave.'
         );
 
-        $this->assertInstanceOf('PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException', $exception);
+        $this->assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class, $exception);
     }
 
     public function testDefaults()

Some files were not shown because too many files changed in this diff