| Total Complexity | 108 |
| Total Lines | 475 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like LearningLocker 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 LearningLocker, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class LearningLocker { |
||
| 23 | |||
| 24 | public $api; |
||
| 25 | public $user; |
||
| 26 | public $role; |
||
| 27 | public $users; |
||
| 28 | public $roles; |
||
| 29 | public $store; |
||
| 30 | public $query; |
||
| 31 | public $stores; |
||
| 32 | public $export; |
||
| 33 | public $client; |
||
| 34 | public $exports; |
||
| 35 | public $clients; |
||
| 36 | public $queries; |
||
| 37 | public $persona; |
||
| 38 | public $journey; |
||
| 39 | public $personas; |
||
| 40 | public $journeys; |
||
| 41 | public $download; |
||
| 42 | public $downloads; |
||
| 43 | public $dashboard; |
||
| 44 | public $statement; |
||
| 45 | public $dashboards; |
||
| 46 | public $statements; |
||
| 47 | public $connection; |
||
| 48 | public $aggregation; |
||
| 49 | public $organisation; |
||
| 50 | public $organisations; |
||
| 51 | public $visualisation; |
||
| 52 | public $visualisations; |
||
| 53 | public $journey_progress; |
||
| 54 | public $statement_forwarding; |
||
| 55 | |||
| 56 | public function __construct($key = null, $secret = null, $url = null) |
||
| 57 | { |
||
| 58 | |||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Learning Locker API: Connect |
||
| 63 | * |
||
| 64 | * @return Connection |
||
| 65 | */ |
||
| 66 | public function connect($key, $secret, $url) |
||
| 67 | { |
||
| 68 | if ($this->connection) return $this; |
||
| 69 | |||
| 70 | $this->connection = new Connection($key, $secret, $url); |
||
| 71 | return $this->connect($key, $secret, $url); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Learning Locker API: Clients |
||
| 76 | * |
||
| 77 | * @return ClientHandler |
||
| 78 | */ |
||
| 79 | public function clients() |
||
| 80 | { |
||
| 81 | if ($this->clients) return $this->clients; |
||
| 82 | |||
| 83 | $this->clients = new ClientHandler; |
||
| 84 | return $this->clients(); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Learning Locker API: Client |
||
| 89 | * |
||
| 90 | * @param $id |
||
| 91 | * @return ClientHandler |
||
| 92 | */ |
||
| 93 | public function client($id = null) |
||
| 94 | { |
||
| 95 | if ($this->client) return $this->client; |
||
| 96 | $this->client = new ClientHandler($id ? $id : null); |
||
| 97 | return $this->client($id ? $id : null); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Learning Locker API: Users |
||
| 102 | * |
||
| 103 | * @return UserHandler |
||
| 104 | */ |
||
| 105 | public function users() |
||
| 106 | { |
||
| 107 | if ($this->users) return $this->users; |
||
| 108 | |||
| 109 | $this->users = new UserHandler; |
||
| 110 | return $this->users(); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Learning Locker API: User |
||
| 115 | * |
||
| 116 | * @param $id |
||
| 117 | * @return UserHandler |
||
| 118 | */ |
||
| 119 | public function user($id = null) |
||
| 120 | { |
||
| 121 | if ($this->user) return $this->user; |
||
| 122 | |||
| 123 | $this->user = new UserHandler($id ? $id : null); |
||
| 124 | return $this->user($id ? $id : null); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Learning Locker API: Roles |
||
| 129 | * |
||
| 130 | * @return RoleHandler |
||
| 131 | */ |
||
| 132 | public function roles() |
||
| 133 | { |
||
| 134 | if ($this->roles) return $this->roles; |
||
| 135 | |||
| 136 | $this->roles = new RoleHandler; |
||
| 137 | return $this->roles(); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Learning Locker API: Role |
||
| 142 | * |
||
| 143 | * @param $id |
||
| 144 | * @return RoleHandler |
||
| 145 | */ |
||
| 146 | public function role($id = null) |
||
| 147 | { |
||
| 148 | if ($this->role) return $this->role; |
||
| 149 | |||
| 150 | $this->role = new RoleHandler($id ? $id : null); |
||
| 151 | return $this->role($id ? $id : null); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Learning Locker API: Stores (LRS) |
||
| 156 | * |
||
| 157 | * @return StoreHandler |
||
| 158 | */ |
||
| 159 | public function stores() |
||
| 160 | { |
||
| 161 | if ($this->stores) return $this->stores; |
||
| 162 | |||
| 163 | $this->stores = new StoreHandler; |
||
| 164 | return $this->stores(); |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Learning Locker API: Store (LRS) |
||
| 169 | * |
||
| 170 | * @param $id |
||
| 171 | * @return StoreHandler |
||
| 172 | */ |
||
| 173 | public function store($id = null) |
||
| 174 | { |
||
| 175 | if ($this->store) return $this->store; |
||
| 176 | |||
| 177 | $this->store = new StoreHandler($id ? $id : null); |
||
| 178 | return $this->store($id ? $id : null); |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Learning Locker API: Query |
||
| 183 | * |
||
| 184 | * @return QueryHandler |
||
| 185 | */ |
||
| 186 | public function queries() |
||
| 187 | { |
||
| 188 | if ($this->queries) return $this->queries; |
||
| 189 | |||
| 190 | $this->queries = new QueryHandler; |
||
| 191 | return $this->queries(); |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Learning Locker API: Query |
||
| 196 | * |
||
| 197 | * @return QueryHandler |
||
| 198 | */ |
||
| 199 | public function query($id = null) |
||
| 200 | { |
||
| 201 | if ($this->query) return $this->query; |
||
| 202 | |||
| 203 | $this->query = new QueryHandler($id ? $id : null); |
||
| 204 | return $this->query($id ? $id : null); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Learning Locker API: Exports |
||
| 209 | * |
||
| 210 | * @return ExportHandler |
||
| 211 | */ |
||
| 212 | public function exports() |
||
| 213 | { |
||
| 214 | if ($this->exports) return $this->exports; |
||
| 215 | |||
| 216 | $this->exports = new ExportHandler; |
||
| 217 | return $this->exports(); |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Learning Locker API: Exports |
||
| 222 | * |
||
| 223 | * @return ExportHandler |
||
| 224 | */ |
||
| 225 | public function export($id = null) |
||
| 226 | { |
||
| 227 | if ($this->export) return $this->export; |
||
| 228 | |||
| 229 | $this->export = new ExportHandler($id ? $id : null); |
||
| 230 | return $this->export($id ? $id : null); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Learning Locker API: Personas |
||
| 235 | * |
||
| 236 | * @return PersonaHandler |
||
| 237 | */ |
||
| 238 | public function personas() |
||
| 239 | { |
||
| 240 | if ($this->personas) return $this->personas; |
||
| 241 | |||
| 242 | $this->personas = new PersonaHandler; |
||
| 243 | return $this->personas(); |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Learning Locker API: Persona |
||
| 248 | * |
||
| 249 | * @param $id |
||
| 250 | * @return PersonaHandler |
||
| 251 | */ |
||
| 252 | public function persona($id = null) |
||
| 253 | { |
||
| 254 | if ($this->persona) return $this->persona; |
||
| 255 | |||
| 256 | $this->persona = new PersonaHandler($id ? $id : null); |
||
| 257 | return $this->persona($id ? $id : null); |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Learning Locker API: Journeys |
||
| 262 | * |
||
| 263 | * @return JourneyHandler |
||
| 264 | */ |
||
| 265 | public function journeys() |
||
| 266 | { |
||
| 267 | if ($this->journeys) return $this->journeys; |
||
| 268 | |||
| 269 | $this->journeys = new JourneyHandler; |
||
| 270 | return $this->journeys(); |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Learning Locker API: Journey |
||
| 275 | * |
||
| 276 | * @param $id |
||
| 277 | * @return JourneyHandler |
||
| 278 | */ |
||
| 279 | public function journey($id = null) |
||
| 280 | { |
||
| 281 | if ($this->journey) return $this->journey; |
||
| 282 | |||
| 283 | $this->journey = new JourneyHandler($id ? $id : null); |
||
| 284 | return $this->journey($id ? $id : null); |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Learning Locker API: Journey |
||
| 289 | * |
||
| 290 | * @param $id |
||
| 291 | * @return JourneyHandler |
||
| 292 | */ |
||
| 293 | public function journeyProgress($id = null) |
||
| 294 | { |
||
| 295 | if ($this->journey_progress) return $this->journey_progress; |
||
| 296 | |||
| 297 | $this->journey_progress = new JourneyProgressHandler($id ? $id : null); |
||
| 298 | return $this->journeyProgress($id ? $id : null); |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Learning Locker API: Dashboards API |
||
| 303 | * |
||
| 304 | * @return DashboardHandler |
||
| 305 | */ |
||
| 306 | public function dashboards() |
||
| 307 | { |
||
| 308 | if ($this->dashboards) return $this->dashboards; |
||
| 309 | |||
| 310 | $this->dashboards = new DashboardHandler; |
||
| 311 | return $this->dashboards(); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Learning Locker API: Dashboards API |
||
| 316 | * |
||
| 317 | * @param $id |
||
| 318 | * @return DashboardHandler |
||
| 319 | */ |
||
| 320 | public function dashboard($id = null) |
||
| 321 | { |
||
| 322 | if ($this->dashboard) return $this->dashboard; |
||
| 323 | |||
| 324 | $this->dashboard = new DashboardHandler($id ? $id : null); |
||
| 325 | return $this->dashboard($id ? $id : null); |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Learning Locker API: Downloads |
||
| 330 | * |
||
| 331 | * @return DownloadsHandler |
||
| 332 | */ |
||
| 333 | public function downloads() |
||
| 334 | { |
||
| 335 | if ($this->downloads) return $this->downloads; |
||
| 336 | |||
| 337 | $this->downloads = new DownloadHandler; |
||
| 338 | return $this->downloads(); |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Learning Locker API: Downloads |
||
| 343 | * |
||
| 344 | * @return DownloadsHandler |
||
| 345 | */ |
||
| 346 | public function download($id) |
||
| 347 | { |
||
| 348 | if ($this->download) return $this->download; |
||
| 349 | |||
| 350 | $this->download = new DownloadHandler($id); |
||
| 351 | return $this->download($id); |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Learning Locker API: Statements |
||
| 356 | * |
||
| 357 | * @return StatementHandler |
||
| 358 | */ |
||
| 359 | public function statements() |
||
| 360 | { |
||
| 361 | if ($this->statements) return $this->statements; |
||
| 362 | |||
| 363 | $this->statements = new StatementHandler; |
||
| 364 | return $this->statements(); |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Learning Locker API: Statement |
||
| 369 | * |
||
| 370 | * @param $id |
||
| 371 | * @return StatementHandler |
||
| 372 | */ |
||
| 373 | public function statement($id = null) |
||
| 374 | { |
||
| 375 | if ($this->statement) return $this->statement; |
||
| 376 | |||
| 377 | $this->statement = new StatementHandler($id ?? $id); |
||
| 378 | return $this->statement($id ?? $id); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Learning Locker API: Statements |
||
| 383 | * |
||
| 384 | * @return StatementHandler |
||
| 385 | */ |
||
| 386 | public function statementForwarding($id = null) |
||
| 387 | { |
||
| 388 | if ($this->statement_forwarding) return $this->statement_forwarding; |
||
| 389 | |||
| 390 | $this->statement_forwarding = new StatementForwardingHandler($id ?? $id); |
||
| 391 | return $this->statementForwarding($id ?? $id); |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Learning Locker API: Organisation |
||
| 396 | * |
||
| 397 | * @param $id |
||
| 398 | * @return OrganisationHandler |
||
| 399 | */ |
||
| 400 | public function organisation($id) |
||
| 401 | { |
||
| 402 | if ($this->organisation) return $this->organisation; |
||
| 403 | |||
| 404 | $this->organisation = new OrganisationHandler($id); |
||
| 405 | return $this->organisation($id); |
||
| 406 | |||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Learning Locker API: Visualisations API |
||
| 411 | * |
||
| 412 | * @return VisualisationHandler |
||
| 413 | */ |
||
| 414 | public function visualisations() |
||
| 415 | { |
||
| 416 | if ($this->visualisations) return $this->visualisations; |
||
| 417 | |||
| 418 | $this->visualisations = new VisualisationHandler; |
||
| 419 | return $this->visualisations(); |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Learning Locker API: Visualisations API |
||
| 424 | * |
||
| 425 | * @param integer|null $id |
||
| 426 | * @return VisualisationHandler |
||
| 427 | */ |
||
| 428 | public function visualisation($id = null) |
||
| 429 | { |
||
| 430 | if ($this->visualisation) return $this->visualisation; |
||
| 431 | |||
| 432 | $this->visualisation = new VisualisationHandler($id ? $id : null); |
||
| 433 | return $this->visualisation($id ? $id : null); |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Learning Locker API: Routes |
||
| 438 | * |
||
| 439 | */ |
||
| 440 | public function routes() |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Learning Locker API: Model Access |
||
| 447 | * |
||
| 448 | * @param $model, $id = null |
||
| 449 | */ |
||
| 450 | public function api($model, $id = null) { |
||
| 451 | |||
| 452 | switch (strtolower($model)) { |
||
| 453 | case "clients": |
||
| 454 | $this->clients(); |
||
| 455 | break; |
||
| 456 | case "client": |
||
| 457 | $this->client($id); |
||
| 458 | break; |
||
| 459 | case "user" || "users": |
||
| 460 | $this->users(); |
||
| 461 | break; |
||
| 462 | case "stores" || "store" || "lrs": |
||
| 463 | $this->stores(); |
||
| 464 | break; |
||
| 465 | case "query" || "queries": |
||
| 466 | $this->query(); |
||
| 467 | break; |
||
| 497 | } |
||
| 498 | } |
||
| 499 | |||
| 500 | } |
||
| 501 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.