瀏覽代碼

Migrate to GH actions, add phpstan

Jordi Boggiano 5 年之前
父節點
當前提交
279cf6a900

+ 69 - 0
.github/workflows/continuous-integration.yml

@@ -0,0 +1,69 @@
+name: "Continuous Integration"
+
+on:
+  - push
+  - pull_request
+
+env:
+  COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
+
+jobs:
+  tests:
+    name: "CI"
+
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        php-version:
+          - "5.3"
+          - "5.4"
+          - "5.5"
+          - "5.6"
+          - "7.0"
+          - "7.1"
+          - "7.2"
+          - "7.3"
+          - "7.4"
+          - "8.0"
+          # disabled for now as it leads to PHPUnit installing in a very old 4.3 version due to phpspec/prophecy not allowing 8.1
+          # - "8.1"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+
+      - name: "Install PHP 5"
+        if: "startsWith(matrix.php-version, '5.')"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          php-version: "${{ matrix.php-version }}"
+          extensions: "mongo"
+
+      - name: "Install PHP 7+"
+        if: "!startsWith(matrix.php-version, '5.')"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          php-version: "${{ matrix.php-version }}"
+
+      - name: Get composer cache directory
+        id: composercache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache dependencies
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.composercache.outputs.dir }}
+          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
+          restore-keys: ${{ runner.os }}-composer-
+
+      - name: "Install latest dependencies"
+        run: |
+          # Remove PHPStan as it requires a newer PHP
+          composer remove phpstan/phpstan --dev --no-update
+          composer update ${{ env.COMPOSER_FLAGS }}
+
+      - name: "Run tests"
+        run: "composer test"

+ 37 - 0
.github/workflows/lint.yml

@@ -0,0 +1,37 @@
+name: "PHP Lint"
+
+on:
+  push:
+  pull_request:
+
+jobs:
+  tests:
+    name: "Lint"
+
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        php-version:
+          - "5.3"
+          - "8.0"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+
+      - name: "Install PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          extensions: "intl"
+          ini-values: "memory_limit=-1"
+          php-version: "${{ matrix.php-version }}"
+
+      - name: "Lint PHP files on 5.3"
+        if: "matrix.php-version == '5.3'"
+        run: "find src/ -type f -name '*.php' -exclude '*Trait.php' -print0 | xargs -0 -L1 -P4 -- php -l -f"
+
+      - name: "Lint PHP files"
+        if: "matrix.php-version != '5.3'"
+        run: "find src/ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f"

+ 46 - 0
.github/workflows/phpstan.yml

@@ -0,0 +1,46 @@
+name: "PHPStan"
+
+on:
+  - push
+  - pull_request
+
+env:
+  COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
+
+jobs:
+  tests:
+    name: "PHPStan"
+
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        php-version:
+          - "8.0"
+
+    steps:
+      - name: "Checkout"
+        uses: "actions/checkout@v2"
+
+      - name: "Install PHP"
+        uses: "shivammathur/setup-php@v2"
+        with:
+          coverage: "none"
+          php-version: "${{ matrix.php-version }}"
+
+      - name: Get composer cache directory
+        id: composercache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache dependencies
+        uses: actions/cache@v2
+        with:
+          path: ${{ steps.composercache.outputs.dir }}
+          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
+          restore-keys: ${{ runner.os }}-composer-
+
+      - name: "Install latest dependencies"
+        run: "composer update ${{ env.COMPOSER_FLAGS }}"
+
+      - name: Run PHPStan
+        run: composer phpstan

+ 1 - 0
.gitignore

@@ -5,3 +5,4 @@ composer.lock
 .DS_Store
 .php_cs.cache
 .hg
+.phpunit.result.cache

+ 0 - 35
.travis.yml

@@ -1,35 +0,0 @@
-language: php
-
-matrix:
-  fast_finish: true
-  include:
-    - dist: precise
-      php: 5.3
-      env: deps=low
-    - dist: precise
-      php: 5.3
-    - php: 5.4
-      dist: trusty
-    - php: 5.5
-      dist: trusty
-    - php: 5.6
-      dist: xenial
-    - php: 7.0
-      dist: xenial
-    - php: 7.1
-      dist: bionic
-    - php: 7.2
-      dist: bionic
-    - php: 7.3
-      dist: bionic
-    - php: 7.4
-      dist: bionic
-
-before_script:
-  - if [[ $TRAVIS_PHP_VERSION = 5.* ]]; then echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
-  - if [ "$TRAVIS_PHP_VERSION" == "7.4" ]; then echo "error_reporting = E_ALL & ~E_DEPRECATED" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
-  - composer self-update --snapshot
-  - if [ "$deps" == "low" ]; then composer update -n --prefer-dist --prefer-lowest --prefer-stable; fi
-  - if [ "$deps" != "low" ]; then composer update -n --prefer-dist; fi
-
-script: composer test

+ 3 - 10
composer.json

@@ -26,7 +26,7 @@
         "php-amqplib/php-amqplib": "~2.4",
         "swiftmailer/swiftmailer": "^5.3|^6.0",
         "php-console/php-console": "^3.1.3",
