for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace WyriHaximus\React\Parallel;
use parallel\Future;
use React\EventLoop\LoopInterface;
use React\EventLoop\TimerInterface;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
final class FutureToPromiseConverter
{
/** @var LoopInterface */
private $loop;
public function __construct(LoopInterface $loop)
$this->loop = $loop;
}
public function convert(Future $future): PromiseInterface
return new Promise(function ($resolve, $reject) use ($future): void {
/** @var TimerInterface|null $timer */
$timer = $this->loop->addPeriodicTimer(0.001, function () use (&$timer, $future, $resolve, $reject): void {
$timer
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
$myVar = 'Value'; $higher = false; if (rand(1, 6) > 3) { $higher = true; } else { $higher = false; }
Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.
$myVar
$higher
if (!$future->done()) {
return;
if ($timer instanceof TimerInterface) {
$this->loop->cancelTimer($timer);
try {
$resolve($future->value());
} catch (\Throwable $throwable) {
$reject($throwable);
});
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.