| Conditions | 10 |
| Paths | 7 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 56 | public function getPiwik($wrap = true) |
||
| 57 | { |
||
| 58 | if (Director::is_cli()) { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | //don't include on dev/build etc... |
||
| 62 | if (Controller::curr() instanceof DevelopmentAdmin) { |
||
| 63 | return false; |
||
| 64 | } |
||
| 65 | if (Director::isDev() && !Config::inst()->get('PiwikExtension', 'show_on_dev')) { |
||
| 66 | return false; |
||
| 67 | } |
||
| 68 | if (Director::isTest() && !Config::inst()->get('PiwikExtension', 'show_on_test')) { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | if (Director::isLive() && !Config::inst()->get('PiwikExtension', 'show_on_live')) { |
||
| 72 | return false; |
||
| 73 | } |
||
| 74 | |||
| 75 | //used for overwriting defaults in SiteConfig, e.g. for different SiteIDs in a Subsite installation |
||
| 76 | $currentSiteConfig = Controller::curr()->hasMethod('getSiteConfig') |
||
| 77 | ? Controller::curr()->getSiteConfig() |
||
| 78 | : SiteConfig::current_site_config(); |
||
| 79 | |||
| 80 | |||
| 81 | $data = array( |
||
| 82 | 'WrapInJsTags' => $wrap, |
||
| 83 | 'URL' => Config::inst()->get('PiwikExtension', 'piwik_server'), |
||
| 84 | 'SiteID' => Config::inst()->get('PiwikExtension', 'piwik_site_id'), |
||
| 85 | 'SiteConfig' => $currentSiteConfig |
||
| 86 | ); |
||
| 87 | |||
| 88 | return ArrayData::create($data)->renderWith(array('Piwik')); |
||
| 89 | } |
||
| 90 | |||
| 117 |
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.