Passed
Push — master ( 0603fe...79dd6e )
by Jean Paul
01:20
created

SourceWatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
use Coco\SourceWatcher\Core\IO\Inputs\Input;
6
use Coco\SourceWatcher\Core\IO\Outputs\Output;
7
8
/**
9
 * Class SourceWatcher
10
 * @package Coco\SourceWatcher\Core
11
 */
12
class SourceWatcher
13
{
14
    /**
15
     * @var StepLoader
16
     */
17
    private StepLoader $stepLoader;
18
19
    /**
20
     * @var Pipeline
21
     */
22
    private Pipeline $pipeline;
23
24
    /**
25
     * SourceWatcher constructor.
26
     */
27
    public function __construct ()
28
    {
29
        $this->stepLoader = new StepLoader();
30
        $this->pipeline = new Pipeline();
31
    }
32
33
    /**
34
     * @return StepLoader
35
     */
36
    public function getStepLoader () : StepLoader
37
    {
38
        return $this->stepLoader;
39
    }
40
41
    /**
42
     * @return Pipeline
43
     */
44
    public function getPipeline () : Pipeline
45
    {
46
        return $this->pipeline;
47
    }
48
49
    /**
50
     * @param string $extractorName
51
     * @param Input $input
52
     * @param array $options
53
     * @return $this
54
     * @throws SourceWatcherException
55
     */
56
    public function extract ( string $extractorName, Input $input, array $options = [] ) : SourceWatcher
57
    {
58
        $extractor = $this->stepLoader->getStep( Extractor::class, $extractorName );
59
60
        if ( $extractor == null ) {
61
            throw new SourceWatcherException( sprintf( "The extractor %s can't be found.", $extractorName ) );
62
        }
63
64
        $extractor->setInput( $input );
0 ignored issues
show
Bug introduced by
The method setInput() does not exist on Coco\SourceWatcher\Core\Step. It seems like you code against a sub-type of Coco\SourceWatcher\Core\Step such as Coco\SourceWatcher\Core\Extractor. ( Ignorable by Annotation )

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

64
        $extractor->/** @scrutinizer ignore-call */ 
65
                    setInput( $input );
Loading history...
65
        $extractor->options( $options );
66
67
        $this->pipeline->setExtractor( $extractor );
68
69
        return $this;
70
    }
71
72
    /**
73
     * @param string $transformerName
74
     * @param array $options
75
     * @return $this
76
     * @throws SourceWatcherException
77
     */
78
    public function transform ( string $transformerName, array $options = [] ) : SourceWatcher
79
    {
80
        $transformer = $this->stepLoader->getStep( Transformer::class, $transformerName );
81
82
        if ( $transformer == null ) {
83
            throw new SourceWatcherException( sprintf( "The transformer %s can't be found.", $transformerName ) );
84
        }
85
86
        $transformer->options( $options );
87
88
        $this->pipeline->pipe( $transformer );
89
90
        return $this;
91
    }
92
93
    /**
94
     * @param string $loaderName
95
     * @param Output $output
96
     * @param array $options
97
     * @return $this
98
     * @throws SourceWatcherException
99
     */
100
    public function load ( string $loaderName, Output $output, array $options = [] ) : SourceWatcher
101
    {
102
        $loader = $this->stepLoader->getStep( Loader::class, $loaderName );
103
104
        if ( $loader == null ) {
105
            throw new SourceWatcherException( sprintf( "The loader %s can't be found.", $loaderName ) );
106
        }
107
108
        $loader->setOutput( $output );
0 ignored issues
show
Bug introduced by
The method setOutput() does not exist on Coco\SourceWatcher\Core\Step. It seems like you code against a sub-type of Coco\SourceWatcher\Core\Step such as Coco\SourceWatcher\Core\Loader. ( Ignorable by Annotation )

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

108
        $loader->/** @scrutinizer ignore-call */ 
109
                 setOutput( $output );
Loading history...
109
        $loader->options( $options );
110
111
        $this->pipeline->pipe( $loader );
112
113
        return $this;
114
    }
115
116
    public function run () : void
117
    {
118
        $this->pipeline->execute();
119
    }
120
}
121