Skip to content

Commit bc946ec

Browse files
committed
addressed 2/3 deprecations
1 parent 77cd00b commit bc946ec

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ 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+
$decoded .= \chr($tuple >> 24)
194+
.\chr($tuple >> 16)
195+
.\chr($tuple >> 8)
196+
.\chr($tuple);
194197
$tuple = 0;
195198
$group_pos = 0;
196199
} 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)