Completed
Push — master ( a96ff7...3238f5 )
by Dirk
03:39
created

SomeTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 12
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A increaseCounter() 0 3 1
A getCounter() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
require __DIR__ . '/../vendor/autoload.php';
6
7
use Nexus\StandardListenerProvider;
8
use Nexus\SynchronousProcessor;
9
use Psr\EventDispatcher\TaskInterface;
10
11
class SomeTask implements TaskInterface
12
{
13
    private $accessCounter = 0;
14
15
    public function increaseCounter(): void
16
    {
17
        $this->accessCounter++;
18
    }
19
20
    public function getCounter(): int
21
    {
22
        return $this->accessCounter;
23
    }
24
}
25
26
class SomeOtherTask implements TaskInterface
27
{
28
}
29
30
$provider = new StandardListenerProvider();
31
$processor = new SynchronousProcessor($provider);
32
33
$provider->addListener(function (SomeTask $someTask) {
34
    echo "some task working!\n";
35
    $someTask->increaseCounter();
36
    return $someTask;
37
});
38
$provider->addListener(function (SomeTask $someTask) {
39
    echo "some task working again!\n";
40
    $someTask->increaseCounter();
41
    $someTask->increaseCounter();
42
    return $someTask;
43
});
44
$provider->addListener(function (SomeOtherTask $someOtherTask) {
45
    echo "the other Task!";
46
    return $someOtherTask;
47
});
48
49
$testTask = new SomeTask();
50
$testTaskResult = $processor->process($testTask);
51
52
echo "task result was: {$testTaskResult->getCounter()}\n";
0 ignored issues
show
Bug introduced by
The method getCounter() does not exist on Psr\EventDispatcher\TaskInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Psr\EventDispatcher\StoppableTaskInterface or SomeOtherTask. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
echo "task result was: {$testTaskResult->/** @scrutinizer ignore-call */ getCounter()}\n";
Loading history...
53