| Conditions | 12 |
| Paths | 54 |
| Total Lines | 71 |
| 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 |
||
| 106 | public function register($sType, $sDirectory, $aOptions) |
||
| 107 | { |
||
| 108 | if($sType != $this->getName()) |
||
| 109 | { |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | |||
| 113 | if(!is_string($sDirectory) || !is_dir($sDirectory)) |
||
| 114 | { |
||
| 115 | throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration')); |
||
| 116 | } |
||
| 117 | if(is_string($aOptions)) |
||
| 118 | { |
||
| 119 | $aOptions = ['namespace' => $aOptions]; |
||
| 120 | } |
||
| 121 | if(!is_array($aOptions)) |
||
| 122 | { |
||
| 123 | throw new \Jaxon\Exception\Error($this->trans('errors.objects.invalid-declaration')); |
||
| 124 | } |
||
| 125 | |||
| 126 | $sDirectory = rtrim(trim($sDirectory), DIRECTORY_SEPARATOR); |
||
| 127 | if(!is_dir($sDirectory)) |
||
| 128 | { |
||
| 129 | return false; |
||
| 130 | } |
||
| 131 | $aOptions['directory'] = $sDirectory; |
||
| 132 | |||
| 133 | $sNamespace = key_exists('namespace', $aOptions) ? $aOptions['namespace'] : ''; |
||
| 134 | if(!($sNamespace = trim($sNamespace, ' \\'))) |
||
| 135 | { |
||
| 136 | $sNamespace = ''; |
||
| 137 | } |
||
| 138 | |||
| 139 | // $sSeparator = key_exists('separator', $aOptions) ? $aOptions['separator'] : '.'; |
||
| 140 | // // Only '.' and '_' are allowed to be used as separator. Any other value is ignored and '.' is used instead. |
||
| 141 | // if(($sSeparator = trim($sSeparator)) != '_') |
||
| 142 | // { |
||
| 143 | // $sSeparator = '.'; |
||
| 144 | // } |
||
| 145 | |||
| 146 | // Change the keys in $aOptions to have "\" as separator |
||
| 147 | $_aOptions = []; |
||
| 148 | foreach($aOptions as $sName => $aOption) |
||
| 149 | { |
||
| 150 | $sName = trim(str_replace('.', '\\', $sName), ' \\'); |
||
| 151 | $_aOptions[$sName] = $aOption; |
||
| 152 | } |
||
| 153 | $aOptions = $_aOptions; |
||
| 154 | |||
| 155 | if(($sNamespace)) |
||
| 156 | { |
||
| 157 | // Register the dir with PSR4 autoloading |
||
| 158 | if(($this->xAutoloader)) |
||
| 159 | { |
||
| 160 | $this->xAutoloader->setPsr4($sNamespace . '\\', $sDirectory); |
||
| 161 | } |
||
| 162 | |||
| 163 | $this->repository->addNamespace($sNamespace, $aOptions); |
||
| 164 | } |
||
| 165 | else |
||
| 166 | { |
||
| 167 | // Use underscore as separator, so there's no need to deal with namespace |
||
| 168 | // when generating javascript code. |
||
| 169 | $aOptions['separator'] = '_'; |
||
| 170 | $aOptions['autoload'] = $this->bAutoloadEnabled; |
||
| 171 | |||
| 172 | $this->repository->addDirectory($sDirectory, $aOptions); |
||
| 173 | } |
||
| 174 | |||
| 175 | return true; |
||
| 176 | } |
||
| 177 | |||
| 218 |