Browse Source

Merge branch 'master' into 3.0

* master:
  Issue #4274: Let lowercase_constants directive to be configurable.
  Add NullableTypeDeclarationForDefaultNullValueFixer
  Fix copy/paste/typos
  Add PHPStan
  IncludeFixer - remove braces when the statement is wrapped in block
  Remove superfluous leading backslash, closes 4520
  DX: ensure data providers are used
  HeredocIndentationFixer - remove whitespace in empty lines
  ClassKeywordRemoveFixer - fix for self,static and parent keywords
  Move readme-update command to Section 3
  DX: use ::class whenever possible
  Allow PHP7.4 to fail
  DX: use ::class whenever possible
  DX: removing unnecessary variable initialization
  bumped version
  Enhancement: Use default name property to configure command names
  Docs: update Cookbook
  SelfStaticAccessor - extend itests
  DX: use PHIVE for dev tools
  Allow running if installed as project specific
SpacePossum 5 years ago
parent
commit
ba4c2f5cfc
10 changed files with 98 additions and 21 deletions
  1. 1 0
      .composer-require-checker.json
  2. 8 6
      .travis.yml
  3. 23 1
      README.rst
  4. 1 0
      dev-tools/.gitignore
  5. 0 1
      dev-tools/composer.json
  6. 19 0
      dev-tools/install.sh
  7. 5 0
      dev-tools/phive.xml
  8. 15 8
      doc/COOKBOOK-FIXERS.md
  9. 16 5
      php-cs-fixer
  10. 10 0
      phpstan.neon

+ 1 - 0
.composer-require-checker.json

@@ -2,6 +2,7 @@
     "symbol-whitelist" : [
         "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",
         "PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
+        "PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",
         "PHPUnit\\Framework\\Constraint\\IsIdentical",
         "PHPUnit\\Framework\\TestCase",
         "PHPUnit\\Runner\\Version",

+ 8 - 6
.travis.yml

@@ -6,6 +6,7 @@ git:
 cache:
     directories:
         - $HOME/.composer
+        - $HOME/.phive
         - $HOME/bin
 
 env:
@@ -26,15 +27,12 @@ jobs:
         -
             stage: Static Code Analysis
             php: 7.2
-            env: COMPOSER_FLAGS="--no-dev --prefer-stable"
+            env: COMPOSER_FLAGS="--prefer-stable"
             install:
-                - travis_retry composer update -d dev-tools $DEFAULT_COMPOSER_FLAGS
-                - composer info -d dev-tools -D | sort
+                - ./dev-tools/install.sh
 
                 - travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
                 - composer info -D | sort
-
-                - ./dev-tools/bin-download.sh
             before_script:
                 - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then COMMIT_RANGE=$TRAVIS_COMMIT_RANGE; else COMMIT_RANGE="HEAD~..HEAD"; fi;
                 - export COMMIT_SCA_FILES=`git diff --name-only --diff-filter=ACMRTUXB $COMMIT_RANGE`
@@ -53,8 +51,9 @@ jobs:
                     | grep -v tests/TestCase.php \
                     && (echo "UNKNOWN FILES DETECTED" && travis_terminate 1) || echo "NO UNKNOWN FILES"
                 - ./check_trailing_spaces.sh || travis_terminate 1
+                - ./dev-tools/tools/phpstan analyse
                 - if [ -n "$COMMIT_SCA_FILES" ]; then ./dev-tools/vendor/bin/phpmd `echo "$COMMIT_SCA_FILES" | grep -Ev "^tests/Fixtures" | xargs | sed 's/ /,/g'` text phpmd.xml || travis_terminate 1; fi
-                - ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file=.composer-require-checker.json || travis_terminate 1
+                - ./dev-tools/tools/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) || travis_terminate 1
                 - composer normalize -d ./dev-tools ./../composer.json --dry-run
                 - ./dev-tools/check-shell-scripts.sh
 
