mirror of
https://github.com/danog/amp.git
synced 2025-01-22 05:11:42 +01:00
Replace leftover LogicExceptions exceptions with Error
This commit is contained in:
parent
496152282e
commit
7bc08b9a6a
@ -148,15 +148,15 @@ class Observer {
|
|||||||
*
|
*
|
||||||
* @return mixed Value emitted from observable.
|
* @return mixed Value emitted from observable.
|
||||||
*
|
*
|
||||||
* @throws \LogicException If the observable has resolved or next() was not called before calling this method.
|
* @throws \Error If the observable has resolved or next() was not called before calling this method.
|
||||||
*/
|
*/
|
||||||
public function getCurrent() {
|
public function getCurrent() {
|
||||||
if (empty($this->values) && $this->resolved) {
|
if (empty($this->values) && $this->resolved) {
|
||||||
throw new \LogicException("The observable has completed");
|
throw new \Error("The observable has completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->values[$this->position])) {
|
if (!isset($this->values[$this->position])) {
|
||||||
throw new \LogicException("Awaitable returned from next() must resolve before calling this method");
|
throw new \Error("Awaitable returned from next() must resolve before calling this method");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->values[$this->position];
|
return $this->values[$this->position];
|
||||||
@ -168,12 +168,12 @@ class Observer {
|
|||||||
*
|
*
|
||||||
* @return mixed Final return value of the observable.
|
* @return mixed Final return value of the observable.
|
||||||
*
|
*
|
||||||
* @throws \LogicException If the observable has not completed.
|
* @throws \Error If the observable has not completed.
|
||||||
* @throws \Throwable The exception used to fail the observable.
|
* @throws \Throwable The exception used to fail the observable.
|
||||||
*/
|
*/
|
||||||
public function getResult() {
|
public function getResult() {
|
||||||
if (!$this->resolved) {
|
if (!$this->resolved) {
|
||||||
throw new \LogicException("The observable has not resolved");
|
throw new \Error("The observable has not resolved");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->exception) {
|
if ($this->exception) {
|
||||||
|
@ -16,13 +16,13 @@ trait Struct {
|
|||||||
private $__propertySuggestThreshold = 70;
|
private $__propertySuggestThreshold = 70;
|
||||||
|
|
||||||
final public function __get($property) {
|
final public function __get($property) {
|
||||||
throw new \DomainException(
|
throw new \Error(
|
||||||
$this->generateStructPropertyError($property)
|
$this->generateStructPropertyError($property)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function __set($property, $value) {
|
final public function __set($property, $value) {
|
||||||
throw new \DomainException(
|
throw new \Error(
|
||||||
$this->generateStructPropertyError($property)
|
$this->generateStructPropertyError($property)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ final class Success implements Awaitable {
|
|||||||
/**
|
/**
|
||||||
* @param mixed $value Anything other than an Awaitable object.
|
* @param mixed $value Anything other than an Awaitable object.
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException If an awaitable is given as the value.
|
* @throws \Error If an awaitable is given as the value.
|
||||||
*/
|
*/
|
||||||
public function __construct($value = null)
|
public function __construct($value = null)
|
||||||
{
|
{
|
||||||
if ($value instanceof Awaitable) {
|
if ($value instanceof Awaitable) {
|
||||||
throw new \InvalidArgumentException("Cannot use an awaitable as success value");
|
throw new \Error("Cannot use an awaitable as success value");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
@ -727,7 +727,7 @@ function some(array $awaitables): Awaitable {
|
|||||||
*
|
*
|
||||||
* @return \Interop\Async\Awaitable
|
* @return \Interop\Async\Awaitable
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException If the array is empty or a non-Awaitable is in the array.
|
* @throws \Error If the array is empty or a non-Awaitable is in the array.
|
||||||
*/
|
*/
|
||||||
function choose(array $awaitables): Awaitable {
|
function choose(array $awaitables): Awaitable {
|
||||||
if (empty($awaitables)) {
|
if (empty($awaitables)) {
|
||||||
@ -966,10 +966,12 @@ function concat(array $observables): Observable {
|
|||||||
* @param int $count Number of values to emit. PHP_INT_MAX by default.
|
* @param int $count Number of values to emit. PHP_INT_MAX by default.
|
||||||
*
|
*
|
||||||
* @return \Amp\Observable
|
* @return \Amp\Observable
|
||||||
|
*
|
||||||
|
* @throws \Error If the number of times to emit is not a positive value.
|
||||||
*/
|
*/
|
||||||
function interval(int $interval, int $count = PHP_INT_MAX): Observable {
|
function interval(int $interval, int $count = PHP_INT_MAX): Observable {
|
||||||
if (0 >= $count) {
|
if (0 >= $count) {
|
||||||
throw new \InvalidArgumentException("The number of times to emit must be a positive value");
|
throw new \Error("The number of times to emit must be a positive value");
|
||||||
}
|
}
|
||||||
|
|
||||||
$postponed = new Postponed;
|
$postponed = new Postponed;
|
||||||
@ -992,14 +994,16 @@ function interval(int $interval, int $count = PHP_INT_MAX): Observable {
|
|||||||
* @param int $step
|
* @param int $step
|
||||||
*
|
*
|
||||||
* @return \Amp\Observable
|
* @return \Amp\Observable
|
||||||
|
*
|
||||||
|
* @throws \Error If the step is 0 or not of the correct sign.
|
||||||
*/
|
*/
|
||||||
function range(int $start, int $end, int $step = 1): Observable {
|
function range(int $start, int $end, int $step = 1): Observable {
|
||||||
if (0 === $step) {
|
if (0 === $step) {
|
||||||
throw new \InvalidArgumentException("Step must be a non-zero integer");
|
throw new \Error("Step must be a non-zero integer");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((($end - $start) ^ $step) < 0) {
|
if ((($end - $start) ^ $step) < 0) {
|
||||||
throw new \InvalidArgumentException("Step is not of the correct sign");
|
throw new \Error("Step is not of the correct sign");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Emitter(function (callable $emit) use ($start, $end, $step) {
|
return new Emitter(function (callable $emit) use ($start, $end, $step) {
|
||||||
|
@ -9,7 +9,7 @@ class StructTestFixture {
|
|||||||
|
|
||||||
class StructTest extends \PHPUnit_Framework_TestCase {
|
class StructTest extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @expectedException \DomainException
|
* @expectedException \Error
|
||||||
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
||||||
*/
|
*/
|
||||||
public function testSetErrorWithSuggestion() {
|
public function testSetErrorWithSuggestion() {
|
||||||
@ -18,7 +18,7 @@ class StructTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \DomainException
|
* @expectedException \Error
|
||||||
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
||||||
*/
|
*/
|
||||||
public function testGetErrorWithSuggestion() {
|
public function testGetErrorWithSuggestion() {
|
||||||
@ -27,7 +27,7 @@ class StructTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \DomainException
|
* @expectedException \Error
|
||||||
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
||||||
*/
|
*/
|
||||||
public function testSetErrorWithoutSuggestion() {
|
public function testSetErrorWithoutSuggestion() {
|
||||||
@ -36,7 +36,7 @@ class StructTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \DomainException
|
* @expectedException \Error
|
||||||
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
||||||
*/
|
*/
|
||||||
public function testGetErrorWithoutSuggestion() {
|
public function testGetErrorWithoutSuggestion() {
|
||||||
@ -45,7 +45,7 @@ class StructTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \DomainException
|
* @expectedException \Error
|
||||||
* @expectedExceptionMessage Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist
|
||||||
*/
|
*/
|
||||||
public function testSuggestionIgnoresPropertyStartingWithUnderscore() {
|
public function testSuggestionIgnoresPropertyStartingWithUnderscore() {
|
||||||
|
@ -8,7 +8,7 @@ use Interop\Async\Loop;
|
|||||||
|
|
||||||
class SuccessTest extends \PHPUnit_Framework_TestCase {
|
class SuccessTest extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @expectedException \LogicException
|
* @expectedException \Error
|
||||||
*/
|
*/
|
||||||
public function testConstructWithNonException() {
|
public function testConstructWithNonException() {
|
||||||
$failure = new Success($this->getMockBuilder(Awaitable::class)->getMock());
|
$failure = new Success($this->getMockBuilder(Awaitable::class)->getMock());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user