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..7d44874
--- /dev/null
+++ b/.github/workflows/integrate.yaml
@@ -0,0 +1,213 @@
+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"
+
+ 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"
+ 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
+
+ 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/.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/.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/Makefile b/Makefile
new file mode 100644
index 0000000..5d625e7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+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
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
-[](https://travis-ci.org/Slamdunk/php-errorhandler-legacy)
-[](https://scrutinizer-ci.com/g/Slamdunk/php-errorhandler-legacy/?branch=master)
-[](https://packagist.org/packages/slam/php-errorhandler-legacy)
+[](https://packagist.org/packages/slam/php-errorhandler-legacy)
+[](https://github.com/Slamdunk/php-errorhandler-legacy/actions)
+[](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..580a20d 100644
--- a/composer.json
+++ b/composer.json
@@ -16,10 +16,10 @@
"require-dev": {
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^9.2",
- "slam/php-cs-fixer-extensions": "^1.19",
+ "phpunit/phpunit": "^9.3",
+ "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"
},
diff --git a/lib/ErrorHandler.php b/lib/ErrorHandler.php
index 78c94cb..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);
@@ -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
+