Conditions | 10 |
Paths | 4 |
Total Lines | 27 |
Code Lines | 16 |
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 |
||
28 | public function parse($notification, $categoryId) |
||
|
|||
29 | { |
||
30 | $category = $notification->category; |
||
31 | if (is_null($category)) { |
||
32 | throw (new ModelNotFoundException)->setModel( |
||
33 | NotificationCategory::class, $notification->category_id |
||
34 | ); |
||
35 | } |
||
36 | $text = $category->template_body; |
||
37 | |||
38 | $specialValues = $this->getValues($text); |
||
39 | if (count($specialValues) > 0) { |
||
40 | $specialValues = array_filter($specialValues, function ($value) use ($notification) { |
||
41 | return ((is_array($notification) && isset($notification[$value])) || (is_object($notification) && isset($notification->$value))) || starts_with($value, ['extra.', 'to.', 'from.']); |
||
42 | }); |
||
43 | |||
44 | foreach ($specialValues as $replacer) { |
||
45 | $replace = $this->mixedGet($notification, $replacer); |
||
46 | if (empty($replace) && notifynder_config()->isStrict()) { |
||
47 | throw new ExtraParamsException("The following [$replacer] param required from your category is missing."); |
||
48 | } |
||
49 | $text = $this->replace($text, $replace, $replacer); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | return $text; |
||
54 | } |
||
55 | |||
120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.