| Conditions | 11 | 
| Paths | 24 | 
| Total Lines | 31 | 
| Code Lines | 17 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | 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  | 
            ||
| 74 | protected function _url($url, $text, $label = false, $truncate = false)  | 
            ||
| 75 |     { | 
            ||
| 76 | // add http:// to URLs without protocol  | 
            ||
| 77 |         if (strpos($url, '://') === false) { | 
            ||
| 78 | // use Cakes Validation class to detect valid URL  | 
            ||
| 79 | $validator = new Validator();  | 
            ||
| 80 |             $validator->add('url', ['url' => ['rule' => 'url']]); | 
            ||
| 81 | $errors = $validator->validate(['url' => $url]);  | 
            ||
| 82 |             if (empty($errors)) { | 
            ||
| 83 | $url = 'http://' . $url;  | 
            ||
| 84 | }  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 | $out = "<a href='$url' class=\"richtext-link";  | 
            ||
| 88 |         if ($truncate) { | 
            ||
| 89 | $out .= ' truncate';  | 
            ||
| 90 | }  | 
            ||
| 91 | $out .= "\">$text</a>";  | 
            ||
| 92 | $out = $this->_decorateTarget($out);  | 
            ||
| 93 | |||
| 94 | // add domain info: `[url=domain.info]my link[/url]` -> `my link [domain.info]`  | 
            ||
| 95 |         if ($label !== false && $label !== 'none' && $label !== 'false') { | 
            ||
| 96 |             if (!empty($url) && preg_match('/\<img\s*?src=/', $text) !== 1) { | 
            ||
| 97 | $host = DomainParser::domainAndTld($url);  | 
            ||
| 98 |                 if ($host !== null && $host !== env('SERVER_NAME')) { | 
            ||
| 99 | $out .= ' <span class=\'richtext-linkInfo\'>[' . $host . ']</span>';  | 
            ||
| 100 | }  | 
            ||
| 101 | }  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 | return $out;  | 
            ||
| 105 | }  | 
            ||
| 157 |