| Conditions | 9 |
| Paths | 5 |
| Total Lines | 23 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 9 |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 30 | 7 | public static function createFilter($element) |
|
| 31 | { |
||
| 32 | 7 | if (is_callable($element)) { |
|
| 33 | 1 | $filter = new CallbackFilter($element); |
|
| 34 | 7 | } elseif (is_array($element) && isset($element['filter']) && is_callable($element['filter'])) { |
|
| 35 | 1 | $filter = new CallbackFilter($element['filter']); |
|
| 36 | 1 | unset($element['filter']); |
|
| 37 | 6 | } elseif (is_array($element) && isset($element['filter']) && $element['filter'] instanceof FilterInterface) { |
|
| 38 | 2 | $filter = $element['filter']; |
|
| 39 | 2 | unset($element['filter']); |
|
| 40 | 5 | } elseif ($element instanceof FilterInterface) { |
|
| 41 | 1 | $filter = $element; |
|
| 42 | 1 | } else { |
|
| 43 | 2 | throw new InvalidArgumentException('Workflow::addFilter() must be called with either an instance of '. |
|
| 44 | 2 | '"Plum\Plum\Filter\FilterInterface" or an array that contains '. |
|
| 45 | 2 | '"filter".'); |
|
| 46 | } |
||
| 47 | |||
| 48 | 5 | $pipe = new self($element); |
|
| 49 | 5 | $pipe->filter = $filter; |
|
| 50 | |||
| 51 | 5 | return $pipe; |
|
| 52 | } |
||
| 53 | } |
||
| 54 |