Skip to content

Commit

Permalink
Fixed Psalm & PHPStan issues (#120)
Browse files Browse the repository at this point in the history
* Fixed Psalm issues

* Fixed PHPStan baseline

* Fixes

* Bugfixes
  • Loading branch information
Nyholm authored Sep 19, 2020
1 parent cb78c99 commit 84629c1
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable

- name: Run tests
run: ./vendor/bin/phpunit
run: ./vendor/bin/simple-phpunit

lowest:
name: Lowest deps
Expand All @@ -46,4 +46,4 @@ jobs:
- name: Run tests
env:
SYMFONY_DEPRECATIONS_HELPER: "max[self]=0"
run: ./vendor/bin/phpunit --coverage-text
run: ./vendor/bin/simple-phpunit --coverage-text
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
composer update --no-interaction --prefer-dist --optimize-autoloader
- name: PHPStan
uses: docker://oskarstark/phpstan-ga:0.12.23
uses: docker://oskarstark/phpstan-ga:0.12.25
with:
entrypoint: /composer/vendor/bin/phpstan
args: analyze --no-progress
Expand Down
75 changes: 0 additions & 75 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,82 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^If condition is always true\\.$#"
count: 3
path: src/EachPromise.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$concurrency \\(\\(callable\\(\\)\\: mixed\\)\\|int\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$iterable \\(Iterator\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$onFulfilled \\(callable\\(\\)\\: mixed\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$onRejected \\(callable\\(\\)\\: mixed\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/FulfilledPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 2
path: src/Promise.php

-
message: "#^Method GuzzleHttp\\\\Promise\\\\Promise\\:\\:callHandler\\(\\) should return array but empty return statement found\\.$#"
count: 1
path: src/Promise.php

-
message: "#^Method GuzzleHttp\\\\Promise\\\\Promise\\:\\:callHandler\\(\\) should return array but return statement is missing\\.$#"
count: 1
path: src/Promise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/RejectedPromise.php

-
message: "#^Parameter \\#1 \\$function of function register_shutdown_function expects callable\\(\\)\\: void, Closure\\(\\)\\: mixed given\\.$#"
count: 1
path: src/TaskQueue.php

-
message: "#^Variable \\$task in PHPDoc tag @var does not exist\\.$#"
count: 1
path: src/TaskQueue.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 2
path: src/Utils.php

3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ parameters:
level: 5
paths:
- src

ignoreErrors:
- "#^Dead catch - Exception is already caught by Throwable above\\.$#"
17 changes: 0 additions & 17 deletions psalm.baseline.xml

This file was deleted.

1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm.baseline.xml"
>
<projectFiles>
<directory name="src" />
Expand Down
26 changes: 20 additions & 6 deletions src/EachPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ class EachPromise implements PromisorInterface
{
private $pending = [];

/** @var \Iterator */
/** @var \Iterator|null */
private $iterable;

/** @var callable|int */
/** @var callable|int|null */
private $concurrency;

/** @var callable */
/** @var callable|null */
private $onFulfilled;

/** @var callable */
/** @var callable|null */
private $onRejected;

/** @var Promise */
/** @var Promise|null */
private $aggregate;

/** @var bool */
/** @var bool|null */
private $mutex;

/**
Expand Down Expand Up @@ -66,6 +66,7 @@ public function __construct($iterable, array $config = [])
}
}

/** @psalm-suppress InvalidNullableReturnType */
public function promise()
{
if ($this->aggregate) {
Expand All @@ -74,16 +75,29 @@ public function promise()

try {
$this->createPromise();
/** @psalm-assert Promise $this->aggregate */
$this->iterable->rewind();
if (!$this->checkIfFinished()) {
$this->refillPending();
}
} catch (\Throwable $e) {
/**
* @psalm-suppress NullReference
* @phpstan-ignore-next-line
*/
$this->aggregate->reject($e);
} catch (\Exception $e) {
/**
* @psalm-suppress NullReference
* @phpstan-ignore-next-line
*/
$this->aggregate->reject($e);
}

/**
* @psalm-suppress NullableReturnStatement
* @phpstan-ignore-next-line
*/
return $this->aggregate;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function cancel()
}

// Reject the promise only if it wasn't rejected in a then callback.
/** @psalm-suppress RedundantCondition */
if ($this->state === self::PENDING) {
$this->reject(new CancellationException('Promise has been cancelled'));
}
Expand Down Expand Up @@ -178,8 +179,6 @@ static function ($reason) use ($handlers) {
* @param int $index 1 (resolve) or 2 (reject).
* @param mixed $value Value to pass to the callback.
* @param array $handler Array of handler data (promise and callbacks).
*
* @return array Returns the next group to resolve.
*/
private static function callHandler($index, $value, array $handler)
{
Expand Down Expand Up @@ -227,6 +226,7 @@ private function waitIfPending()

Utils::queue()->run();

/** @psalm-suppress RedundantCondition */
if ($this->state === self::PENDING) {
$this->reject('Invoking the wait callback did not resolve the promise');
}
Expand Down
2 changes: 2 additions & 0 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function wait($unwrap = true, $defaultDelivery = null)
if ($unwrap) {
throw Create::exceptionFor($this->reason);
}

return null;
}

public function getState()
Expand Down
2 changes: 1 addition & 1 deletion src/TaskQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function add(callable $task)

public function run()
{
/** @var callable $task */
while ($task = array_shift($this->queue)) {
/** @var callable $task */
$task();
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ function each_limit(
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
* @param mixed $iterable
* @param int|callable $concurrency
* @param callable $onFulfilled
*
* @return PromiseInterface
*
Expand Down

0 comments on commit 84629c1

Please sign in to comment.