| Conditions | 27 |
| Paths | 261 |
| Total Lines | 82 |
| Code Lines | 53 |
| Lines | 8 |
| Ratio | 9.76 % |
| 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 |
||
| 53 | protected function validate() |
||
| 54 | { |
||
| 55 | $value =& $this->getData($this->getArgument()); |
||
| 56 | |||
| 57 | if (!is_scalar($value)) { |
||
| 58 | // non scalar values would cause notices |
||
| 59 | $this->throwError(); |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | |||
| 63 | $hasExtraChars = false; |
||
| 64 | if (!is_int($value) && !is_float($value)) { |
||
| 65 | $locale = null; |
||
| 66 | if (Config::get('core.use_translation') && !$this->getParameter('no_locale', false)) { |
||
| 67 | if ($locale = $this->getParameter('in_locale')) { |
||
| 68 | $locale = $this->getContext()->getTranslationManager()->getLocale($locale); |
||
| 69 | } else { |
||
| 70 | $locale = $this->getContext()->getTranslationManager()->getCurrentLocale(); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $parsedValue = DecimalFormatter::parse($value, $locale, $hasExtraChars); |
||
| 75 | } else { |
||
| 76 | $parsedValue = $value; |
||
| 77 | } |
||
| 78 | |||
| 79 | switch (strtolower($this->getParameter('type'))) { |
||
| 80 | case 'int': |
||
| 81 | case 'integer': |
||
| 82 | if (!is_int($parsedValue) || $hasExtraChars) { |
||
| 83 | $this->throwError('type'); |
||
| 84 | return false; |
||
| 85 | } |
||
| 86 | |||
| 87 | break; |
||
| 88 | |||
| 89 | case 'float': |
||
| 90 | case 'double': |
||
| 91 | if ((!is_float($parsedValue) && !is_int($parsedValue)) || $hasExtraChars) { |
||
| 92 | $this->throwError('type'); |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | break; |
||
| 97 | |||
| 98 | default: |
||
| 99 | if ($parsedValue === false || $hasExtraChars) { |
||
| 100 | $this->throwError('type'); |
||
| 101 | return false; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | View Code Duplication | if ($this->hasParameter('min') && $parsedValue < $this->getParameter('min')) { |
|
| 106 | $this->throwError('min'); |
||
| 107 | return false; |
||
| 108 | } |
||
| 109 | |||
| 110 | View Code Duplication | if ($this->hasParameter('max') && $parsedValue > $this->getParameter('max')) { |
|
| 111 | $this->throwError('max'); |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | |||
| 115 | switch (strtolower($this->getParameter('cast_to', $this->getParameter('type')))) { |
||
| 116 | case 'int': |
||
| 117 | case 'integer': |
||
| 118 | $parsedValue = (int) $parsedValue; |
||
| 119 | break; |
||
| 120 | |||
| 121 | case 'float': |
||
| 122 | case 'double': |
||
| 123 | $parsedValue = (float) $parsedValue; |
||
| 124 | break; |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($this->hasParameter('export')) { |
||
| 128 | $this->export($parsedValue); |
||
| 129 | } else { |
||
| 130 | $value = $parsedValue; |
||
| 131 | } |
||
| 132 | |||
| 133 | return true; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: