Passed
Push — master ( f38dcf...954e17 )
by Jean Paul
01:37
created

Extractor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInput() 0 3 1
A setInput() 0 3 1
A getResult() 0 3 1
A getArrayRepresentation() 0 11 3
A setResult() 0 3 1
1
<?php
2
3
namespace Coco\SourceWatcher\Core;
4
5
use Coco\SourceWatcher\Core\Extractors\CsvExtractor;
6
use Coco\SourceWatcher\Core\Extractors\JsonExtractor;
7
use Coco\SourceWatcher\Core\IO\Inputs\Input;
8
9
/**
10
 * Class Extractor
11
 *
12
 * @package Coco\SourceWatcher\Core
13
 */
14
abstract class Extractor extends Step
15
{
16
    protected ?Input $input = null;
17
18
    public function getInput () : Input
19
    {
20
        return $this->input;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->input could return the type null which is incompatible with the type-hinted return Coco\SourceWatcher\Core\IO\Inputs\Input. Consider adding an additional type-check to rule them out.
Loading history...
21
    }
22
23
    public function setInput ( ?Input $input ) : void
24
    {
25
        $this->input = $input;
26
    }
27
28
    public abstract function extract ();
29
30
    /**
31
     * @var array
32
     */
33
    protected array $result;
34
35
    /**
36
     * @return array
37
     */
38
    public function getResult () : array
39
    {
40
        return $this->result;
41
    }
42
43
    /**
44
     * @param array $result
45
     */
46
    public function setResult ( array $result ) : void
47
    {
48
        $this->result = $result;
49
    }
50
51
    public function getArrayRepresentation () : array
52
    {
53
        $result = parent::getArrayRepresentation();
54
55
        if ( $this instanceof CsvExtractor || $this instanceof JsonExtractor ) {
56
            $fileInput = $this->getInput();
57
58
            $result["input"] = [ "class" => get_class( $fileInput ), "location" => $fileInput->getInput() ];
59
        }
60
61
        return $result;
62
    }
63
}
64