Skip to content

Commit 370b7e9

Browse files
authored
Include PHP 8.5 in CI + Fixes deprecations (#779)
* Include PHP 8.5 in CI * Makefile: added --display-phpunit-deprecations to show deprecations during tests * aligned/optimized CI files; also added --display-deprecations to Windows tests * remove --display-deprecations because it only caused errors in lower PHP versions * addressed 2/3 deprecations * added a fix to solve chr deprecation; deprecation warning was: > chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value must be in the [0, 255] interval. The value used will be constrained using % 256 Also removed --display-deprecations in Windows tests * Fixed the fix (chr) * removed test code * refined chr fix * unified content: php-versions => php
1 parent 98d31ba commit 370b7e9

File tree

6 files changed

+73
-43
lines changed

6 files changed

+73
-43
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@ name: "CI"
22

33
on: [push, pull_request]
44

5-
env:
6-
fail-fast: true
7-
85
jobs:
96
phpunit:
107
name: "PHPUnit (PHP ${{ matrix.php }})"
118
runs-on: ubuntu-latest
129

1310
strategy:
1411
matrix:
15-
php:
16-
- "7.2"
17-
- "7.3"
18-
- "7.4"
19-
- "8.0"
20-
- "8.1"
21-
- "8.2"
22-
- "8.3"
23-
- "8.4"
12+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
2413

2514
steps:
2615
- name: "Checkout"
@@ -50,8 +39,7 @@ jobs:
5039

5140
strategy:
5241
matrix:
53-
php:
54-
- "7.1"
42+
php: ['7.1']
5543

5644
steps:
5745
- name: "Checkout"
@@ -81,8 +69,7 @@ jobs:
8169

8270
strategy:
8371
matrix:
84-
php:
85-
- "7.4"
72+
php: ['7.4']
8673

8774
steps:
8875
- name: "Checkout"
@@ -112,8 +99,7 @@ jobs:
11299

113100
strategy:
114101
matrix:
115-
php:
116-
- "7.4"
102+
php: ['7.4']
117103

118104
steps:
119105
- name: "Checkout"
@@ -143,16 +129,7 @@ jobs:
143129

144130
strategy:
145131
matrix:
146-
php:
147-
- "7.1"
148-
- "7.2"
149-
- "7.3"
150-
- "7.4"
151-
- "8.0"
152-
- "8.1"
153-
- "8.2"
154-
- "8.3"
155-
- "8.4"
132+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
156133

157134
steps:
158135
- name: "Checkout"
@@ -173,9 +150,7 @@ jobs:
173150

174151
strategy:
175152
matrix:
176-
php:
177-
- "7.3"
178-
153+
php: ['7.3']
179154
steps:
180155
- name: "Checkout"
181156
uses: "actions/checkout@v3"
@@ -201,13 +176,13 @@ jobs:
201176
run: "make run-phpunit"
202177

203178
windows-tests:
204-
name: Windows-Tests with PHP ${{ matrix.php-versions }}
179+
name: Windows-Tests with PHP ${{ matrix.php }}
205180
runs-on: windows-latest
206181

207182
strategy:
208-
fail-fast: true
183+
fail-fast: false
209184
matrix:
210-
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
185+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
211186

212187
steps:
213188
- name: Checkout
@@ -216,7 +191,7 @@ jobs:
216191
- name: Install PHP
217192
uses: shivammathur/setup-php@v2
218193
with:
219-
php-version: ${{ matrix.php-versions }}
194+
php-version: ${{ matrix.php }}
220195
ini-values: memory_limit=1G
221196

222197
- name: Install Composer dependencies (root)

.github/workflows/performance.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
php:
20-
- "7.4"
19+
php: ['7.4']
2120

2221
steps:
2322
- name: "Checkout"

phpunit-windows.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
3-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor\autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false" displayDetailsOnTestsThatTriggerWarnings="true">
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor\autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerDeprecations="true">
44
<coverage>
55
<include>
66
<directory>src</directory>

src/Smalot/PdfParser/Document.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,16 @@ public function extractXMPMetadata(string $content): void
299299
$this->metadata = array_merge($this->metadata, $metadata);
300300
}
301301
}
302-
xml_parser_free($xml);
302+
303+
// TODO: remove this if-clause and its content when dropping PHP 7 support
304+
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
305+
// ref: https://www.php.net/manual/en/function.xml-parser-free.php
306+
xml_parser_free($xml);
307+
308+
// to avoid memory leaks; documentation said:
309+
// > it was necessary to also explicitly unset the reference to parser to avoid memory leaks
310+
unset($xml);
311+
}
303312
}
304313

