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