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
Merged

Conversation

k00ni
Copy link
Collaborator

@k00ni k00ni commented Jan 1, 2021

Updated 2021-03-10:

  • Introduced PHP 8 support (mostly test related changes)
  • Removed support for PHP 5.6 + 7.0
  • Extended ElementXRef::equals to allow equality checks in PHP 8+, otherwise tests would fail because 5_0 != 5 (see TODOs below)
  • Separated dev-tooling (e.g. PHPUnit) from the library by using a dedicated folder named dev-tools, which contains a separate composer.json file. A detailed explanation why I did that can be found in Introduced PHP 8 support; removed support for PHP 5.6 + 7.0 #383 (comment)

TODOs:

* bumped SYMFONY_PHPUNIT_VERSION from 7.5 to 8.5
* extended ElementXRef::equals allow equals checks in PHP 8+;
  otherwise tests would fail because 5_0 != 5
@k00ni k00ni marked this pull request as draft January 1, 2021 13:54
k00ni added 2 commits January 1, 2021 15:00
because tests failed with errors like

> PHP Fatal error:  Declaration of
Tests\Smalot\PdfParser\Integration\ParserTest::setUp():
Tests\Smalot\PdfParser\Integration\void must be compatible with
Tests\Smalot\PdfParser\TestCase::setUp(): Tests\Smalot\PdfParser\void in
/home/runner/work/pdfparser/pdfparser/tests/Integration/ParserTest.php
on line 279

Ref:
https://github.com/smalot/pdfparser/pull/383/checks?check_run_id=1633732760#step:6:45
@k00ni k00ni marked this pull request as ready for review January 1, 2021 14:03
@k00ni k00ni requested a review from j0k3r January 1, 2021 14:03
@k00ni k00ni changed the title Introduced PHP 8 support; removed support for PHP 5.6 Introduced PHP 8 support; removed support for PHP 5.6 + 7.0 Jan 1, 2021
@k00ni

This comment has been minimized.

Copy link
Collaborator

@j0k3r j0k3r left a comment

Choose a reason for hiding this comment

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

I am not sure about the following addition

If that fix the issue, I'm ok with it.

@k00ni
Copy link
Collaborator Author

k00ni commented Jan 5, 2021

If that fix the issue, I'm ok with it.

It fixes the test for specific parameters, but I am not sure if it covers it 100%. Can you give me a hint what range of parameter values equals has to cover?

@j0k3r
Copy link
Collaborator

j0k3r commented Jan 5, 2021

Can you give me a hint what range of parameter values equals has to cover?

I've no idea...

@k00ni
Copy link
Collaborator Author

k00ni commented Jan 6, 2021

Maybe @Connum?

Reference

@Connum
Copy link
Contributor

Connum commented Jan 6, 2021

Nope, sorry, I have no clue either!

@k00ni
Copy link
Collaborator Author

k00ni commented Jan 12, 2021

We should wait with a merge until further information from #104. Its about a memory leak, but some still use PHP 5.6. I would like to sort it out before we cut off PHP 5.6 + 7.0 support.

@k00ni
Copy link
Collaborator Author

k00ni commented Mar 10, 2021

I learned from semver/semver#468 that dropping support for an supported environment is also considered a breaking change. It means that we would immediately go to 1.0, which is not a bad thing. I wanna try out something before we do that, maybe we can get PHP 8 and keep PHP 5.6/7.0.

