| Conditions | 21 |
| Paths | 17 |
| Total Lines | 54 |
| Code Lines | 26 |
| Lines | 5 |
| Ratio | 9.26 % |
| 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 |
||
| 65 | public function getUrl(string $sCode, array $aParams = array()) : string |
||
| 66 | { |
||
| 67 | if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) { |
||
| 68 | |||
| 69 | foreach (Config::get('Route') as $sHost => $oHost) { |
||
|
|
|||
| 70 | |||
| 71 | if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
||
| 72 | || (strstr($sHost, '/') |
||
| 73 | && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
||
| 74 | |||
| 75 | View Code Duplication | if (strstr($sHost, '/') |
|
| 76 | && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
||
| 77 | |||
| 78 | $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (isset($oHost->routes)) { |
||
| 82 | |||
| 83 | foreach($oHost->routes as $sKey => $oRoute) { |
||
| 84 | |||
| 85 | if ($sKey === $sCode) { |
||
| 86 | |||
| 87 | $sRoute = $this->_sBaseUri.$oRoute->route; |
||
| 88 | |||
| 89 | if (isset($oRoute->constraints)) { |
||
| 90 | |||
| 91 | foreach ($oRoute->constraints as $sName => $sType) { |
||
| 92 | |||
| 93 | if (!isset($aParams[$sName])) { $aParams[$sName] = ''; } |
||
| 94 | |||
| 95 | if (preg_match('#'.$sType.'#', $aParams[$sName])) { |
||
| 96 | |||
| 97 | if ($aParams[$sName]) { $sRoute = str_replace('[/:'.$sName.']', '/'.$aParams[$sName], $sRoute); } else { $sRoute = str_replace('[/:'.$sName.']', '', $sRoute); } |
||
| 98 | $sRoute = str_replace('[:'.$sName.']', $aParams[$sName], $sRoute); |
||
| 99 | continue; |
||
| 100 | } else if (isset($oRoute->defaults_constraints) |
||
| 101 | && isset($oRoute->defaults_constraints->{$sName}) |
||
| 102 | && preg_match('#'.$sType.'#', $oRoute->defaults_constraints->{$sName})) { |
||
| 103 | |||
| 104 | continue; |
||
| 105 | } |
||
| 106 | |||
| 107 | throw new \Exception('For the route '.$sCode.' the parameter '.$sName.' is not good!'); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | return $sRoute; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 142 |