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

SourceWatcher   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 13 2
A extract() 0 13 2
A __construct() 0 4 1
A run() 0 3 1
A transform() 0 12 2
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
use Coco\SourceWatcher\Core\IO\Inputs\Input;
6
7
/**
8
 * Class SourceWatcher
9
 * @package Coco\SourceWatcher\Core
10
 */
11
class SourceWatcher
12
{
13
    private StepLoader $stepLoader;
14
15
    private Pipeline $pipeline;
16
17
    public function __construct ()
18
    {
19
        $this->stepLoader = new StepLoader();
20
        $this->pipeline = new Pipeline();
21
    }
22
23
    public function extract ( string $extractorName, Input $input, array $options = [] ) : SourceWatcher
24
    {
25
        try {
26
            $extractor = $this->stepLoader->getStep( Extractor::class, $extractorName );
27
            $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

27
            $extractor->/** @scrutinizer ignore-call */ 
28
                        setInput( $input );
Loading history...
28
            $extractor->options( $options );
29
30
            $this->pipeline->setExtractor( $extractor );
0 ignored issues
show
Bug introduced by
It seems like $extractor can also be of type null; however, parameter $extractor of Coco\SourceWatcher\Core\Pipeline::setExtractor() does only seem to accept Coco\SourceWatcher\Core\Extractor, maybe add an additional type check? ( Ignorable by Annotation )

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

30
            $this->pipeline->setExtractor( /** @scrutinizer ignore-type */ $extractor );
Loading history...
31
        } catch ( SourceWatcherException $sourceWatcherException ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
32
33
        }
34
35
        return $this;
36
    }
37
38
    public function transform ( string $transformerName, array $options = [] ) : SourceWatcher
39
    {
40
        try {
41
            $transformer = $this->stepLoader->getStep( Transformer::class, $transformerName );
42
            $transformer->options( $options );
43
44
            $this->pipeline->pipe( $transformer );
0 ignored issues
show
Bug introduced by
It seems like $transformer can also be of type null; however, parameter $step of Coco\SourceWatcher\Core\Pipeline::pipe() does only seem to accept Coco\SourceWatcher\Core\Step, maybe add an additional type check? ( Ignorable by Annotation )

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

44
            $this->pipeline->pipe( /** @scrutinizer ignore-type */ $transformer );
Loading history...
45
        } catch ( SourceWatcherException $sourceWatcherException ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
46
47
        }
48
49
        return $this;
50
    }
51
52
    public function load ( string $loaderName, $output, $options = [] ) : SourceWatcher
53
    {
54
        try {
55
            $loader = $this->stepLoader->getStep( Loader::class, $loaderName );
56
            $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

56
            $loader->/** @scrutinizer ignore-call */ 
57
                     setOutput( $output );
Loading history...
57
            $loader->options( $options );
58
59
            $this->pipeline->pipe( $loader );
0 ignored issues
show
Bug introduced by
It seems like $loader can also be of type null; however, parameter $step of Coco\SourceWatcher\Core\Pipeline::pipe() does only seem to accept Coco\SourceWatcher\Core\Step, maybe add an additional type check? ( Ignorable by Annotation )

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

59
            $this->pipeline->pipe( /** @scrutinizer ignore-type */ $loader );
Loading history...
60
        } catch ( SourceWatcherException $sourceWatcherException ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
62
        }
63
64
        return $this;
65
    }
66
67
    public function run () : void
68
    {
69
        $this->pipeline->execute();
70
    }
71
}
72