-        "php-parallel-lint/php-parallel-lint": "^1.0"
+        "phpstan/phpstan": "^0.12.59"
     },
     "suggest": {
         "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
@@ -50,16 +50,9 @@
     "provide": {
         "psr/log-implementation": "1.0.0"
     },
-    "extra": {
-        "branch-alias": {
-            "dev-master": "2.0.x-dev"
-        }
-    },
     "scripts": {
-        "test": [
-            "parallel-lint . --exclude vendor --exclude src/Monolog/Handler/FormattableHandlerInterface.php  --exclude src/Monolog/Handler/FormattableHandlerTrait.php --exclude src/Monolog/Handler/ProcessableHandlerInterface.php --exclude src/Monolog/Handler/ProcessableHandlerTrait.php",
-            "phpunit"
-        ]
+        "test": "vendor/bin/phpunit",
+        "phpstan": "vendor/bin/phpstan analyse"
     },
     "lock": false
 }

+ 16 - 0
phpstan.neon.dist

@@ -0,0 +1,16 @@
+parameters:
+    level: 3
+
+    paths:
+        - src/
+#        - tests/
+
+
+    ignoreErrors:
+        - '#zend_monitor_|ZEND_MONITOR_#'
+        - '#RollbarNotifier#'
+        - '#Predis\\Client#'
+        - '#^Cannot call method ltrim\(\) on int\|false.$#'
+        - '#^Access to an undefined property Raven_Client::\$context.$#'
+        - '#MongoDB\\(Client|Collection)#'
+        - '#Gelf\\IMessagePublisher#'

+ 1 - 0
src/Monolog/ErrorHandler.php

@@ -62,6 +62,7 @@ class ErrorHandler
         //Forces the autoloader to run for LogLevel. Fixes an autoload issue at compile-time on PHP5.3. See https://github.com/Seldaek/monolog/pull/929
         class_exists('\\Psr\\Log\\LogLevel', true);
 
+        /** @phpstan-ignore-next-line */
         $handler = new static($logger);
         if ($errorLevelMap !== false) {
             $handler->registerErrorHandler($errorLevelMap);

+ 1 - 0
src/Monolog/Handler/DynamoDbHandler.php

@@ -77,6 +77,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
         if ($this->version === 3) {
             $formatted = $this->marshaler->marshalItem($filtered);
         } else {
+            /** @phpstan-ignore-next-line */
             $formatted = $this->client->formatAttributes($filtered);
         }
 

+ 1 - 1
src/Monolog/Handler/FirePHPHandler.php

@@ -72,7 +72,7 @@ class FirePHPHandler extends AbstractProcessingHandler
      *
      * @see createHeader()
      * @param  array  $record
-     * @return string
+     * @return array
      */
     protected function createRecordHeader(array $record)
     {

+ 1 - 1
src/Monolog/Handler/GelfHandler.php

@@ -27,7 +27,7 @@ use Monolog\Formatter\GelfMessageFormatter;
 class GelfHandler extends AbstractProcessingHandler
 {
     /**
-     * @var Publisher the publisher object that sends the message to the server
+     * @var Publisher|PublisherInterface|IMessagePublisher the publisher object that sends the message to the server
      */
     protected $publisher;
 

+ 2 - 2
src/Monolog/Handler/HipChatHandler.php

@@ -270,10 +270,10 @@ class HipChatHandler extends SocketHandler
      * will be the highest level from the given records. Datetime will be taken
      * from the first record.
      *
-     * @param $records
+     * @param array $records
      * @return array
      */
-    private function combineRecords($records)
+    private function combineRecords(array $records)
     {
         $batchRecord = null;
         $batchRecords = array();

+ 1 - 1
src/Monolog/Handler/RavenHandler.php

@@ -50,7 +50,7 @@ class RavenHandler extends AbstractProcessingHandler
     protected $ravenClient;
 
     /**
-     * @var LineFormatter The formatter to use for the logs generated via handleBatch()
+     * @var FormatterInterface The formatter to use for the logs generated via handleBatch()
      */
     protected $batchFormatter;
 

+ 1 - 1
src/Monolog/Handler/RedisHandler.php

@@ -36,7 +36,7 @@ class RedisHandler extends AbstractProcessingHandler
      * @param string                $key     The key name to push records to
      * @param int                   $level   The minimum logging level at which this handler will be triggered
      * @param bool                  $bubble  Whether the messages that are handled can bubble up the stack or not
-     * @param int                   $capSize Number of entries to limit list size to
+     * @param int|false             $capSize Number of entries to limit list size to
      */
     public function __construct($redis, $key, $level = Logger::DEBUG, $bubble = true, $capSize = false)
     {

+ 1 - 1
src/Monolog/Handler/StreamHandler.php

@@ -154,7 +154,7 @@ class StreamHandler extends AbstractProcessingHandler
             return dirname(substr($stream, 7));
         }
 
-        return;
+        return null;
     }
 
     private function createDir()

+ 1 - 1
src/Monolog/Logger.php

@@ -522,7 +522,7 @@ class Logger implements LoggerInterface, ResettableInterface
     /**
      * Converts PSR-3 levels to Monolog ones if necessary
      *
-     * @param string|int Level number (monolog) or name (PSR-3)
+     * @param string|int $level Level number (monolog) or name (PSR-3)
      * @return int
      */
     public static function toMonologLevel($level)

+ 1 - 1
src/Monolog/Utils.php

@@ -168,7 +168,7 @@ class Utils
      * Function converts the input in place in the passed variable so that it
      * can be used as a callback for array_walk_recursive.
      *
-     * @param mixed &$data Input to check and convert if needed
+     * @param mixed $data Input to check and convert if needed, passed by ref
      * @private
      */
     public static function detectAndCleanUtf8(&$data)