diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 00000000..c22dd6c1 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,52 @@ +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: + - "7.2" + - "7.3" + - "7.4" + - "8.0" + # disabled for now as phpspec/prophecy does not allow 8.1 + # - "8.1" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP 7+" + 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 tests" + run: "composer test" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..9e20a03e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: "PHP Lint" + +on: + push: + pull_request: + +jobs: + tests: + name: "Lint" + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "7.2" + - "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" + 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/.travis.yml b/.travis.yml deleted file mode 100644 index 7223ea98..00000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - -env: - global: - - COMPOSER_ARGS= - -matrix: - fast_finish: true - include: - - php: 7.2 - dist: bionic - env: deps=low - - php: 7.2 - dist: bionic - - php: 7.3 - dist: bionic - - php: 7.4 - dist: bionic - - php: nightly - dist: bionic - env: COMPOSER_ARGS=--ignore-platform-reqs - -before_script: - - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - composer self-update --snapshot - - if [ "$deps" == "low" ]; then composer update -n --prefer-dist --prefer-lowest --prefer-stable $COMPOSER_ARGS; fi - - if [ "$deps" != "low" ]; then composer update -n --prefer-dist $COMPOSER_ARGS; fi - -script: - - if [ "`phpenv version-name`" != "nightly" ]; then composer lint; fi - - composer test diff --git a/composer.json b/composer.json index 46e141c0..247a6749 100644 --- a/composer.json +++ b/composer.json @@ -23,13 +23,13 @@ "graylog2/gelf-php": "^1.4.2", "php-amqplib/php-amqplib": "~2.4", "php-console/php-console": "^3.1.3", - "php-parallel-lint/php-parallel-lint": "^1.0", "phpspec/prophecy": "^1.6.1", "phpunit/phpunit": "^8.5", "predis/predis": "^1.1", "rollbar/rollbar": "^1.3", "ruflin/elastica": ">=0.90 <3.0", - "swiftmailer/swiftmailer": "^5.3|^6.0" + "swiftmailer/swiftmailer": "^5.3|^6.0", + "phpstan/phpstan": "^0.12.59" }, "suggest": { "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", @@ -56,16 +56,12 @@ }, "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-main": "2.x-dev" } }, "scripts": { - "lint": [ - "parallel-lint . --exclude vendor" - ], - "test": [ - "phpunit" - ] + "test": "vendor/bin/phpunit", + "phpstan": "vendor/bin/phpstan analyse" }, "config": { "sort-packages": true, 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/Handler/DynamoDbHandler.php b/src/Monolog/Handler/DynamoDbHandler.php index 21d74310..961d7acf 100644 --- a/src/Monolog/Handler/DynamoDbHandler.php +++ b/src/Monolog/Handler/DynamoDbHandler.php @@ -75,6 +75,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/Utils.php b/src/Monolog/Utils.php index 5299d441..440beb77 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -177,7 +177,7 @@ final 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 static function detectAndCleanUtf8(&$data) { diff --git a/tests/Monolog/Handler/PHPConsoleHandlerTest.php b/tests/Monolog/Handler/PHPConsoleHandlerTest.php index 7b899550..1169419f 100644 --- a/tests/Monolog/Handler/PHPConsoleHandlerTest.php +++ b/tests/Monolog/Handler/PHPConsoleHandlerTest.php @@ -36,9 +36,17 @@ class PHPConsoleHandlerTest extends TestCase protected function setUp(): void { + // suppress warnings until https://github.com/barbushin/php-console/pull/173 is merged + $previous = error_reporting(0); if (!class_exists('PhpConsole\Connector')) { + error_reporting($previous); $this->markTestSkipped('PHP Console library not found. See https://github.com/barbushin/php-console#installation'); } + if (!class_exists('PhpConsole\Handler')) { + error_reporting($previous); + $this->markTestSkipped('PHP Console library not found. See https://github.com/barbushin/php-console#installation'); + } + error_reporting($previous); $this->connector = $this->initConnectorMock(); $this->debugDispatcher = $this->initDebugDispatcherMock($this->connector);