Conditions | 22 |
Paths | 64 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
15 | function smarty_modifier_has_subscription($user) |
||
16 | { |
||
17 | $context = \CampTemplate::singleton()->context(); |
||
18 | $user = $context->user; |
||
19 | if (!$user) { |
||
20 | return false; |
||
21 | } |
||
22 | |||
23 | $em = \Zend_Registry::get('container')->getService('em'); |
||
24 | $userSubscriptions = $em->getRepository("Newscoop\PaywallBundle\Entity\UserSubscription") |
||
25 | ->getValidSubscriptionsBy($user->identifier)->getArrayResult(); |
||
26 | |||
27 | $publication = $context->publication; |
||
28 | $issue = $context->issue; |
||
29 | $section = $context->section; |
||
30 | $article = $context->article; |
||
31 | |||
32 | try { |
||
33 | foreach ($userSubscriptions as $key => $value) { |
||
34 | $specification = $value['subscription']['specification'][0]; |
||
35 | if ($value['subscription']['type'] === 'publication' && $publication) { |
||
36 | if ($specification['publication'] == $publication->identifier) { |
||
37 | return true; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | if ($value['subscription']['type'] === 'issue' && $issue) { |
||
42 | if ($specification['issue'] == $issue->number && |
||
43 | $specification['publication'] == $issue->publication->identifier) { |
||
44 | return true; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | if ($value['subscription']['type'] === 'section' && $section) { |
||
49 | if ($specification['section'] == $section->number && |
||
50 | $specification['issue'] == $section->issue->number && |
||
51 | $specification['publication'] == $issue->publication->identifier) { |
||
52 | return true; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if ($value['subscription']['type'] === 'article' && $article) { |
||
57 | if ($specification['article'] == $article->number && |
||
58 | $specification['publication'] == $article->publication->identifier && |
||
59 | $specification['issue'] == $article->issue->number && |
||
60 | $specification['section'] == $article->section->number) { |
||
61 | return true; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | } catch (\Exception $e) { |
||
66 | return false; |
||
67 | } |
||
68 | |||
69 | return false; |
||
70 | } |
||
71 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.