Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Jun 24, 2021
1 parent 236c578 commit 6a7bdb5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
22 changes: 9 additions & 13 deletions src/FailedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@

namespace Kiboko\Component\Promise;

use Kiboko\Component\Promise\Resolution\Failure;
use Kiboko\Contract\Promise\DeferredInterface;
use Kiboko\Contract\Promise\PromiseInterface;
use Kiboko\Contract\Promise\Resolution\FailureInterface;
use Kiboko\Contract\Promise\Resolution\ResolutionInterface;
use Kiboko\Contract\Promise as Contract;

/**
* @api
*/
final class FailedPromise implements PromiseInterface
final class FailedPromise implements Contract\PromiseInterface
{
private FailureInterface $resolution;
private Contract\Resolution\FailureInterface $resolution;

public function __construct(\Throwable $exception)
{
$this->resolution = new Failure($exception);
$this->resolution = new Resolution\Failure($exception);
}

public function then(callable $callback): PromiseInterface
public function then(callable $callback): Contract\PromiseInterface
{
return $this;
}

public function failure(callable $callback): PromiseInterface
public function failure(callable $callback): Contract\PromiseInterface
{
$callback($this->resolution->error());
$this->resolution->apply($callback);
return $this;
}

public function defer(): DeferredInterface
public function defer(): Contract\DeferredInterface
{
return new Deferred($this);
}
Expand All @@ -51,7 +47,7 @@ public function isFailure(): bool
return true;
}

public function resolution(): ResolutionInterface
public function resolution(): Contract\Resolution\ResolutionInterface
{
return $this->resolution;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Kiboko\Component\Promise;

use Kiboko\Component\ETL\Promise\Resolution;
use Kiboko\Contract\Promise as Contract;

/**
* @api
*/
final class Promise implements ResolvablePromiseInterface
final class Promise implements Contract\ResolvablePromiseInterface
{
/** @var callable */
private $successCallbacks;
/** @var callable */
private $failureCallbacks;
private Resolution\ResolutionInterface $resolution;
private Contract\Resolution\ResolutionInterface $resolution;

public function __construct()
{
Expand All @@ -22,14 +22,14 @@ public function __construct()
$this->resolution = new Resolution\Pending();
}

public function defer(): DeferredInterface
public function defer(): Contract\DeferredInterface
{
return new Deferred($this);
}

public function then(callable $callback): PromiseInterface
public function then(callable $callback): Contract\PromiseInterface
{
if ($this->resolution instanceof SuccessInterface) {
if ($this->resolution instanceof Contract\Resolution\SuccessInterface) {
$this->resolution->apply($callback);
}

Expand All @@ -38,9 +38,9 @@ public function then(callable $callback): PromiseInterface
return $this;
}

public function failure(callable $callback): PromiseInterface
public function failure(callable $callback): Contract\PromiseInterface
{
if ($this->resolution instanceof FailureInterface) {
if ($this->resolution instanceof Contract\Resolution\FailureInterface) {
$this->resolution->apply($callback);
}

Expand Down Expand Up @@ -88,15 +88,15 @@ public function isResolved(): bool

public function isSuccess(): bool
{
return $this->resolution instanceof Resolution\SuccessInterface;
return $this->resolution instanceof Contract\Resolution\SuccessInterface;
}

public function isFailure(): bool
{
return $this->resolution instanceof Resolution\FailureInterface;
return $this->resolution instanceof Contract\Resolution\FailureInterface;
}

public function resolution(): Resolution\ResolutionInterface
public function resolution(): Contract\Resolution\ResolutionInterface
{
return $this->resolution;
}
Expand Down
20 changes: 8 additions & 12 deletions src/SucceededPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@

namespace Kiboko\Component\Promise;

use Kiboko\Component\Promise\Resolution;
use Kiboko\Contract\Promise\DeferredInterface;
use Kiboko\Contract\Promise\PromiseInterface;
use Kiboko\Contract\Promise\Resolution\ResolutionInterface;
use Kiboko\Contract\Promise\Resolution\SuccessInterface;
use Kiboko\Contract\Promise as Contract;

/**
* @api
*/
final class SucceededPromise implements PromiseInterface
final class SucceededPromise implements Contract\PromiseInterface
{
private SuccessInterface $resolution;
private Contract\Resolution\SuccessInterface $resolution;

public function __construct($value)
{
$this->resolution = new Resolution\Success($value);
}

public function then(callable $callback): PromiseInterface
public function then(callable $callback): Contract\PromiseInterface
{
$callback($this->resolution->value());
$this->resolution->apply($callback);
return $this;
}

public function failure(callable $callback): PromiseInterface
public function failure(callable $callback): Contract\PromiseInterface
{
return $this;
}

public function defer(): DeferredInterface
public function defer(): Contract\DeferredInterface
{
return new Deferred($this);
}
Expand All @@ -51,7 +47,7 @@ public function isFailure(): bool
return false;
}

public function resolution(): ResolutionInterface
public function resolution(): Contract\Resolution\ResolutionInterface
{
return $this->resolution;
}
Expand Down

0 comments on commit 6a7bdb5

Please sign in to comment.