@k00ni k00ni self-assigned this Mar 10, 2021
Comment on lines +59 to +76
/**
* 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;
}

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.

k00ni added 3 commits March 10, 2021 12:12
* Removed Simple PHPUnit and PHP-CS-Fixer from composer.json
  * Simple PHPUnit was used to allow us run tests for PHP 5.6-7.4
  * It adds additional complexity and is not needed anymore.
    Thats why I replaced it with PHPUnit itself.
* Created a new folder "dev-tools" with a composer.json.
  that is the new home for PHPUnit, PHPStan and PHP-CS-Fixer
* Simplified workflows a little bit by using Makefile commands
  sometimes.
* Added Makefile to make it easier for developers to run tests
  or other tools.
* Added DEVELOPER.md which contains information about the
  dev-tools we use.
* Added PHPStan to dev-tools, because it is used in a workflow

Reasons for removing tools from root composer.json:
* PHPUnit and PHP-CS-Fixer should not be a dependency for the
  library, because they are only relevant for development.
  (e.g. https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation)
* Moving them to a separate space makes our tooling easier,
  e.g. in our CI workflow we had to remove PHP-CS-Fixer to allow
  a run without problems
* PHPStan was already used separately which supports my decision
  to move the rest too.
* Dev-Tools like PHPUnit have their own requirements and we
  had problems in the past, which required additional work.
  For instance in PHPUnit 8: they added return type void to a
  few methods like setUp, which forced us to decide if we keep
  PHP 5.6 or we are stuck on PHPUnit 7.5 and can't use PHP 8.
  Source: https://phpunit.de/announcements/phpunit-8.html
* IMHO having dev tools in a separate place at least reduces the
  danger that a tool affects the library.
Copy link
Collaborator

@j0k3r j0k3r left a comment

Choose a reason for hiding this comment

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

What the benefit of moving dev tools deps in a dedicated folder?

DEVELOPER.md Outdated Show resolved Hide resolved
Co-authored-by: Jérémy Benoist <[email protected]>
@k00ni
Copy link
Collaborator Author

k00ni commented Mar 10, 2021

I am sorry I wanted to add the reasons right away, but was interrupted. Here is a copy of my commit message:

* Removed Simple PHPUnit and PHP-CS-Fixer from composer.json
  * Simple PHPUnit was used to allow us run tests for PHP 5.6-7.4
  * It adds additional complexity and is not needed anymore.
    Thats why I replaced it with PHPUnit itself.
* Created a new folder "dev-tools" with a composer.json.
  that is the new home for PHPUnit, PHPStan and PHP-CS-Fixer
* Simplified workflows a little bit by using Makefile commands
  sometimes.
* Added Makefile to make it easier for developers to run tests
  or other tools.
* Added DEVELOPER.md which contains information about the
  dev-tools we use.
* Added PHPStan to dev-tools, because it is used in a workflow

Reasons for removing tools from root composer.json:
* PHPUnit and PHP-CS-Fixer should not be a dependency for the
  library, because they are only relevant for development.
  (e.g. https://github.com/FriendsOfPHP/PHP-CS-Fixer#installation)
* Moving them to a separate space makes our tooling easier,
  e.g. in our CI workflow we had to remove PHP-CS-Fixer to allow
  a run without problems
* PHPStan was already used separately which supports my decision
  to move the rest too.
* Dev-Tools like PHPUnit have their own requirements and we
  had problems in the past, which required additional work.
  For instance in PHPUnit 8: they added return type void to a
  few methods like setUp, which forced us to decide if we keep
  PHP 5.6 or we are stuck on PHPUnit 7.5 and can't use PHP 8.
  Source: https://phpunit.de/announcements/phpunit-8.html
* IMHO having dev tools in a separate place at least reduces the
  danger that a tool affects the library.

@k00ni k00ni linked an issue Mar 10, 2021 that may be closed by this pull request
2 tasks
@k00ni
Copy link
Collaborator Author

k00ni commented Mar 10, 2021

Updated my initial post with a few TODOs.

Semantic Versioning is not clear what happened if a supported environment (in this case PHP 5.6 + 7.0) is dropped. I found a few issues discussing this, like semver/semver#526 (comment).

I would follow the argument and create a new major version (= 1.0.0). 0.18.2 would be the last 0.x version.

@k00ni k00ni requested a review from smalot March 10, 2021 12:31
it used outdated PHPUnit command
@smalot
Copy link
Owner

smalot commented Mar 10, 2021

Hi @k00ni
I agree with you to create a new major release "1.x" and to keep old release under the "0.x".
It seems to be the way to reduce any risk of BC Break for current users.

Copy link
Owner

@smalot smalot left a comment

Choose a reason for hiding this comment

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

I need to understand why ElementXRef contains this fix

Comment on lines +59 to +76
/**
* 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;
}

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" ?

.github/workflows/continuous-integration.yml Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@smalot
Copy link
Owner

smalot commented Mar 11, 2021

Thanks @k00ni, everything seems to be good for me

@k00ni
Copy link
Collaborator Author

k00ni commented Mar 11, 2021

@smalot Just to be sure we didn't forget something. What about https://github.com/smalot/pdfparser/pull/383/files/f595ac26308b167c3a02c3a6a77abd653c47b61e#r592171760 (my addition to ElementXRef.php)?

@k00ni
Copy link
Collaborator Author

k00ni commented Mar 12, 2021

We may merge #401 and #402 before this so that older installations can used latest feature.

@k00ni
Copy link
Collaborator Author

k00ni commented Apr 13, 2021

Because there is no activity/progress in referenced issues I am inclined to merge this PR and prepare a major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Poll: Is this library ready for 1.0?
4 participants