Conditions | 12 |
Paths | 152 |
Total Lines | 50 |
Code Lines | 27 |
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 |
||
70 | public static function createIri(array $parts, array $parameters, string $pageParameterName, float $page = null, bool $absoluteUrl = false): string |
||
71 | { |
||
72 | if (null !== $page) { |
||
73 | $parameters[$pageParameterName] = $page; |
||
74 | } |
||
75 | |||
76 | $query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); |
||
77 | $parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query); |
||
78 | |||
79 | $url = ''; |
||
80 | |||
81 | if ($absoluteUrl && isset($parts['host'])) { |
||
82 | if (isset($parts['scheme'])) { |
||
83 | $url .= $parts['scheme']; |
||
84 | } elseif (isset($parts['port']) && 443 === $parts['port']) { |
||
85 | $url .= 'https'; |
||
86 | } else { |
||
87 | $url .= 'http'; |
||
88 | } |
||
89 | |||
90 | $url .= '://'; |
||
91 | |||
92 | if (isset($parts['user'])) { |
||
93 | $url .= $parts['user']; |
||
94 | |||
95 | if (isset($parts['pass'])) { |
||
96 | $url .= ':'.$parts['pass']; |
||
97 | } |
||
98 | |||
99 | $url .= '@'; |
||
100 | } |
||
101 | |||
102 | $url .= $parts['host']; |
||
103 | |||
104 | if (isset($parts['port'])) { |
||
105 | $url .= ':'.$parts['port']; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $url .= $parts['path']; |
||
110 | |||
111 | if ('' !== $parts['query']) { |
||
112 | $url .= '?'.$parts['query']; |
||
113 | } |
||
114 | |||
115 | if (isset($parts['fragment'])) { |
||
116 | $url .= '#'.$parts['fragment']; |
||
117 | } |
||
118 | |||
119 | return $url; |
||
120 | } |
||
122 |