Conditions | 17 |
Paths | 888 |
Total Lines | 53 |
Code Lines | 30 |
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 |
||
60 | public static function createIri(array $parts, array $parameters, string $pageParameterName = null, float $page = null, $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH): string |
||
61 | { |
||
62 | if (null !== $page && null !== $pageParameterName) { |
||
63 | $parameters[$pageParameterName] = $page; |
||
64 | } |
||
65 | |||
66 | if (\is_bool($urlGenerationStrategy)) { |
||
67 | @trigger_error(sprintf('Passing a bool as 5th parameter to "%s::createIri()" is deprecated since API Platform 2.6. Pass an "%s" constant (int) instead.', __CLASS__, UrlGeneratorInterface::class), E_USER_DEPRECATED); |
||
68 | $urlGenerationStrategy = $urlGenerationStrategy ? UrlGeneratorInterface::ABS_URL : UrlGeneratorInterface::ABS_PATH; |
||
69 | } |
||
70 | |||
71 | $query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); |
||
72 | $parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query); |
||
73 | |||
74 | $url = ''; |
||
75 | if ((UrlGeneratorInterface::ABS_URL === $urlGenerationStrategy || UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy) && isset($parts['host'])) { |
||
76 | if (isset($parts['scheme'])) { |
||
77 | $scheme = $parts['scheme']; |
||
78 | } elseif (isset($parts['port']) && 443 === $parts['port']) { |
||
79 | $scheme = 'https'; |
||
80 | } else { |
||
81 | $scheme = 'http'; |
||
82 | } |
||
83 | $url .= UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy ? '//' : "$scheme://"; |
||
84 | |||
85 | if (isset($parts['user'])) { |
||
86 | $url .= $parts['user']; |
||
87 | |||
88 | if (isset($parts['pass'])) { |
||
89 | $url .= ':'.$parts['pass']; |
||
90 | } |
||
91 | |||
92 | $url .= '@'; |
||
93 | } |
||
94 | |||
95 | $url .= $parts['host']; |
||
96 | |||
97 | if (isset($parts['port'])) { |
||
98 | $url .= ':'.$parts['port']; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | $url .= $parts['path']; |
||
103 | |||
104 | if ('' !== $parts['query']) { |
||
105 | $url .= '?'.$parts['query']; |
||
106 | } |
||
107 | |||
108 | if (isset($parts['fragment'])) { |
||
109 | $url .= '#'.$parts['fragment']; |
||
110 | } |
||
111 | |||
112 | return $url; |
||
113 | } |
||
115 |