Pipeline::pipe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WSW\BrowserAutomation\Pipeline;
6
7
use Facebook\WebDriver\WebDriver;
8
use SplObjectStorage;
9
use WSW\BrowserAutomation\Task\TaskInterface;
10
11
/**
12
 * Class Pipeline
13
 *
14
 * @package WSW\BrowserAutomation\Pipeline
15
 */
16
class Pipeline implements PipelineInterface
17
{
18
    /**
19
     * @var SplObjectStorage
20
     */
21
    private $storage;
22
23
    /**
24
     * @var ProcessorInterface
25
     */
26
    private $processor;
27
28
    /**
29
     * Pipeline constructor.
30
     *
31
     * @param ProcessorInterface $processor
32
     */
33 48
    public function __construct(ProcessorInterface $processor = null)
34
    {
35 48
        $this->storage = new SplObjectStorage();
36 48
        $this->processor = $processor ?? new Processor();
37 48
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 12
    public function pipe(TaskInterface $task): PipelineInterface
43
    {
44 12
        $this->storage->attach($task);
45
46 12
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 12
    public function process(WebDriver $driver): array
53
    {
54 12
        $result = [];
55
56 12
        foreach ($this->storage as $task) {
57 9
            $result[] = $this->processor->process($task, $driver);
58
        }
59
60 12
        return $result;
61
    }
62
}
63