305314
public function getDictionary(): array

src/Smalot/PdfParser/RawData/FilterHelper.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,35 @@ protected function decodeFilterASCII85Decode(string $data): string
190190
// the value represented by a group of 5 characters should never be greater than 2^32 - 1
191191
$tuple += (($char - 33) * $pow85[$group_pos]);
192192
if (4 == $group_pos) {
193-
$decoded .= \chr($tuple >> 24).\chr($tuple >> 16).\chr($tuple >> 8).\chr($tuple);
193+
// The following if-clauses are an attempt to fix/suppress the following deprecation warning:
194+
// chr(): Providing a value not in-between 0 and 255 is deprecated, this is because a byte value
195+
// must be in the [0, 255] interval. The value used will be constrained using % 256
196+
// I know this is ugly and there might be more fancier ways. If you know one, feel free to provide a pull request.
197+
if (255 < $tuple >> 8) {
198+
$chr8Part = \chr(($tuple >> 8) % 256);
199+
} else {
200+
$chr8Part = \chr($tuple >> 8);
201+
}
202+
203+
if (255 < $tuple >> 16) {
204+
$chr16Part = \chr(($tuple >> 16) % 256);
205+
} else {
206+
$chr16Part = \chr($tuple >> 16);
207+
}
208+
209+
if (255 < $tuple >> 24) {
210+
$chr24Part = \chr(($tuple >> 24) % 256);
211+
} else {
212+
$chr24Part = \chr($tuple >> 24);
213+
}
214+
215+
if (255 < $tuple) {
216+
$chrTuple = \chr($tuple % 256);
217+
} else {
218+
$chrTuple = \chr($tuple);
219+
}
220+
221+
$decoded .= $chr24Part . $chr16Part . $chr8Part . $chrTuple;
194222
$tuple = 0;
195223
$group_pos = 0;
196224
} else {

tests/PHPUnit/Integration/PDFObjectTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,14 @@ public function testFormatContent(): void
263263
$expected = str_replace(["\r\n", "\n"], ["\n", "\r\n"], $expected);
264264

265265
$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
266-
$formatContent->setAccessible(true);
266+
267+
// TODO: remove this if-clause when dropping 8.0.x support
268+
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
269+
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
270+
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
271+
$formatContent->setAccessible(true);
272+
}
273+
267274
$cleaned = $formatContent->invoke($this->getPdfObjectInstance(new Document()), $content);
268275

269276
$this->assertEquals($expected, $cleaned);
@@ -303,7 +310,13 @@ public function testFormatContent(): void
303310
public function testFormatContentIssue709()
304311
{
305312
$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
306-
$formatContent->setAccessible(true);
313+
314+
// TODO: remove this if-clause when dropping 8.0.x support
315+
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
316+
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
317+
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
318+
$formatContent->setAccessible(true);
319+
}
307320

308321
$content = '(String \\\\\\(string)Tj '.str_repeat('(Test)Tj ', 4500);
309322
$cleaned = $formatContent->invoke($this->getPdfObjectInstance(new Document()), $content);
@@ -319,7 +332,13 @@ public function testFormatContentIssue709()
319332
public function testFormatContentInlineImages(): void
320333
{
321334
$formatContent = new \ReflectionMethod('Smalot\PdfParser\PDFObject', 'formatContent');
322-
$formatContent->setAccessible(true);
335+
336+
// TODO: remove this if-clause when dropping 8.0.x support
337+
// From documentation > http://php.net/manual/en/reflectionproperty.setaccessible.php:
338+
// As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.
339+
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
340+
$formatContent->setAccessible(true);
341+
}
323342

324343
$cleaned = $formatContent->invoke(
325344
$this->getPdfObjectInstance(new Document()),

0 commit comments

Comments
 (0)