Browse Source

Merge branch '2.10'

Dariusz Ruminski 7 years ago
parent
commit
64473ad899

+ 3 - 1
README.rst

@@ -1339,11 +1339,13 @@ Choose from the list of available rules:
   - ``space_before`` (``'none'``, ``'one'``): spacing to apply before colon; defaults to
     ``'none'``
 
-* **self_accessor** [@Symfony]
+* **self_accessor** [@Symfony:risky]
 
   Inside class or interface element "self" should be preferred to the
   class name itself.
 
+  *Risky rule: risky when using dynamic calls like get_called_class() or late static binding.*
+
 * **semicolon_after_instruction** [@Symfony]
 
   Instructions must be terminated with a semicolon.

+ 2 - 2
src/FileReader.php

@@ -24,12 +24,12 @@ namespace PhpCsFixer;
 final class FileReader
 {
     /**
-     * @var ?self
+     * @var null|self
      */
     private static $instance;
 
     /**
-     * @var ?string
+     * @var null|string
      */
     private $stdinContent;
 

+ 11 - 1
src/Fixer/ClassNotation/SelfAccessorFixer.php

@@ -47,7 +47,9 @@ class Sample
 }
 '
                 ),
-            ]
+            ],
+            null,
+            'Risky when using dynamic calls like get_called_class() or late static binding.'
         );
     }
 
@@ -59,6 +61,14 @@ class Sample
         return $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]);
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function isRisky()
+    {
+        return true;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
src/RuleSet.php

@@ -140,7 +140,6 @@ final class RuleSet implements RuleSetInterface
             'phpdoc_var_without_name' => true,
             'protected_to_private' => true,
             'return_type_declaration' => true,
-            'self_accessor' => true,
             'semicolon_after_instruction' => true,
             'short_scalar_cast' => true,
             'single_blank_line_before_namespace' => true,
@@ -174,6 +173,7 @@ final class RuleSet implements RuleSetInterface
             ],
             'php_unit_construct' => true,
             'psr4' => true,
+            'self_accessor' => true,
             'silenced_deprecation_error' => true,
         ],
         '@DoctrineAnnotation' => [

+ 54 - 0
tests/AutoReview/ComposerTest.php

@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace PhpCsFixer\tests\AutoReview;
+
+use PhpCsFixer\Console\Application;
+use PhpCsFixer\Tests\TestCase;
+
+/**
+ * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * @internal
+ *
+ * @coversNothing
+ * @group auto-review
+ */
+final class ComposerTest extends TestCase
+{
+    public function testBranchAlias()
+    {
+        $composerJson = json_decode(file_get_contents(__DIR__.'/../../composer.json'), true);
+
+        if (!isset($composerJson['extra']['branch-alias'])) {
+            $this->addToAssertionCount(1); // composer.json doesn't contain branch alias, all good!
+            return;
+        }
+
+        $this->assertSame(
+            ['dev-master' => $this->convertAppVersionToAliasedVersion(Application::VERSION)],
+            $composerJson['extra']['branch-alias']
+        );
+    }
+
+    /**
+     * @param string $version
+     *
+     * @return strting
+     */
+    private function convertAppVersionToAliasedVersion($version)
+    {
+        $parts = explode('.', $version, 3);
+
+        return sprintf('%d.%d-dev', $parts[0], $parts[1]);
+    }
+}