Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced PHP 8 support; removed support for PHP 5.6 + 7.0 #383

Merged
merged 11 commits into from
Apr 19, 2021
11 changes: 4 additions & 7 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Install PHPStan"
run: "composer require phpstan/phpstan phpstan/phpstan-phpunit --dev --no-progress --no-suggest"
- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHP CS Fixer"
run: "php vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr"

- name: "Install PHPUnit for PHPStan"
run: "php vendor/bin/simple-phpunit install"
run: "php dev-tools/vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr"

- name: "Run PHPStan"
run: "php vendor/bin/phpstan analyse --no-progress --error-format=checkstyle | cs2pr"
run: "php dev-tools/vendor/bin/phpstan analyse --no-progress --error-format=checkstyle | cs2pr"
45 changes: 20 additions & 25 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ jobs:
name: "PHPUnit (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"

env:
SYMFONY_PHPUNIT_VERSION: 7.5

strategy:
matrix:
php:
- "7.2"
- "7.3"
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand All @@ -40,11 +38,11 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Remove PHP-CS-Fixer"
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHPUnit"
run: "php vendor/bin/simple-phpunit -v"
run: "make run-phpunit"

phpunit-lower-php:
name: "PHPUnit (PHP ${{ matrix.php }})"
Expand All @@ -53,8 +51,6 @@ jobs:
strategy:
matrix:
php:
- "5.6"
- "7.0"
- "7.1"

steps:
Expand All @@ -73,19 +69,16 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Remove PHP-CS-Fixer"
run: "composer remove friendsofphp/php-cs-fixer --dev --no-progress --no-update"
- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHPUnit"
run: "php vendor/bin/simple-phpunit -v"
run: "make run-phpunit"

phpunit-coverage:
name: "PHPUnit coverage (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"

env:
SYMFONY_PHPUNIT_VERSION: 7.5

strategy:
matrix:
php:
Expand All @@ -107,16 +100,16 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Run PHPUnit (with coverage)"
run: "php vendor/bin/simple-phpunit -v --coverage-clover coverage/clover.xml"
- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHPUnit"
run: "php dev-tools/vendor/bin/phpunit -v --coverage-clover coverage/clover.xml"
smalot marked this conversation as resolved.
Show resolved Hide resolved

phpunit-composerv2:
name: "PHPUnit Composer v2 (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"

env:
SYMFONY_PHPUNIT_VERSION: 7.5

strategy:
matrix:
php:
Expand All @@ -138,8 +131,11 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHPUnit"
run: "php vendor/bin/simple-phpunit -v"
run: "make run-phpunit"

alt-autoload:
name: "Tests alternative autoloader (PHP ${{ matrix.php }})"
Expand Down Expand Up @@ -175,10 +171,6 @@ jobs:
name: "PHPUnit lowest deps (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"

env:
SYMFONY_PHPUNIT_VERSION: 7.5
SYMFONY_DEPRECATIONS_HELPER: disabled=1

strategy:
matrix:
php:
Expand All @@ -202,5 +194,8 @@ jobs:
with:
dependency-versions: "lowest"

- name: "Install dev tools"
run: "make install-dev-tools"

- name: "Run PHPUnit"
run: "php vendor/bin/simple-phpunit -v"
run: "make run-phpunit"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/vendor/*
/xdebug/*
/composer.phar
/dev-tools/vendor
/composer
debug*
composer.lock
/.php_cs.cache
/.phpunit.result.cache
40 changes: 40 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Developers

## .editorconfig

Please make sure your editor uses our `.editorconfig` file. It contains rules about our coding styles.

## Development Tools and Tests

Our test related files are located in `tests` folder.
Tests are written using PHPUnit.

To install (and update) development tools like PHPUnit or PHP-CS-Fixer run:

> make install-dev-tools

Development toosl are getting installed in `dev-tools/vendor`.
k00ni marked this conversation as resolved.
Show resolved Hide resolved
Please check `dev-tools/composer.json` for more information about versions etc.
To run a tool manually you use `dev-tools/vendor/bin`, for instance:

> dev-tools/vendor/bin/php-cs-fixer fix --verbose --dry-run

Below are a few shortcuts to improve your developer experience.

### PHPUnit

To run all tests run:

> make run-phpunit

### PHP-CS-Fixer

To check coding styles run:

> make run-php-cs-fixer

### PHPStan

To run a static code analysis use:

> make run-phpstan
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install-dev-tools:
composer update --working-dir=dev-tools

run-php-cs-fixer:
dev-tools/vendor/bin/php-cs-fixer fix

run-phpstan:
dev-tools/vendor/bin/phpstan/phpstan/phpstan analyse

run-phpunit:
dev-tools/vendor/bin/phpunit
smalot marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ As a result, users must expect BC breaks when using the master version.

Original PDF References files can be downloaded from this url: http://www.adobe.com/devnet/pdf/pdf_reference_archive.html

**For developers**: Please read [DEVELOPER.md](DEVELOPER.md) for more information about local development of the PDFParser library.

## Installation

### Using Composer
Expand Down
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
},
"homepage": "https://www.pdfparser.org",
"require": {
"php": ">=5.6",
"php": ">=7.1",
"symfony/polyfill-mbstring": "^1.18",
"ext-zlib": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"symfony/phpunit-bridge": "^5.2"
},
"autoload": {
"psr-0": {
"Smalot\\PdfParser\\": "src/"
Expand Down
9 changes: 9 additions & 0 deletions dev-tools/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"description": "This file provides development-only dependencies.",
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.81",
"phpstan/phpstan-phpunit": "^0.12.18",
"phpunit/phpunit": ">=7.5"
}
}
6 changes: 3 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon
- dev-tools/vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
level: 3
Expand All @@ -9,4 +9,4 @@ parameters:
- tests

bootstrapFiles:
- vendor/bin/.phpunit/phpunit-7.5-0/vendor/autoload.php
- vendor/autoload.php
18 changes: 18 additions & 0 deletions src/Smalot/PdfParser/Element/ElementXRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ public function getObject()
*/
public function equals($value)
{
/**
* In case $value is a number and $this->value is a string like 5_0
*
* Without this if-clause code like:
*
* $element = new ElementXRef('5_0');
* $this->assertTrue($element->equals(5));
*
* would fail (= 5_0 and 5 are not equal in PHP 8.0+).
*/
if (
true === is_numeric($value)
&& true === \is_string($this->getContent())
&& 1 === preg_match('/[0-9]+\_[0-9]+/', $this->getContent(), $matches)
) {
return (float) ($this->getContent()) == $value;
}

Comment on lines +59 to +76
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smalot Do you see any issues with that addition?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me when does this method is called and why we try to validate equality between "5" and "5_0" ?

Copy link
Collaborator Author

@k00ni k00ni Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove this code, assertion in testEquals of ElementXRefTest.php will fail in PHP 8.0.

$id = ($value instanceof self) ? $value->getId() : $value;

return $this->getId() == $id;
Expand Down
Loading