From 279cf6a9004fa611f74995023939492e6d0d0055 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 9 Dec 2020 13:49:22 +0100 Subject: [PATCH 1/4] Migrate to GH actions, add phpstan --- .github/workflows/continuous-integration.yml | 69 ++++++++++++++++++++ .github/workflows/lint.yml | 37 +++++++++++ .github/workflows/phpstan.yml | 46 +++++++++++++ .gitignore | 1 + .travis.yml | 35 ---------- composer.json | 13 +--- phpstan.neon.dist | 16 +++++ src/Monolog/ErrorHandler.php | 1 + src/Monolog/Handler/DynamoDbHandler.php | 1 + src/Monolog/Handler/FirePHPHandler.php | 2 +- src/Monolog/Handler/GelfHandler.php | 2 +- src/Monolog/Handler/HipChatHandler.php | 4 +- src/Monolog/Handler/RavenHandler.php | 2 +- src/Monolog/Handler/RedisHandler.php | 2 +- src/Monolog/Handler/StreamHandler.php | 2 +- src/Monolog/Logger.php | 2 +- src/Monolog/Utils.php | 2 +- 17 files changed, 183 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/phpstan.yml delete mode 100644 .travis.yml create mode 100644 phpstan.neon.dist diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 00000000..a05ef599 --- /dev/null +++ b/.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" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..4daf1c11 --- /dev/null +++ b/.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" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..b26a5573 --- /dev/null +++ b/.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 diff --git a/.gitignore b/.gitignore index 0640915d..a3ec4bab 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock .DS_Store .php_cs.cache .hg +.phpunit.result.cache diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fe999c20..00000000 --- a/.travis.yml +++ /dev/null @@ -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 diff --git a/composer.json b/composer.json index e171e202..d2deab7b 100644 --- a/composer.json +++ b/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 } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..1fe45df7 --- /dev/null +++ b/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#' diff --git a/src/Monolog/ErrorHandler.php b/src/Monolog/ErrorHandler.php index 36ec0098..5121c2cd 100644 --- a/src/Monolog/ErrorHandler.php +++ b/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); diff --git a/src/Monolog/Handler/DynamoDbHandler.php b/src/Monolog/Handler/DynamoDbHandler.php index 237b71f6..8846e0a0 100644 --- a/src/Monolog/Handler/DynamoDbHandler.php +++ b/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); } diff --git a/src/Monolog/Handler/FirePHPHandler.php b/src/Monolog/Handler/FirePHPHandler.php index c30b1843..2a171bd8 100644 --- a/src/Monolog/Handler/FirePHPHandler.php +++ b/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) { diff --git a/src/Monolog/Handler/GelfHandler.php b/src/Monolog/Handler/GelfHandler.php index 71e46693..b6cde7c6 100644 --- a/src/Monolog/Handler/GelfHandler.php +++ b/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; diff --git a/src/Monolog/Handler/HipChatHandler.php b/src/Monolog/Handler/HipChatHandler.php index 179d6268..30258e36 100644 --- a/src/Monolog/Handler/HipChatHandler.php +++ b/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(); diff --git a/src/Monolog/Handler/RavenHandler.php b/src/Monolog/Handler/RavenHandler.php index 9d24dfe8..b0298fa6 100644 --- a/src/Monolog/Handler/RavenHandler.php +++ b/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; diff --git a/src/Monolog/Handler/RedisHandler.php b/src/Monolog/Handler/RedisHandler.php index bb00db50..3725db24 100644 --- a/src/Monolog/Handler/RedisHandler.php +++ b/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) { diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index b52607d2..ad6960cb 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -154,7 +154,7 @@ class StreamHandler extends AbstractProcessingHandler return dirname(substr($stream, 7)); } - return; + return null; } private function createDir() diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index e649af51..b8b4f55b 100644 --- a/src/Monolog/Logger.php +++ b/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) diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index 712b1969..7f1ba129 100644 --- a/src/Monolog/Utils.php +++ b/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) From d3f4f48f0f1a400296db7fb05380574010187a52 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 9 Dec 2020 13:54:14 +0100 Subject: [PATCH 2/4] Fix lint task --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4daf1c11..da908ccf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,7 +30,7 @@ jobs: - 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" + run: "find src/ -type f -name '*.php' -not -name '*Trait.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" - name: "Lint PHP files" if: "matrix.php-version != '5.3'" From 24a9588865006395cd724ac4769c9ec3c7f6de6b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 9 Dec 2020 13:56:13 +0100 Subject: [PATCH 3/4] Disable php 8 build for v1 --- .github/workflows/continuous-integration.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a05ef599..f4de761b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,7 +25,8 @@ jobs: - "7.2" - "7.3" - "7.4" - - "8.0" + # disabled for monolog 1.x as not worth the trouble, people should use monolog 2 anyway + # - "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" From 7c977e451c0af0cc8de233871966fc21c46a42ac Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 9 Dec 2020 13:58:31 +0100 Subject: [PATCH 4/4] Fix lint --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index da908ccf..8c26a72d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,7 +30,7 @@ jobs: - name: "Lint PHP files on 5.3" if: "matrix.php-version == '5.3'" - run: "find src/ -type f -name '*.php' -not -name '*Trait.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" + run: "find src/ -type f -name '*.php' -not -name '*Trait.php' -not -name 'FormattableHandlerInterface.php' -not -name 'ProcessableHandlerInterface.php' -print0 | xargs -0 -L1 -P4 -- php -l -f" - name: "Lint PHP files" if: "matrix.php-version != '5.3'"