Skip to content

Commit f648729

Browse files
committed
Upgrade to PHP 8.1 and higher.
1 parent 6182dea commit f648729

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

build.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project name="php-affirm" default="build" basedir=".">
3-
<target name="build">
3+
<!-- Run composer update and executes various other updates -->
4+
<target name="update">
5+
<exec executable="composer" checkreturn="true" passthru="true">
6+
<arg value="--ansi"/>
7+
<arg value="update"/>
8+
</exec>
9+
10+
<phing phingfile="build.xml" target="outdated" haltonfailure="true"/>
411
</target>
512

6-
<!-- Run composer update -->
7-
<target name="update">
8-
<exec command="composer update" checkreturn="true" passthru="true"/>
13+
<!-- Show outdated packages -->
14+
<target name="outdated">
15+
<exec executable="composer" checkreturn="false" passthru="true">
16+
<arg value="--ansi"/>
17+
<arg value="outdated"/>
18+
<arg value="--direct"/>
19+
</exec>
920
</target>
1021

1122
<!-- Runs all unit tests -->
1223
<target name="unit">
13-
<exec command="bin/phpunit" passthru="true" checkreturn="true"/>
24+
<exec executable="bin/phpunit" passthru="true" checkreturn="true"/>
1425
</target>
26+
27+
<target name="build" depends="update,unit"/>
1528
</project>

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
],
88
"license": "MIT",
99
"require": {
10-
"php": ">=7.3",
11-
"setbased/exception": "^2.1"
10+
"php": ">=8.1",
11+
"setbased/exception": "^2.3.0"
1212
},
13+
"minimum-stability": "dev",
14+
"prefer-stable": true,
1315
"require-dev": {
14-
"phing/phing": "^2.0",
15-
"phpunit/phpunit": "^9.0"
16+
"phing/phing": "^3.0.0-RC4",
17+
"phpunit/phpunit": "^9.5.28"
1618
},
1719
"autoload": {
1820
"psr-4": {
@@ -25,6 +27,9 @@
2527
}
2628
},
2729
"config": {
28-
"bin-dir": "bin"
30+
"bin-dir": "bin",
31+
"allow-plugins": {
32+
"phing/phing-composer-configurator": true
33+
}
2934
}
3035
}

src/ErrorHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class ErrorHandler
2727
*/
2828
public function handleError(int $errno, string $errstr, ?string $errfile, ?int $errline): bool
2929
{
30-
if (error_reporting()===0)
30+
// See https://www.php.net/manual/en/language.operators.errorcontrol.php for the bitwise or expression.
31+
if (error_reporting()===(E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE))
3132
{
3233
// Error was suppressed with the @-operator. Don't throw an exception.
3334
return false;
@@ -71,7 +72,7 @@ public function handleError(int $errno, string $errstr, ?string $errfile, ?int $
7172
* @param null|int $errorTypes The mask for triggering this error handler. Defaults to E_ALL. Note E_STRICT is part
7273
* of E_ALL since PHP 5.4.0.
7374
*/
74-
public function registerErrorHandler($errorTypes = E_ALL)
75+
public function registerErrorHandler(?int $errorTypes = E_ALL): void
7576
{
7677
ini_set('display_errors', '0');
7778
set_error_handler([$this, 'handleError'], $errorTypes);
@@ -81,7 +82,7 @@ public function registerErrorHandler($errorTypes = E_ALL)
8182
/**
8283
* Unregisters this error handler by restoring the PHP error and exception handlers.
8384
*/
84-
public function unregisterErrorHandler()
85+
public function unregisterErrorHandler(): void
8586
{
8687
restore_error_handler();
8788
}

test/ErrorHandlerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class ErrorHandlerTest extends TestCase
1616
/**
1717
* The error handler.
1818
*
19-
* @var ErrorHandler
19+
* @var ErrorHandler|null
2020
*/
21-
private $errorHandler;
21+
private ?ErrorHandler $errorHandler = null;
2222

2323
//--------------------------------------------------------------------------------------------------------------------
2424
/**
@@ -37,7 +37,7 @@ public function __toString(): string
3737
*
3838
* @param \Exception $exception The exception
3939
*/
40-
public function exceptionHandler($exception)
40+
public function exceptionHandler(\Exception $exception): void
4141
{
4242
self::assertInstanceOf(ErrorException::class, $exception);
4343
}
@@ -68,7 +68,7 @@ public function tearDown(): void
6868
/**
6969
* Errors suppressed with the @-operator must not throw exceptions.
7070
*/
71-
public function testSuppressedError()
71+
public function testSuppressedError(): void
7272
{
7373
$handle = @fopen(__DIR__.'/not-found.txt', 'r');
7474
self::assertFalse($handle);
@@ -78,7 +78,7 @@ public function testSuppressedError()
7878
/**
7979
* Test when __toString fails.
8080
*/
81-
public function testToString1()
81+
public function testToString1(): void
8282
{
8383
$tmp = (string)$this;
8484
self::assertSame('__toString', $tmp);
@@ -88,7 +88,7 @@ public function testToString1()
8888
/**
8989
* Test when __toString fails.
9090
*/
91-
public function testToString2()
91+
public function testToString2(): void
9292
{
9393
set_exception_handler([$this, 'exceptionHandler']);
9494
$tmp = (string)$this;
@@ -97,9 +97,9 @@ public function testToString2()
9797

9898
//--------------------------------------------------------------------------------------------------------------------
9999
/**
100-
* Test E_WARNING when opening a non existing file throws an exception.
100+
* Test E_WARNING when opening a non-existing file throws an exception.
101101
*/
102-
public function testWarning()
102+
public function testWarning(): void
103103
{
104104
$this->expectException(ErrorException::class);
105105
$this->expectExceptionCode(E_WARNING);

0 commit comments

Comments
 (0)