Skip to content

Commit 1f03b94

Browse files
authored
Php 7.4 (#2)
* PHPUnit ok * Support PHP 7.4 * Updated to Symfony 5.0
1 parent 4d0d3ff commit 1f03b94

File tree

6 files changed

+174
-89
lines changed

6 files changed

+174
-89
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
12
vendor/
23
.php_cs.cache
4+
.phpunit.result.cache
35
composer.lock

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ sudo: false
55
matrix:
66
fast_finish: true
77
include:
8-
- php: 7.1
9-
env: CS_CHECK=1 STATIC_ANALYSIS=1
10-
- php: 7.2
118
- php: 7.3
9+
env: CS_CHECK=1 STATIC_ANALYSIS=1
10+
- php: 7.4
1211
env: CODE_COVERAGE=1
1312

1413
cache:

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.1"
14+
"php": "^7.3"
1515
},
1616
"require-dev": {
17-
"phpstan/phpstan": "^0.11",
18-
"phpstan/phpstan-phpunit": "^0.11",
19-
"phpunit/phpunit": "^7.5",
17+
"phpstan/phpstan": "^0.12",
18+
"phpstan/phpstan-phpunit": "^0.12",
19+
"phpunit/phpunit": "^8.5",
2020
"roave/security-advisories": "dev-master",
21-
"slam/php-cs-fixer-extensions": "^1.18",
21+
"slam/php-cs-fixer-extensions": "^1.19",
2222
"slam/php-debug-r": "^1.6",
23-
"slam/phpstan-extensions": "^3.6",
24-
"symfony/console": "^4.3",
25-
"thecodingmachine/phpstan-strict-rules": "^0.11"
23+
"slam/phpstan-extensions": "^4.0",
24+
"symfony/console": "^5.0",
25+
"thecodingmachine/phpstan-strict-rules": "^0.12"
2626
},
2727
"autoload": {
2828
"psr-4": {

lib/ErrorHandler.php

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,67 @@
55
namespace Slam\ErrorHandler;
66

77
use Doctrine\Common\Util\Debug as DoctrineDebug;
8+
use ErrorException;
9+
use Throwable;
810

911
final class ErrorHandler
1012
{
13+
/**
14+
* @var bool
15+
*/
1116
private $autoExit = true;
17+
18+
/**
19+
* @var null|bool
20+
*/
1221
private $cli;
22+
23+
/**
24+
* @var null|int
25+
*/
1326
private $terminalWidth;
27+
28+
/**
29+
* @var null|resource
30+
*/
1431
private $errorOutputStream;
32+
33+
/**
34+
* @var bool
35+
*/
1536
private $hasColorSupport = false;
37+
38+
/**
39+
* @var null|bool
40+
*/
1641
private $logErrors;
42+
43+
/**
44+
* @var bool
45+
*/
1746
private $logVariables = true;
47+
48+
/**
49+
* @var callable
50+
*/
1851
private $emailCallback;
52+
53+
/**
54+
* @var array<int, bool>
55+
*/
1956
private $scream = [];
2057

58+
/**
59+
* @var array<string, string>
60+
*/
2161
private static $colors = [
2262
'<error>' => "\033[37;41m",
2363
'</error>' => "\033[0m",
2464
];
2565

66+
/**
67+
* @var array<int, string>
68+
*/
2669
private static $errors = [
2770
\E_COMPILE_ERROR => 'E_COMPILE_ERROR',
2871
\E_COMPILE_WARNING => 'E_COMPILE_WARNING',
@@ -65,6 +108,7 @@ public function isCli(): bool
65108
{
66109
if (null === $this->cli) {
67110
$this->setCli(\PHP_SAPI === 'cli');
111+
\assert(null !== $this->cli);
68112
}
69113

70114
return $this->cli;
@@ -85,11 +129,15 @@ public function getTerminalWidth(): int
85129
}
86130

87131
$this->setTerminalWidth((int) $width ?: 80);
132+
\assert(null !== $this->terminalWidth);
88133
}
89134

90135
return $this->terminalWidth;
91136
}
92137

138+
/**
139+
* @param mixed $errorOutputStream
140+
*/
93141
public function setErrorOutputStream($errorOutputStream): void
94142
{
95143
if (! \is_resource($errorOutputStream)) {
@@ -100,10 +148,14 @@ public function setErrorOutputStream($errorOutputStream): void
100148
$this->hasColorSupport = (\function_exists('posix_isatty') && @\posix_isatty($errorOutputStream));
101149
}
102150

151+
/**
152+
* @return resource
153+
*/
103154
public function getErrorOutputStream()
104155
{
105156
if (null === $this->errorOutputStream) {
106157
$this->setErrorOutputStream(\STDERR);
158+
\assert(null !== $this->errorOutputStream);
107159
}
108160

109161
return $this->errorOutputStream;
@@ -118,6 +170,7 @@ public function logErrors(): bool
118170
{
119171
if (null === $this->logErrors) {
120172
$this->setLogErrors(! \interface_exists(\PHPUnit\Framework\Test::class));
173+
\assert(null !== $this->logErrors);
121174
}
122175

123176
return $this->logErrors;
@@ -133,11 +186,17 @@ public function logVariables(): bool
133186
return $this->logVariables;
134187
}
135188

189+
/**
190+
* @param array<int, bool> $scream
191+
*/
136192
public function setScreamSilencedErrors(array $scream): void
137193
{
138194
$this->scream = $scream;
139195
}
140196

197+
/**
198+
* @return array<int, bool>
199+
*/
141200
public function getScreamSilencedErrors(): array
142201
{
143202
return $this->scream;
@@ -149,17 +208,23 @@ public function register(): void
149208
\set_exception_handler([$this, 'exceptionHandler']);
150209
}
151210

211+
/**
212+
* @param int $errno
213+
* @param string $errstr
214+
* @param string $errfile
215+
* @param int $errline
216+
*/
152217
public function errorHandler($errno, $errstr = '', $errfile = '', $errline = 0): void
153218
{
154219
// Mandatory check for @ operator
155220
if (0 === \error_reporting() && ! isset($this->scream[$errno])) {
156221
return;
157222
}
158223

159-
throw new \ErrorException($errstr, $errno, $errno, $errfile, $errline);
224+
throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
160225
}
161226

162-
public function exceptionHandler(\Throwable $exception): void
227+
public function exceptionHandler(Throwable $exception): void
163228
{
164229
$this->logException($exception);
165230
$this->emailException($exception);
@@ -256,7 +321,7 @@ private function outputError(string $text): void
256321
\fwrite($this->getErrorOutputStream(), \str_replace(\array_keys(self::$colors), $this->hasColorSupport ? \array_values(self::$colors) : '', $text) . \PHP_EOL);
257322
}
258323

259-
public function logException(\Throwable $exception): void
324+
public function logException(Throwable $exception): void
260325
{
261326
if (! $this->logErrors()) {
262327
return;
@@ -280,7 +345,7 @@ public function logException(\Throwable $exception): void
280345
} while ($exception = $exception->getPrevious());
281346
}
282347

283-
public function emailException(\Throwable $exception): void
348+
public function emailException(Throwable $exception): void
284349
{
285350
if (! $this->logErrors()) {
286351
return;
@@ -348,16 +413,16 @@ public function emailException(\Throwable $exception): void
348413

349414
try {
350415
$callback($subject, $bodyText);
351-
} catch (\Throwable $e) {
416+
} catch (Throwable $e) {
352417
$this->logException($e);
353418
}
354419
}
355420

356-
private function getExceptionCode(\Throwable $exception): string
421+
private function getExceptionCode(Throwable $exception): string
357422
{
358423
$code = $exception->getCode();
359-
if ($exception instanceof \ErrorException && isset(static::$errors[$code])) {
360-
$code = static::$errors[$code];
424+
if ($exception instanceof ErrorException && isset(self::$errors[$code])) {
425+
$code = self::$errors[$code];
361426
}
362427

363428
return (string) $code;

phpstan.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
includes:
2-
- vendor/phpstan/phpstan/conf/config.levelmax.neon
2+
- phar://phpstan.phar/conf/config.levelmax.neon
33
- vendor/phpstan/phpstan-phpunit/extension.neon
44
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
55
- vendor/slam/phpstan-extensions/conf/thecodingmachine-rules.neon
@@ -15,3 +15,4 @@ parameters:
1515
- '#Variable \$_\w+ in isset\(\) always exists and is not nullable#'
1616
- '#Parameter \#1 \$error_handler of function set_error_handler expects#'
1717
- '#Offset .(no_exception_thrown.*|undefined_index). does not exist on array#'
18+
- '#Expression .+arrayPerVerificaErrori.+ on a separate line does not do anything#'

0 commit comments

Comments
 (0)