| Conditions | 10 |
| Paths | 10 |
| Total Lines | 33 |
| Code Lines | 18 |
| 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 |
||
| 43 | public static function get_homepage_link() |
||
| 44 | { |
||
| 45 | if (!self::$cached_homepage_link) { |
||
| 46 | // @todo Move to 'homepagefordomain' module |
||
| 47 | if (class_exists('HomepageForDomainExtension')) { |
||
| 48 | $host = str_replace('www.', null, $_SERVER['HTTP_HOST']); |
||
| 49 | $candidates = SiteTree::get()->where(array( |
||
| 50 | '"SiteTree"."HomepageForDomain" LIKE ?' => "%$host%" |
||
| 51 | )); |
||
| 52 | if ($candidates) { |
||
| 53 | foreach ($candidates as $candidate) { |
||
| 54 | if (preg_match('/(,|^) *' . preg_quote($host) . ' *(,|$)/', $candidate->HomepageForDomain)) { |
||
| 55 | self::$cached_homepage_link = trim($candidate->RelativeLink(true), '/'); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | if (!self::$cached_homepage_link) { |
||
| 62 | // TODO Move to 'translatable' module |
||
| 63 | if (class_exists('Translatable') |
||
| 64 | && SiteTree::has_extension('Translatable') |
||
| 65 | && $link = Translatable::get_homepage_link_by_locale(Translatable::get_current_locale()) |
||
| 66 | ) { |
||
| 67 | self::$cached_homepage_link = $link; |
||
| 68 | } else { |
||
| 69 | self::$cached_homepage_link = Config::inst()->get('SilverStripe\\CMS\\Controllers\\RootURLController', 'default_homepage_link'); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return self::$cached_homepage_link; |
||
| 75 | } |
||
| 76 | |||
| 155 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: