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

Add PHP >=8.1 compatibility #75

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

SOHELAHMED7
Copy link

@SOHELAHMED7 SOHELAHMED7 commented Nov 13, 2023

This pull request does the following:

  • fix bugs in library and unit tests (described in PR comments and in Add PHP >=8.1 compatibility #75 (comment))
  • make this library compatible with PHP >= 8.1 (also due to newer PHPUnit, this library will require PHP >= 8.1)
  • upgrade PHPUnit and other dependencies
  • upgrades tests to run with newer PHPUnit
  • upgrades PHP CS Fixer
  • setup GitHub actions to run PHPUnit and PHP CS Fixer

This pull request is endorsed by ☁️ cebe.cloud

@SOHELAHMED7 SOHELAHMED7 marked this pull request as ready for review November 17, 2023 12:01
@SOHELAHMED7 SOHELAHMED7 changed the title WIP - Add PHP 8.2 compatibility Add PHP 8.2 compatibility Nov 17, 2023
Copy link
Contributor

@cebe cebe left a comment

Choose a reason for hiding this comment

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

fix bugs in library

can you explain which bugs have been fixed?
I only saw code style and php compatibility fixes in the review except the place I commented.

@@ -1629,7 +1628,7 @@ private function pipeline()

$operations[] = new CompileHPKP($this->hpkp, $this->hpkpro);

$operations[] = new RemoveCookies(array_keys($this->removedCookies));
$operations[] = new RemoveCookies($this->removedCookies);
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this changed?

Copy link
Author

Choose a reason for hiding this comment

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

This is bug.

@@ -1730,7 +1729,7 @@ private function cspAllow(
$reportOnly = null
) {
Types::assert(
['string' => [$friendlyDirective, $friendlySource]]
['?string' => [$friendlyDirective, $friendlySource]]
Copy link
Author

Choose a reason for hiding this comment

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

This is bug.

@@ -1749,9 +1748,9 @@ private function cspAllow(
*/
private function longDirective($friendlyDirective)
{
Types::assert(['string' => [$friendlyDirective]]);
Types::assert(['?string' => [$friendlyDirective]]);
Copy link
Author

Choose a reason for hiding this comment

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

This is bug.


$friendlyDirective = strtolower($friendlyDirective);
$friendlyDirective = strtolower((string) $friendlyDirective);
Copy link
Author

Choose a reason for hiding this comment

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

This is PHP >= 8.1 compatibility fix.

@@ -1774,9 +1773,9 @@ private function longDirective($friendlyDirective)
*/
private function longSource($friendlySource)
{
Types::assert(['string' => [$friendlySource]]);
Types::assert(['?string' => [$friendlySource]]);
Copy link
Author

Choose a reason for hiding this comment

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

This is bug.


$lowerFriendlySource = strtolower($friendlySource);
$lowerFriendlySource = strtolower((string) $friendlySource);
Copy link
Author

Choose a reason for hiding this comment

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

This is PHP >= 8.1 compatibility fix.

@@ -7,7 +7,7 @@
use Aidantwoods\SecureHeaders\Operations\CompileCSP;
use PHPUnit\Framework\TestCase;

class CSPTest extends TestCase
class CompileCSPTest extends TestCase
Copy link
Author

Choose a reason for hiding this comment

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

This is bug in test. PHPUnit was throwing warning.

'Contains',
'NotContains',
'StringContainsString',
'StringNotContainsString',
Copy link
Author

Choose a reason for hiding this comment

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

This and similar changes is for PHPUnit 10.4.* compatibility

@SOHELAHMED7
Copy link
Author

SOHELAHMED7 commented Nov 17, 2023

I have added comments in PR to identify the bugs. I am giving description here for bug:

  • Class Aidantwoods\SecureHeaders\SecureHeaders:: longDirective() was checking its argument against only string. However it can be null. Because this argument is carry forwarded from the method from which longDirective() is called and there it defaults to null
  • Similar is the case for Aidantwoods\SecureHeaders\SecureHeaders:: longSource()
  • Aidantwoods\SecureHeaders\SecureHeaders:: pipeline() was constructing Aidantwoods\SecureHeaders\Operations\RemoveCookies in wrong way (L1631). It is corrected.

@SOHELAHMED7 SOHELAHMED7 changed the title Add PHP 8.2 compatibility Add PHP >=8.1 compatibility Nov 17, 2023
@franzliedke
Copy link
Contributor

I would strongly suggest to split up the unrelated parts of this PR: compatibility changes, CI changes, and especially bug fixes.

This drastically increases the chances of getting at least parts merged.

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

Successfully merging this pull request may close these issues.

None yet

3 participants