Skip to content

Commit c0a665d

Browse files
authored
Allow PHP 8.0 (#7)
* Allow PHP 8.0 * Update check for @ operator
1 parent ccc9a29 commit c0a665d

File tree

6 files changed

+62
-102
lines changed

6 files changed

+62
-102
lines changed

.github/workflows/integrate.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
coverage: "none"
2828
php-version: "${{ matrix.php-version }}"
29-
tools: composer:v1, composer-normalize, composer-require-checker, composer-unused
29+
tools: composer-normalize
3030

3131
- name: "Get composer cache directory"
3232
id: composercache
@@ -56,8 +56,8 @@ jobs:
5656
strategy:
5757
matrix:
5858
php-version:
59-
- "7.3"
6059
- "7.4"
60+
- "8.0"
6161

6262
steps:
6363
- name: "Checkout"
@@ -83,8 +83,13 @@ jobs:
8383
restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-
8484

8585
- name: "Install dependencies"
86+
if: ${{ matrix.php-version != '8.0' }}
8687
run: "composer update --no-interaction --no-progress"
8788

89+
- name: "Install dependencies PHP 8.0"
90+
if: ${{ matrix.php-version == '8.0' }}
91+
run: "composer update --no-interaction --no-progress --ignore-platform-reqs"
92+
8893
- name: "Run tests"
8994
timeout-minutes: 3
9095
run: "vendor/bin/phpunit --no-coverage --no-logging"
@@ -109,7 +114,6 @@ jobs:
109114
coverage: "pcov"
110115
php-version: "${{ matrix.php-version }}"
111116
ini-values: zend.assertions=1
112-
tools: composer:v1
113117

114118
- name: "Get composer cache directory"
115119
id: composercache
@@ -144,7 +148,7 @@ jobs:
144148
strategy:
145149
matrix:
146150
php-version:
147-
- "7.3"
151+
- "7.4"
148152

149153
steps:
150154
- name: "Checkout"
@@ -155,7 +159,7 @@ jobs:
155159
with:
156160
coverage: "none"
157161
php-version: "${{ matrix.php-version }}"
158-
tools: composer:v1, cs2pr
162+
tools: cs2pr
159163

160164
- name: "Get composer cache directory"
161165
id: composercache
@@ -193,7 +197,7 @@ jobs:
193197
with:
194198
coverage: "none"
195199
php-version: "${{ matrix.php-version }}"
196-
tools: composer:v1, cs2pr
200+
tools: cs2pr
197201

198202
- name: "Get composer cache directory"
199203
id: composercache

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: csfix static-analysis test
22
@echo "Done."
33

4-
vendor: composer.json composer.lock
4+
vendor: composer.json
55
composer update
66
touch vendor
77

@@ -15,4 +15,4 @@ static-analysis: vendor
1515

1616
.PHONY: test
1717
test: vendor
18-
vendor/bin/phpunit --coverage-text
18+
php -d zend.assertions=1 vendor/bin/phpunit

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.3"
14+
"php": "^7.4 || ^8.0"
1515
},
1616
"require-dev": {
17-
"phpstan/phpstan": "^0.12",
18-
"phpstan/phpstan-phpunit": "^0.12",
19-
"phpunit/phpunit": "^9.3",
20-
"slam/php-cs-fixer-extensions": "^2.0",
21-
"slam/php-debug-r": "^1.6",
22-
"slam/phpstan-extensions": "^5.0",
23-
"symfony/console": "^5.1",
24-
"thecodingmachine/phpstan-strict-rules": "^0.12"
17+
"phpstan/phpstan": "^0.12.50",
18+
"phpstan/phpstan-phpunit": "^0.12.16",
19+
"phpunit/phpunit": "^9.4.2",
20+
"slam/php-cs-fixer-extensions": "^2.0.0",
21+
"slam/php-debug-r": "^1.6.1",
22+
"slam/phpstan-extensions": "^5.0.2",
23+
"symfony/console": "^5.1.6",
24+
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
2525
},
2626
"autoload": {
2727
"psr-4": {

lib/ErrorHandler.php

Lines changed: 36 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,12 @@
1010

1111
final class ErrorHandler
1212
{
13-
/**
14-
* @var bool
15-
*/
16-
private $autoExit = true;
17-
18-
/**
19-
* @var null|bool
20-
*/
21-
private $cli;
22-
23-
/**
24-
* @var null|int
25-
*/
26-
private $terminalWidth;
27-
28-
/**
29-
* @var null|resource
30-
*/
31-
private $errorOutputStream;
32-
33-
/**
34-
* @var bool
35-
*/
36-
private $hasColorSupport = false;
37-
38-
/**
39-
* @var null|bool
40-
*/
41-
private $logErrors;
42-
43-
/**
44-
* @var bool
45-
*/
46-
private $logVariables = true;
47-
48-
/**
49-
* @var null|bool
50-
*/
51-
private $displayErrors;
52-
53-
/**
54-
* @var callable
55-
*/
56-
private $emailCallback;
57-
58-
/**
59-
* @var callable
60-
*/
61-
private $errorLogCallback = '\\error_log';
62-
63-
/**
64-
* @var array<int, bool>
65-
*/
66-
private $scream = [];
67-
68-
/**
69-
* @var array<string, string>
70-
*/
71-
private static $colors = [
13+
private const COLORS = [
7214
'<error>' => "\033[37;41m",
7315
'</error>' => "\033[0m",
7416
];
7517

76-
/**
77-
* @var array<int, string>
78-
*/
79-
private static $errors = [
18+
private const ERRORS = [
8019
\E_COMPILE_ERROR => 'E_COMPILE_ERROR',
8120
\E_COMPILE_WARNING => 'E_COMPILE_WARNING',
8221
\E_CORE_ERROR => 'E_CORE_ERROR',
@@ -94,10 +33,33 @@ final class ErrorHandler
9433
\E_WARNING => 'E_WARNING',
9534
];
9635

36+
private bool $autoExit = true;
37+
private ?bool $cli = null;
38+
private ?int $terminalWidth = null;
39+
/**
40+
* @var null|resource
41+
*/
42+
private $errorOutputStream;
43+
private bool $hasColorSupport = false;
44+
private ?bool $logErrors = null;
45+
private bool $logVariables = true;
46+
private ?bool $displayErrors = null;
47+
/**
48+
* @var callable
49+
*/
50+
private $emailCallback;
51+
/**
52+
* @var callable
53+
*/
54+
private $errorLogCallback = '\\error_log';
55+
/**
56+
* @var array<int, bool>
57+
*/
58+
private array $scream = [];
9759
/**
9860
* @var array<int, class-string<Throwable>>
9961
*/
100-
private $exceptionsTypesFor404 = [];
62+
private array $exceptionsTypesFor404 = [];
10163

10264
public function __construct(callable $emailCallback)
10365
{
@@ -248,17 +210,11 @@ public function register(): void
248210
\set_exception_handler([$this, 'exceptionHandler']);
249211
}
250212

251-
/**
252-
* @param int $errno
253-
* @param string $errstr
254-
* @param string $errfile
255-
* @param int $errline
256-
*/
257-
public function errorHandler($errno, $errstr = '', $errfile = '', $errline = 0): void
213+
public function errorHandler(int $errno, string $errstr = '', string $errfile = '', int $errline = 0): bool
258214
{
259215
// Mandatory check for @ operator
260-
if (0 === \error_reporting() && ! isset($this->scream[$errno])) {
261-
return;
216+
if (0 === (\error_reporting() & $errno) && ! isset($this->scream[$errno])) {
217+
return true;
262218
}
263219

264220
throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
@@ -371,7 +327,11 @@ public function renderHtmlException(Throwable $exception): string
371327

372328
private function outputError(string $text): void
373329
{
374-
\fwrite($this->getErrorOutputStream(), \str_replace(\array_keys(self::$colors), $this->hasColorSupport ? \array_values(self::$colors) : '', $text) . \PHP_EOL);
330+
\fwrite($this->getErrorOutputStream(), \str_replace(
331+
\array_keys(self::COLORS),
332+
$this->hasColorSupport ? \array_values(self::COLORS) : '',
333+
$text
334+
) . \PHP_EOL);
375335
}
376336

377337
public function logException(Throwable $exception): void
@@ -476,8 +436,8 @@ public function emailException(Throwable $exception): void
476436
private function getExceptionCode(Throwable $exception): string
477437
{
478438
$code = $exception->getCode();
479-
if ($exception instanceof ErrorException && isset(self::$errors[$code])) {
480-
$code = self::$errors[$code];
439+
if ($exception instanceof ErrorException && isset(self::ERRORS[$code])) {
440+
$code = self::ERRORS[$code];
481441
}
482442

483443
return (string) $code;

phpstan.neon

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,18 @@ parameters:
99
- lib/
1010
- tests/
1111
ignoreErrors:
12-
-
13-
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\\.$#"
14-
count: 1
15-
path: lib/ErrorHandler.php
16-
1712
-
1813
message: "#^Expression \"@\\$arrayPerVerificaErrori\\['no_exception_thrown_on_undefined_index_now'\\]\" on a separate line does not do anything\\.$#"
1914
count: 1
2015
path: tests/ErrorHandlerTest.php
21-
2216
-
2317
message: "#^Offset 'no_exception_thrown…' does not exist on array\\(\\)\\.$#"
2418
count: 1
2519
path: tests/ErrorHandlerTest.php
26-
2720
-
2821
message: "#^Expression \"\\$arrayPerVerificaErrori\\['undefined_index'\\]\" on a separate line does not do anything\\.$#"
2922
count: 1
3023
path: tests/ErrorHandlerTest.php
31-
3224
-
3325
message: "#^Offset 'undefined_index' does not exist on array\\(\\)\\.$#"
3426
count: 1

phpunit.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
<?xml version="1.0"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
55
bootstrap="./vendor/autoload.php"
66
colors="true"
7+
verbose="true"
78
>
89
<coverage>
910
<include>
1011
<directory suffix=".php">./lib</directory>
1112
</include>
13+
<report>
14+
<text outputFile="php://stdout" showOnlySummary="true"/>
15+
</report>
1216
</coverage>
1317
<testsuite name="ErrorHandler">
1418
<directory>./tests</directory>

0 commit comments

Comments
 (0)