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

PHP 8 Support #39

Merged
merged 2 commits into from
Jan 22, 2021
Merged

PHP 8 Support #39

merged 2 commits into from
Jan 22, 2021

Conversation

canvural
Copy link
Contributor

@canvural canvural commented Nov 1, 2020

This PR:

  • Updates dependencies to support PHP 8
  • Fixes code styles and PHPStan errors

{
return new static($name, $value);
return new self($name, $value);

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

{
return new static(Cookie::listFromCookieString($string));
return new self(Cookie::listFromCookieString($string));

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.


/** @var Cookie $cookie */
$cookie = new static($cookieName);
$cookie = new self($cookieName);

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

Choose a reason for hiding this comment

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

this one isn't reverted yet

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, can this one get updated, too?

{
return new static($name, $value);
return new self($name, $value);

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.


/** @var SetCookie $setCookie */
$setCookie = new static($cookieName);
$setCookie = new self($cookieName);

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

Choose a reason for hiding this comment

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

this one isn't reverted yet

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, can this one get updated, too?

{
return new static(array_map(function (string $setCookieString) : SetCookie {
return new self(array_map(static function (string $setCookieString): SetCookie {

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

{
return new static(array_map(function (string $setCookieString) : SetCookie {
return new self(array_map(static function (string $setCookieString): SetCookie {

Choose a reason for hiding this comment

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

class is not final, means this is a behavior change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

@canvural
Copy link
Contributor Author

@dominikzogg Is there something else that needs to be done here? Can we merge this?

Copy link

@dominikzogg dominikzogg left a comment

Choose a reason for hiding this comment

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

@canvural i am only a user like you are, but i tried to help @simensen to review this PR.


/** @var Cookie $cookie */
$cookie = new static($cookieName);
$cookie = new self($cookieName);

Choose a reason for hiding this comment

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

this one isn't reverted yet

{
$cookieString = implode('; ', $this->cookies);

$request = $request->withHeader(static::COOKIE_HEADER, $cookieString);
$request = $request->withHeader(self::COOKIE_HEADER, $cookieString);

Choose a reason for hiding this comment

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

changes are low (http spec), but also this constant could be overridden

Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

Choose a reason for hiding this comment

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

static:: means it will take the called class, while self:: will take the class the self:: is done in the class that does the self:: call:

https://3v4l.org/soaZR

{
$cookieString = $request->getHeaderLine(static::COOKIE_HEADER);
$cookieString = $request->getHeaderLine(self::COOKIE_HEADER);

Choose a reason for hiding this comment

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

changes are low (http spec), but also this constant could be overridden

Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

{
return new self(self::STRICT);
return new static(self::STRICT);

Choose a reason for hiding this comment

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

it's a final class, static is useless here

Copy link
Member

Choose a reason for hiding this comment

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

But is it wrong?

{
return new self(self::LAX);
return new static(self::LAX);

Choose a reason for hiding this comment

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

it's a final class, static is useless here

Copy link
Member

Choose a reason for hiding this comment

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

But is it wrong?

return SetCookie::fromSetCookieString($setCookieString);
}, $response->getHeader(static::SET_COOKIE_HEADER)));
}, $response->getHeader(self::SET_COOKIE_HEADER)));

Choose a reason for hiding this comment

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

changes are low (http spec), but also this constant could be overridden

Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

$request = $this->prophesize(static::INTERFACE_PSR_HTTP_MESSAGE_REQUEST);
$request->getHeaderLine(Cookies::COOKIE_HEADER)->willReturn($cookieString);
/** @var RequestInterface|MockObject $request */
$request = $this->createMock(self::INTERFACE_PSR_HTTP_MESSAGE_REQUEST);

Choose a reason for hiding this comment

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

prophecy is still usable, by loading a trait

Choose a reason for hiding this comment

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

i have no idea if @simensen wants to keep prophecy

Copy link
Member

Choose a reason for hiding this comment

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

I don't care about Prophecy. I think this was maybe added by @Ocramius at some point?

@@ -210,7 +207,7 @@ public function provideCookieStringAndExpectedCookiesData() : array
}

/** @return string[][]|Cookie[][] */
public function provideGetsCookieByNameData()
public function provideGetsCookieByNameData(): array

Choose a reason for hiding this comment

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

test is not final could be overridden (i would take the risk of a BC here)

@@ -57,7 +59,7 @@ public function withAddedHeader($name, $value)
/** {@inheritDoc} */
public function withoutHeader($name)
{
$clone = clone($this);
$clone = clone$this;

Choose a reason for hiding this comment

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

Suggested change
$clone = clone$this;
$clone = clone $this;

Copy link
Member

Choose a reason for hiding this comment

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

Let's get this change added to the PR.

/** @var ResponseInterface|ObjectProphecy $response */
$response = $this->prophesize(static::INTERFACE_PSR_HTTP_MESSAGE_RESPONSE);
$response->getHeader(SetCookies::SET_COOKIE_HEADER)->willReturn($setCookieStrings);
/** @var ResponseInterface|MockObject $response */

Choose a reason for hiding this comment

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

prophecy is still usable, by loading a trait

Choose a reason for hiding this comment

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

i have no idea if @simensen wants to keep prophecy

Copy link
Member

Choose a reason for hiding this comment

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

Happy to drop it if it's easier at this point.

@simensen
Copy link
Member

@dominikzogg How are we doing on this one? My bad for not catching this earlier. @Ocramius, are you able to take a look at this? I think your big changes were some of the last things to go in here.

@simensen simensen mentioned this pull request Nov 30, 2020
@dominikzogg
Copy link

@simensen i get aware about this PR, cause i like to create an issue about the lack of PHP 8 support. In my opinion its PR is much larger than it needs to be, but its not my repository, so i only mentioned the things that i believe are critical like (self vs static changes).

Copy link
Member

@simensen simensen left a comment

Choose a reason for hiding this comment

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

This looks good. Agreed it is maybe larger than needed (especially the style changes) but none of them look altogether bad. Would love to get sign off from @Ocramius, though, as he did a lot of work on this recently.


/** @var Cookie $cookie */
$cookie = new static($cookieName);
$cookie = new self($cookieName);
Copy link
Member

Choose a reason for hiding this comment

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

Indeed, can this one get updated, too?

{
$cookieString = implode('; ', $this->cookies);

$request = $request->withHeader(static::COOKIE_HEADER, $cookieString);
$request = $request->withHeader(self::COOKIE_HEADER, $cookieString);
Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

{
$cookieString = $request->getHeaderLine(static::COOKIE_HEADER);
$cookieString = $request->getHeaderLine(self::COOKIE_HEADER);
Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

{
return new self(self::STRICT);
return new static(self::STRICT);
Copy link
Member

Choose a reason for hiding this comment

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

But is it wrong?

{
return new self(self::LAX);
return new static(self::LAX);
Copy link
Member

Choose a reason for hiding this comment

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

But is it wrong?

foreach ($this->setCookies as $setCookie) {
$response = $response->withAddedHeader(static::SET_COOKIE_HEADER, (string) $setCookie);
$response = $response->withAddedHeader(self::SET_COOKIE_HEADER, (string) $setCookie);
Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

return SetCookie::fromSetCookieString($setCookieString);
}, $response->getHeader(static::SET_COOKIE_HEADER)));
}, $response->getHeader(self::SET_COOKIE_HEADER)));
Copy link
Member

Choose a reason for hiding this comment

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

I think I've completely underestimated the static:: vs self:: implications in a few places... Is doing static:: bad here for some reason?

$request = $this->prophesize(static::INTERFACE_PSR_HTTP_MESSAGE_REQUEST);
$request->getHeaderLine(Cookies::COOKIE_HEADER)->willReturn($cookieString);
/** @var RequestInterface|MockObject $request */
$request = $this->createMock(self::INTERFACE_PSR_HTTP_MESSAGE_REQUEST);
Copy link
Member

Choose a reason for hiding this comment

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

I don't care about Prophecy. I think this was maybe added by @Ocramius at some point?

@@ -57,7 +59,7 @@ public function withAddedHeader($name, $value)
/** {@inheritDoc} */
public function withoutHeader($name)
{
$clone = clone($this);
$clone = clone$this;
Copy link
Member

Choose a reason for hiding this comment

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

Let's get this change added to the PR.

/** @var ResponseInterface|ObjectProphecy $response */
$response = $this->prophesize(static::INTERFACE_PSR_HTTP_MESSAGE_RESPONSE);
$response->getHeader(SetCookies::SET_COOKIE_HEADER)->willReturn($setCookieStrings);
/** @var ResponseInterface|MockObject $response */
Copy link
Member

Choose a reason for hiding this comment

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

Happy to drop it if it's easier at this point.

@simensen
Copy link
Member

@canvural are you up for making the requested changes? :) If not, I can see if I can take over.

@canvural
Copy link
Contributor Author

I can fix it, but Wednesday earliest.

Style changes are because of doctrine/coding-standard 8.0 So it's normal I'd say.

static to self changes are because of PHPStan. Basically, it warns us that if the user extends the class and does something unexpected our code here will not work as expected. Cause static:class will refer to the extended class, not our class. One way to fix it making the class or constructors final or changing it to self::class So, it's up to you to decide. I can revert the changes and ignore those error in PHPStan.

@simensen
Copy link
Member

@canvural Awesome, thanks.

Indeed, it makes sense re: the style changes. :) However, it might have been possible to not upgrade that dependency so far just yet. I'm happy with it as-is, to be clear. It does make it harder to review the PR, tho.

Re static/self, I think if you can revert just the few that @dominikzogg called out if that works. If PHPStan gives errors, we can look into it more. The solution might need to be to make __construct final but I'll need to think about that.

Thanks again for your help!

@dominikzogg
Copy link

dominikzogg commented Nov 30, 2020

self:
against final classes
against final methods / constants

static:
against the rest (if you want extend ability)

Change from static to self is a BC, except it matches already the self:

@acelaya acelaya mentioned this pull request Nov 30, 2020
28 tasks
Copy link

@waghanza waghanza left a comment

Choose a reason for hiding this comment

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

I think PHP 8 should be added to CI's matrix (I can mot do it myself right now)

@@ -20,10 +20,12 @@
}
},
"require-dev": {
"phpunit/phpunit": "^7.2.6",
"phpunit/phpunit": "^7.2.6 || ^9",

Choose a reason for hiding this comment

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

The minimum php version of this lib is php 7.2, so the minimum vesion of phpunit could be 8, as that still supports php 7.2

{
$cookieString = implode('; ', $this->cookies);

$request = $request->withHeader(static::COOKIE_HEADER, $cookieString);
$request = $request->withHeader(self::COOKIE_HEADER, $cookieString);

Choose a reason for hiding this comment

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

static:: means it will take the called class, while self:: will take the class the self:: is done in the class that does the self:: call:

https://3v4l.org/soaZR

{
if ($expires === null) {
return 0;
}

if ($expires instanceof DateTimeInterface) {
return $expires->getTimestamp();
return (int) $expires->getTimestamp();

Choose a reason for hiding this comment

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

Before php 8, this method could return false on failure.

@hugochinchilla
Copy link

Hi, this is the last dependency preventing my project from runnin on php 8.0, can I do something to help get this ready? should I fork the pull-request and complete the pending changes?

simensen added a commit that referenced this pull request Jan 22, 2021
Extending and finalizing #39
@simensen simensen merged commit 60675f7 into dflydev:master Jan 22, 2021
@simensen simensen mentioned this pull request Jan 22, 2021
@hugochinchilla
Copy link

Thank you!

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.

6 participants