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