From 970a62aa32984782bf07345c428c0aa699197506 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 30 Sep 2020 08:48:10 +0200 Subject: [PATCH 1/3] First run --- .gitattributes | 3 +- .github/workflows/integrate.yaml | 229 +++++++++++++++++++++++++++++++ .scrutinizer.yml | 2 - .travis.yml | 22 --- README.md | 6 +- composer.json | 4 +- 6 files changed, 235 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/integrate.yaml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index cbf0de8..b5f5cda 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,7 @@ +/.github export-ignore /tests export-ignore .gitattributes export-ignore .gitignore export-ignore .php_cs export-ignore -.scrutinizer.yml export-ignore -.travis.yml export-ignore phpstan.neon export-ignore phpunit.xml export-ignore diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml new file mode 100644 index 0000000..5cc0c88 --- /dev/null +++ b/.github/workflows/integrate.yaml @@ -0,0 +1,229 @@ +name: "Integrate" + +on: + pull_request: + push: + branches: + - "master" + +jobs: + composer-json-lint: + name: "Lint composer.json" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: composer:v1, composer-normalize, composer-require-checker, composer-unused + + - 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 }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- + + - name: "Install dependencies" + run: "composer update --no-interaction --no-progress" + + - name: "Validate composer.json" + run: "composer validate --strict" + + - name: "Normalize composer.json" + run: "composer-normalize --dry-run" + + - name: "Check composer.json explicit dependencies" + run: "composer-require-checker check --config-file=$(realpath composer-require-checker.json)" + + - name: "Check composer.json unused dependencies" + run: "composer-unused" + + tests: + name: "Tests" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.3" + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: zend.assertions=1 + tools: composer:v1 + + - 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 }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- + + - name: "Install dependencies" + if: ${{ matrix.dependencies == 'highest' && matrix.php-version != '8.0' }} + run: "composer update --no-interaction --no-progress" + + - name: "Run tests" + timeout-minutes: 3 + run: "vendor/bin/phpunit --no-coverage --no-logging" + + code-coverage: + name: "Code Coverage" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: zend.assertions=1 + tools: composer:v1 + + - 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 }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- + + - name: "Install dependencies" + run: "composer update --no-interaction --no-progress" + + - name: "Run tests" + timeout-minutes: 3 + run: "vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-xml=coverage/coverage-xml --log-junit=coverage/junit.xml" + + - name: "Send code coverage report to Codecov.io" + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + fail_ci_if_error: true + + #- name: "Infection" + # timeout-minutes: 10 + # run: "vendor/bin/infection --ansi --threads=$(nproc) --coverage=coverage --skip-initial-tests" + # env: + # INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} + + #- name: "Output infections" + # run: "cat infections.log" + + coding-standards: + name: "Coding Standards" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.3" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: composer:v1, cs2pr + + - 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 }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- + + - name: "Install dependencies" + run: "composer update --no-interaction --no-progress" + + - name: "Check coding standards" + run: "vendor/bin/php-cs-fixer fix --verbose --dry-run --diff" + + static-analysis: + name: "Static Analysis" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: composer:v1, cs2pr + + - 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 }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- + + - name: "Install dependencies" + run: "composer update --no-interaction --no-progress" + + - name: "Run static analysis" + run: "vendor/bin/phpstan analyse --no-progress" diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index d73cd74..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,2 +0,0 @@ -tools: - external_code_coverage: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 67c275d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: php - -sudo: false - -matrix: - fast_finish: true - include: - - php: 7.3 - env: CS_CHECK=1 STATIC_ANALYSIS=1 - - php: 7.4 - env: CODE_COVERAGE=1 - -cache: - directories: - - $HOME/.composer/cache - -install: wget -qO - https://github.com/Slamdunk/travis-scripts/raw/master/php-install.sh | sh - -script: wget -qO - https://github.com/Slamdunk/travis-scripts/raw/master/php-script.sh | sh - -notifications: - email: false diff --git a/README.md b/README.md index 8749963..026e4e0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # php-errorhandler-legacy -[![Build Status](https://travis-ci.org/Slamdunk/php-errorhandler-legacy.svg?branch=master)](https://travis-ci.org/Slamdunk/php-errorhandler-legacy) -[![Code Coverage](https://scrutinizer-ci.com/g/Slamdunk/php-errorhandler-legacy/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Slamdunk/php-errorhandler-legacy/?branch=master) -[![Packagist](https://img.shields.io/packagist/v/slam/php-errorhandler-legacy.svg)](https://packagist.org/packages/slam/php-errorhandler-legacy) +[![Latest Stable Version](https://img.shields.io/packagist/v/slam/php-errorhandler-legacy.svg)](https://packagist.org/packages/slam/php-errorhandler-legacy) +[![Integrate](https://github.com/Slamdunk/php-errorhandler-legacy/workflows/Integrate/badge.svg?branch=master)](https://github.com/Slamdunk/php-errorhandler-legacy/actions) +[![Code Coverage](https://codecov.io/gh/Slamdunk/php-errorhandler-legacy/coverage.svg?branch=master)](https://codecov.io/gh/Slamdunk/php-errorhandler-legacy?branch=master) Crappy class to manage errors and exceptions diff --git a/composer.json b/composer.json index ed82bc6..1607415 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpunit/phpunit": "^9.2", - "slam/php-cs-fixer-extensions": "^1.19", + "slam/php-cs-fixer-extensions": "^2.0", "slam/php-debug-r": "^1.6", - "slam/phpstan-extensions": "^4.0", + "slam/phpstan-extensions": "^5.0", "symfony/console": "^5.1", "thecodingmachine/phpstan-strict-rules": "^0.12" }, From 45f69ec54025ed20f6aeed6ef2645473996bcc17 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 30 Sep 2020 09:08:23 +0200 Subject: [PATCH 2/3] Fixes --- .github/workflows/integrate.yaml | 7 ------- .gitignore | 1 + .php_cs | 2 +- Makefile | 22 ++++++++++++++++++++++ composer.json | 2 +- lib/ErrorHandler.php | 10 +++++----- phpstan.neon | 29 ++++++++++++++++++++++++----- phpunit.xml | 26 +++++++++++++------------- 8 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 5cc0c88..8d1f0aa 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -48,12 +48,6 @@ jobs: - name: "Normalize composer.json" run: "composer-normalize --dry-run" - - name: "Check composer.json explicit dependencies" - run: "composer-require-checker check --config-file=$(realpath composer-require-checker.json)" - - - name: "Check composer.json unused dependencies" - run: "composer-unused" - tests: name: "Tests" @@ -89,7 +83,6 @@ jobs: restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer- - name: "Install dependencies" - if: ${{ matrix.dependencies == 'highest' && matrix.php-version != '8.0' }} run: "composer update --no-interaction --no-progress" - name: "Run tests" diff --git a/.gitignore b/.gitignore index ea60caf..55573b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ +coverage/ vendor/ .php_cs.cache .phpunit.result.cache diff --git a/.php_cs b/.php_cs index db1b862..c549e32 100644 --- a/.php_cs +++ b/.php_cs @@ -1,6 +1,6 @@ getFinder() ->in(__DIR__ . '/lib') ->in(__DIR__ . '/tests') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7b7c2b4 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +all: csfix static-analysis test + @echo "Done." + +vendor: composer.json composer.lock + composer update + touch vendor + +.PHONY: csfix +csfix: vendor + vendor/bin/php-cs-fixer fix --verbose + +.PHONY: static-analysis +static-analysis: vendor + vendor/bin/phpstan analyse + +.PHONY: test +test: vendor + vendor/bin/phpunit --coverage-text --coverage-xml=coverage/coverage-xml --log-junit=coverage/junit.xml + +#.PHONY: code-coverage +#code-coverage: test +# vendor/bin/infection --threads=$(shell nproc) --coverage=coverage --skip-initial-tests diff --git a/composer.json b/composer.json index 1607415..580a20d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require-dev": { "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^9.2", + "phpunit/phpunit": "^9.3", "slam/php-cs-fixer-extensions": "^2.0", "slam/php-debug-r": "^1.6", "slam/phpstan-extensions": "^5.0", diff --git a/lib/ErrorHandler.php b/lib/ErrorHandler.php index 78c94cb..364032a 100644 --- a/lib/ErrorHandler.php +++ b/lib/ErrorHandler.php @@ -272,9 +272,9 @@ public function exceptionHandler(Throwable $exception): void $line = $lines[$i]; if (isset($line[$width])) { - $lines[$i] = \mb_substr($line, 0, $width); + $lines[$i] = \substr($line, 0, $width); if (isset($line[0]) && '#' !== $line[0]) { - \array_splice($lines, $i + 1, 0, ' ' . \mb_substr($line, $width)); + \array_splice($lines, $i + 1, 0, ' ' . \substr($line, $width)); } } @@ -284,7 +284,7 @@ public function exceptionHandler(Throwable $exception): void $this->outputError(\PHP_EOL); $this->outputError(\sprintf(' %s ', \str_repeat(' ', $width))); foreach ($lines as $line) { - $this->outputError(\sprintf(' %s%s ', $line, \str_repeat(' ', \max(0, $width - \mb_strlen($line))))); + $this->outputError(\sprintf(' %s%s ', $line, \str_repeat(' ', \max(0, $width - \strlen($line))))); } $this->outputError(\sprintf(' %s ', \str_repeat(' ', $width))); $this->outputError(\PHP_EOL); @@ -314,7 +314,7 @@ public function exceptionHandler(Throwable $exception): void public function renderHtmlException(Throwable $exception): string { - $ajax = (isset($_SERVER) && isset($_SERVER['X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['X_REQUESTED_WITH']); + $ajax = (isset($_SERVER['X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['X_REQUESTED_WITH']); $output = ''; $errorType = '500: Internal Server Error'; if (\in_array(\get_class($exception), $this->exceptionsTypesFor404, true)) { @@ -427,7 +427,7 @@ public function emailException(Throwable $exception): void $username = null; if ($this->logVariables()) { - if (isset($_POST) && ! empty($_POST)) { + if (! empty($_POST)) { $bodyText .= '$_POST = ' . \print_r($_POST, true) . \PHP_EOL; } if (isset($_SESSION) && ! empty($_SESSION)) { diff --git a/phpstan.neon b/phpstan.neon index 21b2233..833911a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,8 +9,27 @@ parameters: - lib/ - tests/ ignoreErrors: - - '#Function \w+ is unsafe to use, rely on .+ instead#' - - '#Variable \$_\w+ in isset\(\) always exists and is not nullable#' - - '#Parameter \#1 \$error_handler of function set_error_handler expects#' - - '#Offset .(no_exception_thrown.*|undefined_index). does not exist on array#' - - '#Expression .+arrayPerVerificaErrori.+ on a separate line does not do anything#' + - + message: "#^Parameter \\#1 \\$error_handler of function set_error_handler expects \\(callable\\(int, string, string, int, array\\)\\: bool\\)\\|null, array\\(\\$this\\(Slam\\\\ErrorHandler\\\\ErrorHandler\\), 'errorHandler'\\) given\\.$#" + count: 1 + path: lib/ErrorHandler.php + + - + message: "#^Expression \"@\\$arrayPerVerificaErrori\\['no_exception_thrown_on_undefined_index_now'\\]\" on a separate line does not do anything\\.$#" + count: 1 + path: tests/ErrorHandlerTest.php + + - + message: "#^Offset 'no_exception_thrown…' does not exist on array\\(\\)\\.$#" + count: 1 + path: tests/ErrorHandlerTest.php + + - + message: "#^Expression \"\\$arrayPerVerificaErrori\\['undefined_index'\\]\" on a separate line does not do anything\\.$#" + count: 1 + path: tests/ErrorHandlerTest.php + + - + message: "#^Offset 'undefined_index' does not exist on array\\(\\)\\.$#" + count: 1 + path: tests/ErrorHandlerTest.php diff --git a/phpunit.xml b/phpunit.xml index 439d567..c02f873 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,16 @@ + - - ./tests - - - - - ./lib - - + + + ./lib + + + + ./tests + From 26f8d22b3d904898867766623d74bb469f03caf8 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Wed, 30 Sep 2020 09:11:37 +0200 Subject: [PATCH 3/3] 100% CC --- .github/workflows/integrate.yaml | 9 --------- Makefile | 6 +----- lib/ErrorHandler.php | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 8d1f0aa..7d44874 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -136,15 +136,6 @@ jobs: file: ./coverage.xml fail_ci_if_error: true - #- name: "Infection" - # timeout-minutes: 10 - # run: "vendor/bin/infection --ansi --threads=$(nproc) --coverage=coverage --skip-initial-tests" - # env: - # INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} - - #- name: "Output infections" - # run: "cat infections.log" - coding-standards: name: "Coding Standards" diff --git a/Makefile b/Makefile index 7b7c2b4..5d625e7 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,4 @@ static-analysis: vendor .PHONY: test test: vendor - vendor/bin/phpunit --coverage-text --coverage-xml=coverage/coverage-xml --log-junit=coverage/junit.xml - -#.PHONY: code-coverage -#code-coverage: test -# vendor/bin/infection --threads=$(shell nproc) --coverage=coverage --skip-initial-tests + vendor/bin/phpunit --coverage-text diff --git a/lib/ErrorHandler.php b/lib/ErrorHandler.php index 364032a..ee9c880 100644 --- a/lib/ErrorHandler.php +++ b/lib/ErrorHandler.php @@ -135,7 +135,7 @@ public function getTerminalWidth(): int $width = \getenv('COLUMNS'); if (false === $width && 1 === \preg_match('{rows.(\d+);.columns.(\d+);}i', \exec('stty -a 2> /dev/null | grep columns'), $match)) { - $width = $match[2]; + $width = $match[2]; // @codeCoverageIgnore } $this->setTerminalWidth((int) $width ?: 80);