Passed
Push — master ( 46260f...cb5e2e )
by Jean Paul
01:23
created

Pipeline::getSteps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
use Iterator;
6
7
/**
8
 * Class Pipeline
9
 * @package Coco\SourceWatcher\Core
10
 */
11
class Pipeline implements Iterator
12
{
13
    /**
14
     * @var Extractor
15
     */
16
    private ?Extractor $extractor = null;
17
18
    /**
19
     * @var array
20
     */
21
    private array $steps = [];
22
23
    /**
24
     * @var array
25
     */
26
    private array $results = [];
27
28
    public function __construct ()
29
    {
30
31
    }
32
33
    /**
34
     * @return Extractor
35
     */
36
    public function getExtractor () : Extractor
37
    {
38
        return $this->extractor;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->extractor could return the type null which is incompatible with the type-hinted return Coco\SourceWatcher\Core\Extractor. Consider adding an additional type-check to rule them out.
Loading history...
39
    }
40
41
    /**
42
     * @param Extractor $extractor
43
     */
44
    public function setExtractor ( Extractor $extractor ) : void
45
    {
46
        $this->extractor = $extractor;
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function getSteps () : array
53
    {
54
        return $this->steps;
55
    }
56
57
    /**
58
     * @param array $steps
59
     */
60
    public function setSteps ( array $steps ) : void
61
    {
62
        $this->steps = $steps;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function getResults () : array
69
    {
70
        return $this->results;
71
    }
72
73
    /**
74
     * @param array $results
75
     */
76
    public function setResults ( array $results ) : void
77
    {
78
        $this->results = $results;
79
    }
80
81
    private int $index = 0;
82
83
    public function current ()
84
    {
85
        return $this->results[$this->index];
86
    }
87
88
    public function next ()
89
    {
90
        $this->index++;
91
    }
92
93
    public function key ()
94
    {
95
        return $this->index;
96
    }
97
98
    public function valid ()
99
    {
100
        return isset( $this->results[$this->key()] );
101
    }
102
103
    public function rewind ()
104
    {
105
        $this->index = 0;
106
    }
107
108
    /**
109
     * @param Step $step
110
     */
111
    public function pipe ( Step $step ) : void
112
    {
113
        $this->steps[] = $step;
114
    }
115
116
    public function execute () : void
117
    {
118
        $this->results = $this->extractor->extract();
0 ignored issues
show
Bug introduced by
The method extract() does not exist on null. ( Ignorable by Annotation )

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

118
        /** @scrutinizer ignore-call */ 
119
        $this->results = $this->extractor->extract();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
120
        foreach ( $this->steps as $currentStep ) {
121
            if ( $currentStep instanceof Transformer ) {
122
                foreach ( $this->results as $currentIndex => $currentItem ) {
123
                    $currentStep->transform( $this->results[$currentIndex] );
124
                }
125
            }
126
127
            if ( $currentStep instanceof Loader ) {
128
                foreach ( $this->results as $currentIndex => $currentItem ) {
129
                    $currentStep->load( $currentItem );
130
                }
131
            }
132
        }
133
    }
134
}
135