| Conditions | 10 |
| Paths | 49 |
| Total Lines | 12 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 24 | public function __construct($url=''){ |
||
| 25 | if (empty($url) || !is_string($url)) return; |
||
| 26 | $tmp_url = (strpos($url, '://') === false) ? "..N..://$url" : $url; |
||
| 27 | if (mb_detect_encoding($tmp_url, 'UTF-8', true) || ($parsed = parse_url($tmp_url)) === false) { |
||
| 28 | preg_match('(^((?P<scheme>[^:/?#]+):(//))?((\\3|//)?(?:(?P<user>[^:]+):(?P<pass>[^@]+)@)?(?P<host>[^/?:#]*))(:(?P<port>\\d+))?(?P<path>[^?#]*)(\\?(?P<query>[^#]*))?(#(?P<fragment>.*))?)u', $tmp_url, $parsed); |
||
| 29 | } |
||
| 30 | foreach($parsed as $k => $v) if(isset($this->$k)) $this->$k = $v; |
||
| 31 | if ($this->scheme == '..N..') $this->scheme = null; |
||
| 32 | if (!empty($this->query)) { |
||
| 33 | parse_str($this->query, $this->query); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 50 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.