@@ -164,3 +163,6 @@ jobs:
                     tags: true
             after_deploy:
                 - ./dev-tools/trigger-website.sh ${TRAVIS_TOKEN} ${TRAVIS_TAG}
+
+    allow_failures:
+        - php: 7.4snapshot

+ 23 - 1
README.rst

@@ -407,6 +407,16 @@ Choose from the list of available rules:
   - ``spacing`` (``'none'``, ``'one'``): spacing to apply around concatenation operator;
     defaults to ``'none'``
 
+* **constant_case** [@PSR2, @Symfony, @PhpCsFixer]
+
+  The PHP constants ``true``, ``false``, and ``null`` MUST be written using the
+  correct casing.
+
+  Configuration options:
+
+  - ``case`` (``'lower'``, ``'upper'``): whether to use the ``upper`` or ``lower`` case
+    syntax; defaults to ``'lower'``
+
 * **date_time_immutable**
 
   Class ``DateTimeImmutable`` should be used instead of ``DateTime``.
@@ -790,9 +800,10 @@ Choose from the list of available rules:
 
   Cast should be written in lower case.
 
-* **lowercase_constants** [@PSR2, @Symfony, @PhpCsFixer]
+* **lowercase_constants**
 
   The PHP constants ``true``, ``false``, and ``null`` MUST be in lower case.
+  DEPRECATED: use ``constant_case`` instead.
 
 * **lowercase_keywords** [@PSR2, @Symfony, @PhpCsFixer]
 
@@ -1173,6 +1184,17 @@ Choose from the list of available rules:
 
   Logical NOT operators (``!``) should have one trailing whitespace.
 
+* **nullable_type_declaration_for_default_null_value**
+
+  Adds or removes ``?`` before type declarations for parameters with a
+  default ``null`` value.
+
+  Configuration options:
+
+  - ``use_nullable_type_declaration`` (``bool``): whether to add or remove ``?``
+    before type declarations for parameters with a default ``null`` value;
+    defaults to ``true``
+
 * **object_operator_without_whitespace** [@Symfony, @PhpCsFixer]
 
   There should not be space before or after object ``T_OBJECT_OPERATOR``

+ 1 - 0
dev-tools/.gitignore

@@ -1,3 +1,4 @@
 /composer.lock
 /bin/
+/tools/
 /vendor/

+ 0 - 1
dev-tools/composer.json

@@ -5,7 +5,6 @@
     "require-dev": {
         "humbug/box": "~3.7.0",
         "localheinz/composer-normalize": "^1.1",
-        "maglnet/composer-require-checker": "^2.0",
         "mi-schi/phpmd-extension": "^4.3",
         "phpmd/phpmd": "^2.6"
     },

+ 19 - 0
dev-tools/bin-download.sh → dev-tools/install.sh

@@ -9,15 +9,34 @@ mkdir -p bin
 VERSION_CB="2.0.0.2"
 VERSION_SC="stable"
 
+echo λλλ phive
+if [ ! -f bin/phive ]; then
+    wget --no-clobber --output-document=bin/phive https://phar.io/releases/phive.phar
+    wget --no-clobber --output-document=bin/phive.asc https://phar.io/releases/phive.phar.asc
+    gpg --keyserver pool.sks-keyservers.net --recv-keys 0x9D8A98B29B2D5D79
+    gpg --verify bin/phive.asc bin/phive
+    chmod u+x bin/phive
+    bin/phive --version
+fi
+
+echo λλλ checkbashisms
 if [ ! -f bin/checkbashisms ]; then
     wget --no-clobber --output-document=bin/checkbashisms https://sourceforge.net/projects/checkbaskisms/files/${VERSION_CB}/checkbashisms/download
     chmod u+x bin/checkbashisms
     bin/checkbashisms --version
 fi
 
+echo λλλ shellcheck
 if [ ! -f bin/shellcheck ]; then
     wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-${VERSION_SC}.linux.x86_64.tar.xz" | tar -xJv --directory bin shellcheck-${VERSION_SC}/shellcheck
     mv "bin/shellcheck-${VERSION_SC}/shellcheck" bin/
     rmdir "bin/shellcheck-${VERSION_SC}/"
     bin/shellcheck --version
 fi
