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

adjust to promise template annotations #173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Remove phpspec
run: composer remove --dev friends-of-phpspec/phpspec-code-coverage phpspec/phpspec

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"require": {
"php": "^7.1 || ^8.0",
"php-http/promise": "^1.1",
"php-http/promise": "dev-template-exception as 1.2.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
"php-http/promise": "dev-template-exception as 1.2.2",
"php-http/promise": "^1.2.2",

"psr/http-client": "^1.0",
"psr/http-message": "^1.0 || ^2.0"
},
Expand Down
3 changes: 0 additions & 3 deletions src/Exception/RequestAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ private function setRequest(RequestInterface $request)
$this->request = $request;
}

/**
* {@inheritdoc}
*/
public function getRequest(): RequestInterface
{
return $this->request;
Expand Down
3 changes: 2 additions & 1 deletion src/HttpAsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Sends a PSR-7 Request in an asynchronous way by returning a Promise.
Expand All @@ -17,7 +18,7 @@ interface HttpAsyncClient
*
* Exceptions related to processing the request are available from the returned Promise.
*
* @return Promise resolves a PSR-7 Response or fails with an Http\Client\Exception
* @return Promise<ResponseInterface, Exception> resolves a PSR-7 Response or fails with an Http\Client\Exception
*
* @throws \Exception If processing the request is impossible (eg. bad configuration).
*/
Expand Down
12 changes: 3 additions & 9 deletions src/Promise/HttpFulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Http\Promise\Promise;
use Psr\Http\Message\ResponseInterface;

/**
* @implements Promise<ResponseInterface, Exception>
*/
final class HttpFulfilledPromise implements Promise
{
/**
Expand All @@ -18,9 +21,6 @@
$this->response = $response;
}

/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null === $onFulfilled) {
Expand All @@ -28,26 +28,20 @@
}

try {
return new self($onFulfilled($this->response));

Check failure on line 31 in src/Promise/HttpFulfilledPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpFulfilledPromise::then() should return Http\Promise\Promise<V, Http\Client\Exception> but returns Http\Client\Promise\HttpFulfilledPromise.

Check failure on line 31 in src/Promise/HttpFulfilledPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $response of class Http\Client\Promise\HttpFulfilledPromise constructor expects Psr\Http\Message\ResponseInterface, V given.
} catch (Exception $e) {
return new HttpRejectedPromise($e);

Check failure on line 33 in src/Promise/HttpFulfilledPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpFulfilledPromise::then() should return Http\Promise\Promise<V, Http\Client\Exception> but returns Http\Client\Promise\HttpRejectedPromise.
}
}

/**
* {@inheritdoc}
*/
public function getState()
{
return Promise::FULFILLED;
}

/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
if ($unwrap) {

Check failure on line 44 in src/Promise/HttpFulfilledPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpFulfilledPromise::wait() should return Psr\Http\Message\ResponseInterface|null but return statement is missing.
return $this->response;
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/Promise/HttpRejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

use Http\Client\Exception;
use Http\Promise\Promise;
use Psr\Http\Message\ResponseInterface;

/**
* @implements Promise<ResponseInterface, Exception>
*/
final class HttpRejectedPromise implements Promise
{
/**
Expand All @@ -17,9 +21,6 @@
$this->exception = $exception;
}

/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null === $onRejected) {
Expand All @@ -32,26 +33,20 @@
return $result;
}

return new HttpFulfilledPromise($result);

Check failure on line 36 in src/Promise/HttpRejectedPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpRejectedPromise::then() should return Http\Promise\Promise<V, Http\Client\Exception> but returns Http\Client\Promise\HttpFulfilledPromise.

Check failure on line 36 in src/Promise/HttpRejectedPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $response of class Http\Client\Promise\HttpFulfilledPromise constructor expects Psr\Http\Message\ResponseInterface, V of mixed given.
} catch (Exception $e) {
return new self($e);

Check failure on line 38 in src/Promise/HttpRejectedPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpRejectedPromise::then() should return Http\Promise\Promise<V, Http\Client\Exception> but returns Http\Client\Promise\HttpRejectedPromise.
}
}

/**
* {@inheritdoc}
*/
public function getState()
{
return Promise::REJECTED;
}

/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
if ($unwrap) {

Check failure on line 49 in src/Promise/HttpRejectedPromise.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Http\Client\Promise\HttpRejectedPromise::wait() should return Psr\Http\Message\ResponseInterface|null but return statement is missing.
throw $this->exception;
}
}
Expand Down