SynchronousManager::tick()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3
1
<?php
2
3
namespace AsyncPHP\Doorman\Manager;
4
5
use AsyncPHP\Doorman\Handler;
6
use AsyncPHP\Doorman\Manager;
7
use AsyncPHP\Doorman\Task;
8
9
final class SynchronousManager implements Manager
10
{
11
    /**
12
     * @var Task[]
13
     */
14
    private $waiting = [];
15
16
    /**
17
     * @inheritdoc
18
     *
19
     * @param Task $task
20
     *
21
     * @return $this
22
     */
23 1
    public function addTask(Task $task)
24
    {
25 1
        $this->waiting[] = $task;
26
27 1
        return $this;
28
    }
29
30
    /**
31
     * @inheritdoc
32
     *
33
     * @return bool
34
     */
35 1
    public function tick()
36
    {
37 1
        foreach ($this->waiting as $task) {
38 1
            $handler = $task->getHandler();
39
40 1
            $object = new $handler();
41
42 1
            if ($object instanceof Handler) {
43 1
                $object->handle($task);
44 1
            }
45 1
        }
46
47 1
        return false;
48
    }
49
}
50