| Total Complexity | 48 |
| Total Lines | 360 |
| Duplicated Lines | 0 % |
| Changes | 9 | ||
| Bugs | 0 | Features | 0 |
Complex classes like map often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use map, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class map extends route\router implements interfaces\optionsInterface |
||
| 24 | { |
||
| 25 | use \responsible\core\traits\optionsTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * [$BASE_ENDPOINTS] |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | private $BASE_ENDPOINTS = array(); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * [$BASE_ENDPOINTS] |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $NAMESPACE_ENDPOINTS = array(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * [$registry] |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | private $registry = array(); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * [$middleWareClass Holds middleware class object] |
||
| 47 | * @var object |
||
| 48 | */ |
||
| 49 | private static $middleWareClass; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * [$SYSTEM_ENDPOINTS Reserved system Endpoints] |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | const SYSTEM_ENDPOINTS = [ |
||
| 56 | 'token' => '/token/access_token', |
||
| 57 | 'user' => [ |
||
| 58 | '/user/create', |
||
| 59 | '/user/load', |
||
| 60 | ], |
||
| 61 | ]; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * [__construct Silence...] |
||
| 65 | */ |
||
| 66 | public function __construct() {} |
||
| 67 | |||
| 68 | /** |
||
| 69 | * [register Scan and register endpoints defined in services] |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | public function register() |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * [isSystemEndpoint Check if the endpoint request is a ResponsibleAPI reserved endpoint] |
||
| 155 | * @param string $api |
||
| 156 | * @param string $endpoint |
||
| 157 | * @return object|null |
||
| 158 | */ |
||
| 159 | private function isSystemEndpoint($api, $endpoint) |
||
| 160 | { |
||
| 161 | $endpointSettings = []; |
||
| 162 | |||
| 163 | if (isset(self::SYSTEM_ENDPOINTS[$api]) && |
||
| 164 | ( |
||
| 165 | in_array($endpoint, self::SYSTEM_ENDPOINTS) || |
||
| 166 | array_search($endpoint, self::SYSTEM_ENDPOINTS[$api]) !== false |
||
| 167 | ) |
||
| 168 | ) { |
||
| 169 | $methodCreate = explode('/', $endpoint); |
||
| 170 | $methodCreate = array_values(array_filter($methodCreate)); |
||
| 171 | $method = ''; |
||
| 172 | |||
| 173 | foreach ($methodCreate as $i => $parts) { |
||
| 174 | if (preg_match_all('#_#', $parts)) { |
||
| 175 | $parts = str_replace('_', '', lcfirst(ucwords($parts, '_'))); |
||
| 176 | } |
||
| 177 | if ($i > 0) { |
||
| 178 | $method .= ucfirst($parts); |
||
| 179 | } else { |
||
| 180 | $method .= $parts; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | $endpointSettings['model'] = array( |
||
| 185 | 'scope' => 'system', |
||
| 186 | 'namespace' => 'responsible\core\endpoints\system', |
||
| 187 | 'class' => 'system', |
||
| 188 | 'method' => $method, |
||
| 189 | 'arguments' => '', |
||
| 190 | ); |
||
| 191 | |||
| 192 | return (object) $endpointSettings; |
||
| 193 | } |
||
| 194 | |||
| 195 | return null; |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * [isEndpoint Check the requested endpoint, scope and tier parts] |
||
| 200 | * @param string $api |
||
| 201 | * @param string $endpoint |
||
| 202 | * @return object|null |
||
| 203 | */ |
||
| 204 | public function isEndpoint($api, $endpoint) |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * [filterParts Prepare routed parts] |
||
| 331 | * @return array |
||
| 332 | */ |
||
| 333 | private function filterParts($uri, $parts) |
||
| 334 | { |
||
| 335 | $filter = array(); |
||
| 336 | |||
| 337 | foreach ($parts as $p => $part) { |
||
| 338 | if (is_array($part)) { |
||
| 339 | foreach ($part as $i => $parti) { |
||
| 340 | if ($parti !== $uri) { |
||
| 341 | $filter[] = $parti; |
||
| 342 | } |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } |
||
| 346 | |||
| 347 | return $filter; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * [uriCheckSize] |
||
| 352 | * |
||
| 353 | * Compare the current request endpoint with the registered endpoint |
||
| 354 | * only return the same tier sizes |
||
| 355 | * |
||
| 356 | * @return boolean |
||
| 357 | */ |
||
| 358 | private function uriCheckSize($endpointRegister, $endpoint) |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * [getClassModel Class, Method] |
||
| 367 | * @return array |
||
| 368 | */ |
||
| 369 | private function getClassModel($request_path) |
||
| 385 |