Plumber   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A pour() 0 21 5
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow;
5
6
use SlayerBirden\DataFlow\Exception\FlowTerminationException;
7
8
class Plumber
9
{
10
    /**
11
     * @var ProviderInterface
12
     */
13
    private $source;
14
    /**
15
     * @var PipeLineInterface
16
     */
17
    private $pipeLine;
18
    /**
19
     * @var EmitterInterface
20
     */
21
    private $emitter;
22
23 4
    public function __construct(ProviderInterface $source, PipeLineInterface $pipeLine, EmitterInterface $emitter)
24
    {
25 4
        $this->source = $source;
26 4
        $this->pipeLine = $pipeLine;
27 4
        $this->emitter = $emitter;
28 4
    }
29
30
    /**
31
     * Pour source into pipeline.
32
     */
33 4
    public function pour(): void
34
    {
35 4
        $provider = $this->source->getCask();
36 4
        foreach ($provider as $dataBag) {
37 4
            if ($dataBag instanceof \Throwable) {
38
                $this->emitter->emit('provider_error', $dataBag->getMessage());
39
                continue;
40
            }
41
            try {
42 4
                $this->pipeLine->rewind();
43 4
                while ($this->pipeLine->valid()) {
44 4
                    $handler = $this->pipeLine->current();
45 4
                    $dataBag = $handler->pass($dataBag);
46 4
                    $this->pipeLine->next();
47
                }
48 2
            } catch (FlowTerminationException $exception) {
49 4
                $this->emitter->emit('valve_closed', $exception->getIdentifier(), $dataBag);
50
            }
51
        }
52 4
        $this->emitter->emit('empty_cask');
53 4
    }
54
}
55