| Conditions | 15 | 
| Paths | 24 | 
| Total Lines | 66 | 
| Code Lines | 39 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| 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  | 
            ||
| 144 | protected function fillRuleObjectFields(RewriteurlRule $rule, $request)  | 
            ||
| 145 |     { | 
            ||
| 146 |         $ruleType = $request->get("ruleType", null); | 
            ||
| 147 |         if ($ruleType !== "regex" && $ruleType !== "params") { | 
            ||
| 148 |             throw new \Exception(Translator::getInstance()->trans("Unknown rule type.", [], RewriteUrl::MODULE_DOMAIN)); | 
            ||
| 149 | }  | 
            ||
| 150 | |||
| 151 |         $regexValue = $request->get("value", null); | 
            ||
| 152 |         if ($ruleType == "regex" && empty($regexValue)) { | 
            ||
| 153 |             throw new \Exception(Translator::getInstance()->trans("Regex value cannot be empty.", [], RewriteUrl::MODULE_DOMAIN)); | 
            ||
| 154 | }  | 
            ||
| 155 | |||
| 156 |         $redirectUrl = $request->get("redirectUrl", null); | 
            ||
| 157 |         if (empty($redirectUrl)) { | 
            ||
| 158 |             throw new \Exception(Translator::getInstance()->trans("Redirect url cannot be empty.", [], RewriteUrl::MODULE_DOMAIN)); | 
            ||
| 159 | }  | 
            ||
| 160 | |||
| 161 | $paramRuleArray = array();  | 
            ||
| 162 |         if ($ruleType == "params") { | 
            ||
| 163 |             $paramRuleArray = $request->get("paramRules", null); | 
            ||
| 164 |             if (empty($paramRuleArray)) { | 
            ||
| 165 |                 throw new \Exception(Translator::getInstance()->trans("At least one GET parameter is required.", [], RewriteUrl::MODULE_DOMAIN)); | 
            ||
| 166 | }  | 
            ||
| 167 | }  | 
            ||
| 168 | |||
| 169 | |||
| 170 | |||
| 171 | $rule->setRuleType($ruleType);  | 
            ||
| 172 | $rule->setValue($regexValue);  | 
            ||
| 173 |         $rule->setOnly404($request->get("only404", 1)); | 
            ||
| 174 | $rule->setRedirectUrl($redirectUrl);  | 
            ||
| 175 |         if (empty($rule->getPosition())) { | 
            ||
| 176 | $rule->setPosition($rule->getNextPosition());  | 
            ||
| 177 | }  | 
            ||
| 178 | |||
| 179 | |||
| 180 | $rule->deleteAllRelatedParam();  | 
            ||
| 181 | |||
| 182 | $rule->save();  | 
            ||
| 183 | |||
| 184 |         if ($ruleType == "params") { | 
            ||
| 185 |             foreach ($paramRuleArray as $paramRule) { | 
            ||
| 186 |                 if (!array_key_exists("paramName", $paramRule) || empty($paramRule["paramName"])) { | 
            ||
| 187 | throw new \Exception(Translator::getInstance()->trans(  | 
            ||
| 188 | "Param name is empty.",  | 
            ||
| 189 | [],  | 
            ||
| 190 | RewriteUrl::MODULE_DOMAIN  | 
            ||
| 191 | ));  | 
            ||
| 192 | }  | 
            ||
| 193 |                 if (!array_key_exists("condition", $paramRule) || empty($paramRule["condition"])) { | 
            ||
| 194 | throw new \Exception(Translator::getInstance()->trans(  | 
            ||
| 195 | "Param condition is empty.",  | 
            ||
| 196 | [],  | 
            ||
| 197 | RewriteUrl::MODULE_DOMAIN  | 
            ||
| 198 | ));  | 
            ||
| 199 | }  | 
            ||
| 200 | |||
| 201 | $paramRuleObject = new RewriteurlRuleParam();  | 
            ||
| 202 | $paramRuleObject->setParamName($paramRule["paramName"]);  | 
            ||
| 203 | $paramRuleObject->setParamCondition($paramRule["condition"]);  | 
            ||
| 204 | $paramRuleObject->setParamValue($paramRule["paramValue"]);  | 
            ||
| 205 | $paramRuleObject->setIdRule($rule->getId());  | 
            ||
| 206 | $paramRuleObject->save();  | 
            ||
| 207 | }  | 
            ||
| 208 | }  | 
            ||
| 209 | }  | 
            ||
| 210 | }  | 
            ||
| 211 |