| Conditions | 14 |
| Paths | 126 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 60 | public function __construct($target, $operator, $value, Value $valueData = null) |
||
| 61 | { |
||
| 62 | if ($operator === null) { |
||
| 63 | $operator = is_array($value) ? Operator::IN : Operator::EQ; |
||
| 64 | } |
||
| 65 | |||
| 66 | $operatorFound = false; |
||
| 67 | |||
| 68 | // we loop on each specified operator. |
||
| 69 | // If the provided operator ain't found, an exception will be thrown at the end |
||
| 70 | foreach ($this->getSpecifications() as $operatorSpecifications) { |
||
| 71 | if ($operatorSpecifications->operator != $operator) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | $operatorFound = true; |
||
| 75 | |||
| 76 | // input format check (single/array) |
||
| 77 | switch ($operatorSpecifications->valueFormat) { |
||
| 78 | case Specifications::FORMAT_SINGLE: |
||
| 79 | if (is_array($value)) { |
||
| 80 | throw new InvalidArgumentException('The Criterion expects a single value'); |
||
| 81 | } |
||
| 82 | break; |
||
| 83 | |||
| 84 | case Specifications::FORMAT_ARRAY: |
||
| 85 | if (!is_array($value)) { |
||
| 86 | throw new InvalidArgumentException('The criterion expects an array of values'); |
||
| 87 | } |
||
| 88 | break; |
||
| 89 | } |
||
| 90 | |||
| 91 | // input value check |
||
| 92 | if ($operatorSpecifications->valueTypes !== null) { |
||
| 93 | $callback = $this->getValueTypeCheckCallback($operatorSpecifications->valueTypes); |
||
| 94 | if (!is_array($value)) { |
||
| 95 | $value = [$value]; |
||
| 96 | } |
||
| 97 | foreach ($value as $item) { |
||
| 98 | if ($callback($item) === false) { |
||
| 99 | throw new InvalidArgumentException('Unsupported value (' . gettype($item) . ")$item"); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | // Operator wasn't found in the criterion specifications |
||
| 106 | if ($operatorFound === false) { |
||
| 107 | throw new InvalidArgumentException("Operator $operator isn't supported by the Criterion " . get_class($this)); |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->operator = $operator; |
||
| 111 | $this->value = $value; |
||
| 112 | $this->target = $target; |
||
| 113 | $this->valueData = $valueData; |
||
| 114 | } |
||
| 115 | |||
| 191 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.