Conditions | 10 |
Paths | 13 |
Total Lines | 32 |
Code Lines | 23 |
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 |
||
59 | public static function slot_list() |
||
60 | { |
||
61 | $list = Config::inst()->get('GoogleDfpSlotHelper', 'layouts'); |
||
62 | if (!is_array($list)) { |
||
63 | return false; |
||
64 | } |
||
65 | |||
66 | $out = ArrayList::create(); |
||
67 | $controller = Controller::curr(); |
||
68 | $dfpTargetPage = $controller->ID; |
||
69 | $dfpTargetCategory = $controller->Parent()->Title ? $controller->Parent()->Title : $controller->Title; |
||
70 | $dfpTargetCategoryParent = $controller->Parent()->Parent()->Title ? $controller->Parent()->Parent()->Title : null; |
||
71 | |||
72 | foreach ($list as $key => $item) { |
||
73 | foreach ($item as $slotKey => $slot) { |
||
74 | $out->add(ArrayData::create(array( |
||
75 | 'ID' => $slotKey, |
||
76 | 'Layout' => $key, |
||
77 | 'Alias' => isset($slot['alias']) ? $slot['alias'] : null, |
||
78 | 'AdUnitPath' => isset($slot['adUnitPath']) ? $slot['adUnitPath'] : null, |
||
79 | 'Size' => isset($slot['size']) ? $slot['size'] : null, |
||
80 | 'OutOfPage' => isset($slot['outOfPage']) ? $slot['outOfPage'] : false, |
||
81 | 'DfpTargetPage' => $dfpTargetPage, |
||
82 | 'DfpTargetCategory' => $dfpTargetCategory, |
||
83 | 'DfpTargetCategoryParent' => $dfpTargetCategoryParent, |
||
84 | 'DfpTargetRos' => $key, |
||
85 | ))); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return $out; |
||
90 | } |
||
91 | |||
118 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.