Completed
Pull Request — master (#1)
by De Cramer
02:11
created

AbstractFactory::validateOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\Builder\Factories;
4
5
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
6
7
/**
8
 * Class AbstractFactory
9
 *
10
 * @author    de Cramer Oliver<[email protected]>
11
 * @copyright 2018 Oliverde8
12
 * @package Oliverde8\Component\PhpEtl\Builder\Factories
13
 */
14
abstract class AbstractFactory
15
{
16
    /** @var string The operation type */
17
    protected $operation;
18
19
    /** @var string Class to built */
20
    protected $class;
21
22
    /**
23
     * AbstractFactory constructor.
24
     *
25
     * @param string $operation
26
     * @param string $class
27
     */
28
    public function __construct($operation, $class)
29
    {
30
        $this->operation = $operation;
31
        $this->class = $class;
32
    }
33
34
    /**
35
     * Validate and Build an operation of a certain type with the options.
36
     *
37
     * @param String $operation
38
     * @param array $options
39
     *
40
     * @return ChainOperationInterface
41
     */
42
    public function getOperation($operation, $options)
43
    {
44
        $this->validateOptions($this, $options);
45
        return $this->build($operation, $options);
46
    }
47
48
    /**
49
     * Build an operation of a certain type with the options.
50
     *
51
     * @param String $operation
52
     * @param array $options
53
     *
54
     * @return ChainOperationInterface
55
     */
56
    abstract protected function build($type, $options);
57
58
    /**
59
     * Create the operation object.
60
     *
61
     * @param array ...$arguments
62
     *
63
     * @return ChainOperationInterface
64
     */
65
    protected function create(...$arguments)
66
    {
67
        $class = $this->class;
68
        return new $class(...$arguments);
69
    }
70
71
    /**
72
     * Validate the options.
73
     *
74
     * @param $operation
75
     * @param $options
76
     */
77
    protected function validateOptions($operation, $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

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

77
    protected function validateOptions($operation, /** @scrutinizer ignore-unused */ $options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operation is not used and could be removed. ( Ignorable by Annotation )

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

77
    protected function validateOptions(/** @scrutinizer ignore-unused */ $operation, $options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        // Does nothing for not. TODO validation.
80
    }
81
82
    /**
83
     * Check if the factory supports this operation declaration.
84
     *
85
     * @param $operation
86
     * @param $options
87
     *
88
     * @return bool
89
     */
90
    public function supports($operation, $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

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

90
    public function supports($operation, /** @scrutinizer ignore-unused */ $options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        return $this->operation == $operation;
93
    }
94
}