+
+echo λλλ composer packages
+composer update
+composer info -D | sort
+
+echo λλλ phive packages
+./bin/phive install --trust-gpg-keys D2CCAC42F6295E7D,8E730BA25823D8B5

+ 5 - 0
dev-tools/phive.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phive xmlns="https://phar.io/phive">
+  <phar name="composer-require-checker" version="^2.0" installed="2.0.0" location="./tools/composer-require-checker" copy="false"/>
+  <phar name="phpstan" version="^0.11.15" installed="0.11.15" location="./tools/phpstan" copy="false"/>
+</phive>

+ 15 - 8
doc/COOKBOOK-FIXERS.md

@@ -76,6 +76,15 @@ final class RemoveCommentsFixer extends AbstractFixer
         // Return a definition of the fixer, it will be used in the README.rst.
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function isCandidate(Tokens $tokens)
+    {
+        // Check whether the collection is a candidate for fixing.
+        // Has to be ultra cheap to execute.
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -137,13 +146,6 @@ final class RemoveCommentsFixerTest extends AbstractFixerTestCase
     }
 }
 ```
-
-The files are created, one thing is still missing though: we need to
-update the README.md. Fortunately, PHP CS Fixer can help you here.
-Execute the following command in your command shell:
-
-`$ php php-cs-fixer readme > README.rst`
-
 ### Step 2 - Using tests to define fixers behavior
 
 Now that the files are created, you can start writing test to define the
@@ -238,7 +240,7 @@ final class RemoveCommentsFixerTest extends AbstractFixerTestBase
 You have defined the behavior of your fixer in tests. Now it is time to
 implement it.
 
-We need first to create one method to describe what this fixer does:
+First, we need to create one method to describe what this fixer does:
 `src/Fixer/Comment/RemoveCommentsFixer.php`:
 ```php
 final class RemoveCommentsFixer extends AbstractFixer
@@ -259,6 +261,11 @@ final class RemoveCommentsFixer extends AbstractFixer
     }
 }
 ```
+Next, we need to update the `README.rst`.
+Fortunately, PHP CS Fixer can help you here.
+Execute the following command in your command shell:
+
+`$ php php-cs-fixer readme > README.rst`
 
 Next, we must filter what type of tokens we want to fix. Here, we are interested in code that contains `T_COMMENT` tokens:
 `src/Fixer/Comment/RemoveCommentsFixer.php`:

+ 16 - 5
php-cs-fixer

@@ -51,15 +51,26 @@ if (class_exists('Phar')) {
     } catch (PharException $e) {
     }
 }
+
 if ($require) {
     // OK, it's not, let give Composer autoloader a try!
-    if (file_exists($a = __DIR__.'/../../autoload.php')) {
-        require_once $a;
-    } else {
-        require_once __DIR__.'/vendor/autoload.php';
+    $possibleFiles = [__DIR__.'/../../autoload.php', __DIR__.'/../autoload.php', __DIR__.'/vendor/autoload.php'];
+    $file = null;
+    foreach ($possibleFiles as $possibleFile) {
+        if (file_exists($possibleFile)) {
+            $file = $possibleFile;
+
+            break;
+        }
     }
 
-    unset($a);
+    if (null === $file) {
+        throw new RuntimeException('Unable to locate autoload.php file.');
+    }
+
+    require_once $file;
+
+    unset($possibleFiles, $possibleFile, $file);
 }
 unset($require);
 

+ 10 - 0
phpstan.neon

@@ -0,0 +1,10 @@
+parameters:
+    level: 0
+    paths:
+        - src
+        - tests
+    excludes_analyse:
+        - tests/Fixtures
+    ignoreErrors:
+        - '/^.+::__construct\(\) does not call parent constructor from SplFileInfo\.$/'
+        - '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'

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