Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
213 changes: 213 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
coverage/
vendor/
.php_cs.cache
.phpunit.result.cache
Expand Down
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$config = new SlamCsFixer\Config(SlamCsFixer\Config::LIB);
$config = new SlamCsFixer\Config();
$config->getFinder()
->in(__DIR__ . '/lib')
->in(__DIR__ . '/tests')
Expand Down
2 changes: 0 additions & 2 deletions .scrutinizer.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 6 additions & 6 deletions lib/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -284,7 +284,7 @@ public function exceptionHandler(Throwable $exception): void
$this->outputError(\PHP_EOL);
$this->outputError(\sprintf('<error> %s </error>', \str_repeat(' ', $width)));
foreach ($lines as $line) {
$this->outputError(\sprintf('<error> %s%s </error>', $line, \str_repeat(' ', \max(0, $width - \mb_strlen($line)))));
$this->outputError(\sprintf('<error> %s%s </error>', $line, \str_repeat(' ', \max(0, $width - \strlen($line)))));
}
$this->outputError(\sprintf('<error> %s </error>', \str_repeat(' ', $width)));
$this->outputError(\PHP_EOL);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
29 changes: 24 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading