| Conditions | 8 |
| Paths | 9 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 99 | private function make( |
||
| 100 | array $data, |
||
| 101 | array $rules |
||
| 102 | ) { |
||
| 103 | $data = $this->prepareData($data); |
||
| 104 | $rules = $this->prepareRules($rules); |
||
| 105 | |||
| 106 | foreach ($rules as $fieldName => $fieldRules) { |
||
| 107 | $fieldName = trim($fieldName); |
||
| 108 | $fieldRules = trim($fieldRules); |
||
| 109 | |||
| 110 | if (!$fieldRules) { |
||
| 111 | //no rules |
||
| 112 | throw new Excpetion('No rules provided.'); |
||
| 113 | } |
||
| 114 | |||
| 115 | $groupedRules = explode(self::$ruleSeparator, $fieldRules); |
||
| 116 | |||
| 117 | foreach ($groupedRules as $concreteRule) { |
||
| 118 | $ruleNameParam = explode(self::$ruleParamSeparator, $concreteRule); |
||
| 119 | $ruleName = $ruleNameParam[0]; |
||
| 120 | |||
| 121 | // For date/time validators. |
||
| 122 | if (count($ruleNameParam) >= 2) { |
||
| 123 | $ruleValue = implode(self::$ruleParamSeparator, array_slice( |
||
| 124 | $ruleNameParam, |
||
| 125 | 1 |
||
| 126 | )); |
||
| 127 | //for other params |
||
| 128 | } else { |
||
| 129 | $ruleValue = isset($ruleNameParam[1]) ? $ruleNameParam[1] : ''; |
||
| 130 | } |
||
| 131 | |||
| 132 | self::$config[BaseRule::CONFIG_DATA] = $data; |
||
| 133 | self::$config[BaseRule::CONFIG_FIELD_RULES] = $fieldRules; |
||
| 134 | |||
| 135 | $ruleInstance = $this->rulesFactory->createRule( |
||
| 136 | $ruleName, |
||
| 137 | self::$config, |
||
| 138 | [ |
||
| 139 | $fieldName, // The field name |
||
| 140 | isset($data[$fieldName]) ? $data[$fieldName] : '', // The provided value |
||
| 141 | $ruleValue, // The rule's value |
||
| 142 | ], |
||
| 143 | $this->validationProvider |
||
| 144 | ); |
||
| 145 | |||
| 146 | if (! $ruleInstance->isValid()) { |
||
| 147 | $this->validationResultProcessor->chooseErrorMessage($ruleInstance); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | return $this->validationResultProcessor; |
||
| 153 | } |
||
| 154 | |||
| 220 |
This check marks private properties in classes that are never used. Those properties can be removed.