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

Extractor::setResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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