Skip to content

[2.0] Add types #117

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

Merged
merged 15 commits into from
Nov 22, 2018
Merged

[2.0] Add types #117

merged 15 commits into from
Nov 22, 2018

Conversation

Jean85
Copy link
Contributor

@Jean85 Jean85 commented Nov 19, 2018

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Related tickets partially #115
License MIT

What's in this PR?

Another PR toward 2.0

Why?

Because PHP 7.0 is now the required minimum.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (not needed?)

To Do

  • Should I add : Promise where possible or it may interfere on how the promises works?

@sagikazarmark sagikazarmark added this to the v2.0.0 milestone Nov 19, 2018
@sagikazarmark
Copy link
Member

I think we can also drop docblocks where the type is obvious from the hint.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 19, 2018

Maybe we can do it with PHPCSFixer and the no_superfluous_phpdoc_tags + no_empty_phpdoc rules?

@sagikazarmark
Copy link
Member

Sounds like a good idea.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 19, 2018

@sagikazarmark PHPCSFixer is not installed, and we have StyleCI... How should I proceed? Do we want to maintain StileCI? Or should we use PHPCSFixer all the way and add a separate job/stage on Travis?

I should open a separate PR for sure...

For now I've fixed the CS of this PR alone, for StyleCI.

@sagikazarmark
Copy link
Member

We are working towards pretty ci which relies on phpcsfixer config, so you are free to ignore styleci and use PHPCS fixer only.

@dbu
Copy link
Contributor

dbu commented Nov 20, 2018

lets for now accept what styleci proposes and fix things when we switch to php-cs-fixer with prettyci. there should be no behaviour change whatsoever for style things, so its not critical.

there is an error with a stub in the tests. can you fix that?

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 20, 2018

I've fixed the stub and a few other things in 2a80705. I also took the liberty of adding the specs to the dev autoloader (236a8ea) and migrated to ::class (e87785c).

@Jean85 Jean85 mentioned this pull request Nov 20, 2018
1 task
@Jean85
Copy link
Contributor Author

Jean85 commented Nov 20, 2018

After #120 this has a lot of conflicts. Fixing now...

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 20, 2018

I've fixed all the conflicts. I wanted to add : Promise to the Plugin interface but a lot of tests will fail 😢

@dbu
Copy link
Contributor

dbu commented Nov 21, 2018

looks good to me.

i was wondering if we need a changelog entry, but i think we should make all those clients final classes and then the type declarations are no relevant change anymore. is there any classes in this PR that we explicitly should not declare final?

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 21, 2018

I don't know, you or @sagikazarmark should decide on that. I'll try lo list here all the impacted classes (checks will be used to mark classes made final):

  • BatchClient: got sendRequest(...): ResponseInterface from PSR-18 and sendRequests(...): BatchResult
  • BatchResult
  • Deferred
  • HttpClientPool, but it's abstract
  • LeastUsedClientPool, extends HttpClientPool
  • RoundRobinClientPool, extends HttpClientPool
  • HttpMethodsClient
  • PluginClient
  • PluginClientFactory

Also, nearly all plugins are impacted, but I want to give another go to adding : Promise to the Plugin interface.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 21, 2018

I fixed nearly all specs, but I'm not able to fix it for the CookiePlugin. It seems to me that the callbacks used as mock are not working properly:

public function it_does_not_load_cookie_if_expired(RequestInterface $request, UriInterface $uri, Promise $promise)
{
    $cookie = new Cookie('name', 'value', null, 'test.com', false, false, null, (new \DateTime())->modify('-1 day'));
    $this->cookieJar->addCookie($cookie);

    $request->withAddedHeader('Cookie', 'name=value')->shouldNotBeCalled();

    $this->handleRequest($request, function (RequestInterface $requestReceived) use ($request, $promise) {
        if (Argument::is($requestReceived)->scoreArgument($request->getWrappedObject())) {
            return $promise->getWrappedObject();
        }
    }, function () {});
}

The error is:

---- broken examples

    Http/Client/Common/Plugin/CookiePlugin

79 ! does not load cookie if expired
exception [err:TypeError("Return value of Http\Client\Common\Plugin\CookiePlugin::handleRequest() must implement interface Http\Promise\Promise, null returned")] has been thrown.

Anyone can help me here?

@dbu
Copy link
Contributor

dbu commented Nov 21, 2018

lets do the final in a separate pull request. i only brought it up here because if we make the classes final we don't need a changelog.

@dbu
Copy link
Contributor

dbu commented Nov 21, 2018

see also #20 => can you please add a changelog for the abstract class?

@sagikazarmark is our expert in phpspec, maybe he can help with the error?

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 21, 2018

@dbu changelog updated. I'll wait for help on the CookiePlugin specs 👍

@sagikazarmark
Copy link
Member

I feel like being summoned. 😄

Lemme check...

@sagikazarmark
Copy link
Member

It's one of my biggest regret that I didn't pay more attention to tests in this repo. We abused spec testing quite a bit....

Anyway, you could try using this line in the breaking examples:

$this->handleRequest($request, PluginStub::next(), function () {});

We don't really care about the returned promise in those cases.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 21, 2018

It seems to work, great! Thanks!

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

looks good to me!

lets merge?

Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

Thanks @Jean85 , outstanding!

@sagikazarmark sagikazarmark merged commit 543b2a2 into php-http:2.x Nov 22, 2018
@Jean85 Jean85 deleted the add-types branch November 22, 2018 12:18
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.

3 participants