Skip to content

Commit

Permalink
CI: added PHP 8.4 (#723)
Browse files Browse the repository at this point in the history
* continuous-integration.yml: added PHP 8.4 to the list

* extended phpunit.xml's to show hidden warning during tests

* fixed warnings in Font.php

Warnings were:

1) /var/www/html/src/Smalot/PdfParser/Font.php:292
range(): Argument #1 ($start) must not be empty, casted to 0

Triggered by:

* PHPUnitTests\Integration\FontTest::testCalculateTextWidthNoWidthsKey
  /var/www/html/tests/PHPUnit/Integration/FontTest.php:473

2) /var/www/html/src/Smalot/PdfParser/Font.php:292
range(): Argument #2 ($end) must not be empty, casted to 0

Triggered by:

* PHPUnitTests\Integration\FontTest::testCalculateTextWidthNoWidthsKey
  /var/www/html/tests/PHPUnit/Integration/FontTest.php:473

* fixed 3 CS issues

* PDFObject: fixed introduced syntax errors in older PHP versions; refined comment in Font.php
  • Loading branch information
k00ni authored Oct 24, 2024
1 parent 15da82a commit f8ae4b4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -151,6 +152,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -205,7 +207,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion phpunit-windows.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<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">
<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">
<coverage>
<include>
<directory>src</directory>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<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">
<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">
<coverage>
<include>
<directory>src</directory>
Expand Down
9 changes: 7 additions & 2 deletions src/Smalot/PdfParser/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,13 @@ public function calculateTextWidth(string $text, ?array &$missing = null): ?floa
// Usually, Widths key is set in $details array, but if it isn't use an empty array instead.
$widths = $details['Widths'] ?? [];

// Widths array is zero indexed but table is not. We must map them based on FirstChar and LastChar
$width_map = array_flip(range($details['FirstChar'], $details['LastChar']));
/*
* Widths array is zero indexed but table is not. We must map them based on FirstChar and LastChar
*
* Note: Without the change you would see warnings in PHP 8.4 because the values of FirstChar or LastChar
* can be null sometimes.
*/
$width_map = array_flip(range((int) $details['FirstChar'], (int) $details['LastChar']));

$width = null;
$missing = [];
Expand Down

0 comments on commit f8ae4b4

Please sign in to comment.