AbstractPipe::setFilter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of plumphp/plum.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Plum\Plum\Pipe;
12
13
use Plum\Plum\Converter\ConverterInterface;
14
use Plum\Plum\Filter\CallbackFilter;
15
use Plum\Plum\Filter\FilterInterface;
16
use Plum\Plum\Workflow;
17
use Plum\Plum\Writer\WriterInterface;
18
19
/**
20
 * Pipe.
21
 *
22
 * @author    Florian Eckerstorfer
23
 * @copyright 2014-2016 Florian Eckerstorfer
24
 */
25
abstract class AbstractPipe
26
{
27
    /**
28
     * @var int
29
     */
30
    protected $position = Workflow::APPEND;
31
32
    /**
33
     * @var FilterInterface
34
     */
35
    protected $filter;
36
37
    /**
38
     * @var ConverterInterface
39
     */
40
    protected $converter;
41
42
    /**
43
     * @var WriterInterface
44
     */
45
    protected $writer;
46
47
    /**
48
     * @var string|int|array
49
     */
50
    protected $field;
51
52
    /**
53
     * @var string|int|array
54
     */
55
    protected $filterField;
56
57
    /**
58
     * @param mixed $element
59
     */
60 8
    public function __construct($element)
61
    {
62 8
        if (is_array($element) && isset($element['position'])) {
63 1
            $this->setPosition($element['position']);
64 1
        }
65 8
        if (is_array($element) && isset($element['field'])) {
66 2
            $this->setField($element['field']);
67 2
        }
68 8
        if (is_array($element) && isset($element['filterField'])) {
69 1
            $this->setFilterField($element['filterField']);
70 1
        }
71 8
        if (is_array($element) && isset($element['filter']) && is_callable($element['filter'])) {
72 2
            $this->setFilter(new CallbackFilter($element['filter']));
73 8
        } elseif (is_array($element) && isset($element['filter'])) {
74 2
            $this->setFilter($element['filter']);
75 2
        }
76 8
    }
77
78
    /**
79
     * @return FilterInterface
80
     */
81 6
    public function getFilter()
82
    {
83 6
        return $this->filter;
84
    }
85
86
    /**
87
     * @return ConverterInterface
88
     */
89 5
    public function getConverter()
90
    {
91 5
        return $this->converter;
92
    }
93
94
    /**
95
     * @return WriterInterface
96
     */
97 2
    public function getWriter()
98
    {
99 2
        return $this->writer;
100
    }
101
102
    /**
103
     * @return int
104
     */
105 1
    public function getPosition()
106
    {
107 1
        return $this->position;
108
    }
109
110
    /**
111
     * @return array|int|string
112
     */
113 2
    public function getField()
114
    {
115 2
        return $this->field;
116
    }
117
118
    /**
119
     * @return array|int|string
120
     */
121 1
    public function getFilterField()
122
    {
123 1
        return $this->filterField;
124
    }
125
126
    /**
127
     * @param int $position
128
     *
129
     * @return AbstractPipe
130
     */
131 1
    public function setPosition($position)
132
    {
133 1
        $this->position = $position;
134
135 1
        return $this;
136
    }
137
138
    /**
139
     * @param FilterInterface $filter
140
     *
141
     * @return AbstractPipe
142
     */
143 2
    public function setFilter(FilterInterface $filter)
144
    {
145 2
        $this->filter = $filter;
146
147 2
        return $this;
148
    }
149
150
    /**
151
     * @param array|int|string $filterField
152
     *
153
     * @return $this
154
     */
155 1
    public function setFilterField($filterField)
156
    {
157 1
        $this->filterField = $filterField;
158
159 1
        return $this;
160
    }
161
162
    /**
163
     * @param array|int|string $field
164
     *
165
     * @return $this
166
     */
167 2
    public function setField($field)
168
    {
169 2
        $this->field = $field;
170
171 2
        return $this;
172
    }
173
}
174