Skip to content

Minor cleanup #162

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 3 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 7 additions & 12 deletions src/Deferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
final class Deferred implements Promise
{
private $value;

Copy link
Contributor

Choose a reason for hiding this comment

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

imho it would make sense to have phpdoc for the types of all fields here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you

private $failure;

private $state;

private $waitCallback;

private $onFulfilledCallbacks;

private $onRejectedCallbacks;

public function __construct(callable $waitCallback)
Expand Down Expand Up @@ -81,12 +76,12 @@ public function getState(): string
*/
public function resolve(ResponseInterface $response): void
{
if (self::PENDING !== $this->state) {
if (Promise::PENDING !== $this->state) {
return;
}

$this->value = $response;
$this->state = self::FULFILLED;
$this->state = Promise::FULFILLED;

foreach ($this->onFulfilledCallbacks as $onFulfilledCallback) {
$onFulfilledCallback($response);
Expand All @@ -98,12 +93,12 @@ public function resolve(ResponseInterface $response): void
*/
public function reject(Exception $exception): void
{
if (self::PENDING !== $this->state) {
if (Promise::PENDING !== $this->state) {
return;
}

$this->failure = $exception;
$this->state = self::REJECTED;
$this->state = Promise::REJECTED;

foreach ($this->onRejectedCallbacks as $onRejectedCallback) {
$onRejectedCallback($exception);
Expand All @@ -115,16 +110,16 @@ public function reject(Exception $exception): void
*/
public function wait($unwrap = true)
{
if (self::PENDING === $this->state) {
if (Promise::PENDING === $this->state) {
$callback = $this->waitCallback;
$callback();
}

if (!$unwrap) {
return;
return null;
}

if (self::FULFILLED === $this->state) {
if (Promise::FULFILLED === $this->state) {
return $this->value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/HttpClientPool/HttpClientPoolItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class HttpClientPoolItem implements HttpClient, HttpAsyncClient
* @param ClientInterface|HttpAsyncClient $client
* @param int|null $reenableAfter Number of seconds until this client is enabled again after an error
*/
public function __construct($client, $reenableAfter = null)
public function __construct($client, int $reenableAfter = null)
{
$this->client = new FlexibleHttpClient($client);
$this->reenableAfter = $reenableAfter;
Expand Down