| Total Complexity | 80 |
| Total Lines | 679 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Extension 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 Extension, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class Extension extends AbstractEntity |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Category index for distributions |
||
| 31 | */ |
||
| 32 | const DISTRIBUTION_CATEGORY = 10; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Contains default categories. |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected static $defaultCategories = [ |
||
| 40 | 0 => 'be', |
||
| 41 | 1 => 'module', |
||
| 42 | 2 => 'fe', |
||
| 43 | 3 => 'plugin', |
||
| 44 | 4 => 'misc', |
||
| 45 | 5 => 'services', |
||
| 46 | 6 => 'templates', |
||
| 47 | 8 => 'doc', |
||
| 48 | 9 => 'example', |
||
| 49 | self::DISTRIBUTION_CATEGORY => 'distribution' |
||
| 50 | ]; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Contains default states. |
||
| 54 | * |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected static $defaultStates = [ |
||
| 58 | 0 => 'alpha', |
||
| 59 | 1 => 'beta', |
||
| 60 | 2 => 'stable', |
||
| 61 | 3 => 'experimental', |
||
| 62 | 4 => 'test', |
||
| 63 | 5 => 'obsolete', |
||
| 64 | 6 => 'excludeFromUpdates', |
||
| 65 | 7 => 'deprecated', |
||
| 66 | 999 => 'n/a' |
||
| 67 | ]; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $extensionKey = ''; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | protected $version = ''; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int |
||
| 81 | */ |
||
| 82 | protected $integerVersion = 0; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $title = ''; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $description = ''; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var int |
||
| 96 | */ |
||
| 97 | protected $state = 0; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var int |
||
| 101 | */ |
||
| 102 | protected $category = 0; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var \DateTime |
||
| 106 | */ |
||
| 107 | protected $lastUpdated; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | protected $updateComment = ''; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string |
||
| 116 | */ |
||
| 117 | protected $authorName = ''; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | protected $authorEmail = ''; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var bool |
||
| 126 | */ |
||
| 127 | protected $currentVersion = false; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var string |
||
| 131 | */ |
||
| 132 | protected $md5hash = ''; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var int |
||
| 136 | */ |
||
| 137 | protected $reviewState; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var int |
||
| 141 | */ |
||
| 142 | protected $alldownloadcounter; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var string |
||
| 146 | */ |
||
| 147 | protected $serializedDependencies = ''; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var \SplObjectStorage<Dependency> |
||
| 151 | */ |
||
| 152 | protected $dependencies; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var string |
||
| 156 | */ |
||
| 157 | protected $documentationLink = ''; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var string |
||
| 161 | */ |
||
| 162 | protected $distributionImage = ''; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var string |
||
| 166 | */ |
||
| 167 | protected $remote; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @internal |
||
| 171 | * @var int |
||
| 172 | */ |
||
| 173 | protected $position = 0; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $authorEmail |
||
| 177 | */ |
||
| 178 | public function setAuthorEmail($authorEmail) |
||
| 179 | { |
||
| 180 | $this->authorEmail = $authorEmail; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getAuthorEmail() |
||
| 187 | { |
||
| 188 | return $this->authorEmail; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $authorName |
||
| 193 | */ |
||
| 194 | public function setAuthorName($authorName) |
||
| 195 | { |
||
| 196 | $this->authorName = $authorName; |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function getAuthorName() |
||
| 203 | { |
||
| 204 | return $this->authorName; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param int $category |
||
| 209 | */ |
||
| 210 | public function setCategory($category) |
||
| 211 | { |
||
| 212 | $this->category = $category; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return int |
||
| 217 | */ |
||
| 218 | public function getCategory() |
||
| 219 | { |
||
| 220 | return $this->category; |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get Category String |
||
| 225 | * |
||
| 226 | * @return string |
||
| 227 | */ |
||
| 228 | public function getCategoryString() |
||
| 229 | { |
||
| 230 | $categoryString = ''; |
||
| 231 | if (isset(self::$defaultCategories[$this->getCategory()])) { |
||
| 232 | $categoryString = self::$defaultCategories[$this->getCategory()]; |
||
| 233 | } |
||
| 234 | return $categoryString; |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Returns category index from a given string or an integer. |
||
| 239 | * Fallback to 4 - 'misc' in case string is not found or integer ist out of range. |
||
| 240 | * |
||
| 241 | * @param string|int $category Category string or integer |
||
| 242 | * @return int Valid category index |
||
| 243 | */ |
||
| 244 | public function getCategoryIndexFromStringOrNumber($category) |
||
| 245 | { |
||
| 246 | $categoryIndex = 4; |
||
| 247 | if (MathUtility::canBeInterpretedAsInteger($category)) { |
||
| 248 | $categoryIndex = (int)$category; |
||
| 249 | if ($categoryIndex < 0 || $categoryIndex > 10) { |
||
| 250 | $categoryIndex = 4; |
||
| 251 | } |
||
| 252 | } elseif (is_string($category)) { |
||
| 253 | $categoryIndex = array_search($category, self::$defaultCategories); |
||
| 254 | if ($categoryIndex === false) { |
||
| 255 | $categoryIndex = 4; |
||
| 256 | } |
||
| 257 | } |
||
| 258 | return $categoryIndex; |
||
|
|
|||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param string $description |
||
| 263 | */ |
||
| 264 | public function setDescription($description) |
||
| 265 | { |
||
| 266 | $this->description = $description; |
||
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getDescription() |
||
| 273 | { |
||
| 274 | return $this->description; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string $extensionKey |
||
| 279 | */ |
||
| 280 | public function setExtensionKey($extensionKey) |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @return string |
||
| 287 | */ |
||
| 288 | public function getExtensionKey() |
||
| 289 | { |
||
| 290 | return $this->extensionKey; |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param \DateTime $lastUpdated |
||
| 295 | */ |
||
| 296 | public function setLastUpdated(\DateTime $lastUpdated) |
||
| 297 | { |
||
| 298 | $this->lastUpdated = $lastUpdated; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return \DateTime |
||
| 303 | */ |
||
| 304 | public function getLastUpdated() |
||
| 305 | { |
||
| 306 | return $this->lastUpdated; |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param int $state |
||
| 311 | */ |
||
| 312 | public function setState($state) |
||
| 313 | { |
||
| 314 | $this->state = $state; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @return int |
||
| 319 | */ |
||
| 320 | public function getState() |
||
| 321 | { |
||
| 322 | return $this->state; |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Get State string |
||
| 327 | * |
||
| 328 | * @return string |
||
| 329 | */ |
||
| 330 | public function getStateString() |
||
| 331 | { |
||
| 332 | $stateString = ''; |
||
| 333 | if (isset(self::$defaultStates[$this->getState()])) { |
||
| 334 | $stateString = self::$defaultStates[$this->getState()]; |
||
| 335 | } |
||
| 336 | return $stateString; |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Returns either array with all default states or index/title |
||
| 341 | * of a state entry. |
||
| 342 | * |
||
| 343 | * @param mixed $state state title or state index |
||
| 344 | * @return mixed |
||
| 345 | */ |
||
| 346 | public function getDefaultState($state = null) |
||
| 347 | { |
||
| 348 | $defaultState = ''; |
||
| 349 | if ($state === null) { |
||
| 350 | $defaultState = self::$defaultStates; |
||
| 351 | } else { |
||
| 352 | if (is_string($state)) { |
||
| 353 | $stateIndex = array_search(strtolower($state), self::$defaultStates); |
||
| 354 | if ($stateIndex === false) { |
||
| 355 | // default state |
||
| 356 | $stateIndex = 999; |
||
| 357 | } |
||
| 358 | $defaultState = $stateIndex; |
||
| 359 | } else { |
||
| 360 | if (is_int($state) && $state >= 0) { |
||
| 361 | if (array_key_exists($state, self::$defaultStates)) { |
||
| 362 | $stateTitle = self::$defaultStates[$state]; |
||
| 363 | } else { |
||
| 364 | // default state |
||
| 365 | $stateTitle = 'n/a'; |
||
| 366 | } |
||
| 367 | $defaultState = $stateTitle; |
||
| 368 | } |
||
| 369 | } |
||
| 370 | } |
||
| 371 | return $defaultState; |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @param string $title |
||
| 376 | */ |
||
| 377 | public function setTitle($title) |
||
| 378 | { |
||
| 379 | $this->title = $title; |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | public function getTitle() |
||
| 386 | { |
||
| 387 | return $this->title; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @param string $updateComment |
||
| 392 | */ |
||
| 393 | public function setUpdateComment($updateComment) |
||
| 394 | { |
||
| 395 | $this->updateComment = $updateComment; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | public function getUpdateComment() |
||
| 402 | { |
||
| 403 | return $this->updateComment; |
||
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @param string $version |
||
| 408 | */ |
||
| 409 | public function setVersion($version) |
||
| 410 | { |
||
| 411 | $this->version = $version; |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @return string |
||
| 416 | */ |
||
| 417 | public function getVersion() |
||
| 418 | { |
||
| 419 | return $this->version; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @param bool $currentVersion |
||
| 424 | */ |
||
| 425 | public function setCurrentVersion($currentVersion) |
||
| 426 | { |
||
| 427 | $this->currentVersion = $currentVersion; |
||
| 428 | } |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @return bool |
||
| 432 | */ |
||
| 433 | public function getCurrentVersion() |
||
| 434 | { |
||
| 435 | return $this->currentVersion; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @param string $md5hash |
||
| 440 | */ |
||
| 441 | public function setMd5hash($md5hash) |
||
| 442 | { |
||
| 443 | $this->md5hash = $md5hash; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | public function getMd5hash() |
||
| 450 | { |
||
| 451 | return $this->md5hash; |
||
| 452 | } |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Possible install paths |
||
| 456 | * |
||
| 457 | * @static |
||
| 458 | * @return array |
||
| 459 | */ |
||
| 460 | public static function returnInstallPaths() |
||
| 461 | { |
||
| 462 | $installPaths = [ |
||
| 463 | 'System' => Environment::getFrameworkBasePath() . '/', |
||
| 464 | 'Global' => Environment::getBackendPath() . '/ext/', |
||
| 465 | 'Local' => Environment::getExtensionsPath() . '/' |
||
| 466 | ]; |
||
| 467 | return $installPaths; |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Allowed install paths |
||
| 472 | * |
||
| 473 | * @static |
||
| 474 | * @return array |
||
| 475 | */ |
||
| 476 | public static function returnAllowedInstallPaths() |
||
| 477 | { |
||
| 478 | $installPaths = self::returnInstallPaths(); |
||
| 479 | if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall'])) { |
||
| 480 | unset($installPaths['Global']); |
||
| 481 | } |
||
| 482 | if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowLocalInstall'])) { |
||
| 483 | unset($installPaths['Local']); |
||
| 484 | } |
||
| 485 | return $installPaths; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Allowed install names: System, Global, Local |
||
| 490 | * |
||
| 491 | * @static |
||
| 492 | * @return array |
||
| 493 | */ |
||
| 494 | public static function returnAllowedInstallTypes() |
||
| 495 | { |
||
| 496 | $installPaths = self::returnAllowedInstallPaths(); |
||
| 497 | return array_keys($installPaths); |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @param string $dependencies |
||
| 502 | */ |
||
| 503 | public function setSerializedDependencies($dependencies) |
||
| 504 | { |
||
| 505 | $this->serializedDependencies = $dependencies; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @return string |
||
| 510 | */ |
||
| 511 | public function getSerializedDependencies() |
||
| 512 | { |
||
| 513 | return $this->serializedDependencies; |
||
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @param \SplObjectStorage<Dependency> $dependencies |
||
| 518 | */ |
||
| 519 | public function setDependencies($dependencies) |
||
| 520 | { |
||
| 521 | $this->dependencies = $dependencies; |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @return \SplObjectStorage<Dependency> |
||
| 526 | */ |
||
| 527 | public function getDependencies() |
||
| 528 | { |
||
| 529 | if (!is_object($this->dependencies)) { |
||
| 530 | $this->setDependencies($this->convertDependenciesToObjects($this->getSerializedDependencies())); |
||
| 531 | } |
||
| 532 | return $this->dependencies; |
||
| 533 | } |
||
| 534 | |||
| 535 | public function getTypo3Dependency(): ?Dependency |
||
| 536 | { |
||
| 537 | foreach ($this->getDependencies() as $dependency) { |
||
| 538 | if ($dependency->getIdentifier() === 'typo3') { |
||
| 539 | return $dependency; |
||
| 540 | } |
||
| 541 | } |
||
| 542 | return null; |
||
| 543 | } |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @param Dependency $dependency |
||
| 547 | */ |
||
| 548 | public function addDependency(Dependency $dependency) |
||
| 549 | { |
||
| 550 | $this->dependencies->attach($dependency); |
||
| 551 | } |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @param int $integerVersion |
||
| 555 | */ |
||
| 556 | public function setIntegerVersion($integerVersion) |
||
| 557 | { |
||
| 558 | $this->integerVersion = $integerVersion; |
||
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * @return int |
||
| 563 | */ |
||
| 564 | public function getIntegerVersion() |
||
| 565 | { |
||
| 566 | return $this->integerVersion; |
||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * @param int $reviewState |
||
| 571 | */ |
||
| 572 | public function setReviewState($reviewState) |
||
| 573 | { |
||
| 574 | $this->reviewState = $reviewState; |
||
| 575 | } |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @return int |
||
| 579 | */ |
||
| 580 | public function getReviewState() |
||
| 581 | { |
||
| 582 | return $this->reviewState; |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * @param int $position |
||
| 587 | */ |
||
| 588 | public function setPosition($position) |
||
| 589 | { |
||
| 590 | $this->position = $position; |
||
| 591 | } |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @return int |
||
| 595 | */ |
||
| 596 | public function getPosition() |
||
| 599 | } |
||
| 600 | |||
| 601 | /** |
||
| 602 | * @param int $alldownloadcounter |
||
| 603 | */ |
||
| 604 | public function setAlldownloadcounter($alldownloadcounter) |
||
| 605 | { |
||
| 606 | $this->alldownloadcounter = $alldownloadcounter; |
||
| 607 | } |
||
| 608 | |||
| 609 | /** |
||
| 610 | * @return int |
||
| 611 | */ |
||
| 612 | public function getAlldownloadcounter() |
||
| 613 | { |
||
| 614 | return $this->alldownloadcounter; |
||
| 615 | } |
||
| 616 | |||
| 617 | /** |
||
| 618 | * @return string |
||
| 619 | */ |
||
| 620 | public function getDocumentationLink(): string |
||
| 621 | { |
||
| 622 | return $this->documentationLink; |
||
| 623 | } |
||
| 624 | |||
| 625 | /** |
||
| 626 | * @param string $documentationLink |
||
| 627 | */ |
||
| 628 | public function setDocumentationLink(string $documentationLink): void |
||
| 629 | { |
||
| 630 | $this->documentationLink = $documentationLink; |
||
| 631 | } |
||
| 632 | |||
| 633 | public function getRemoteIdentifier(): string |
||
| 634 | { |
||
| 635 | return $this->remote; |
||
| 636 | } |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Map a legacy extension array to an object |
||
| 640 | * |
||
| 641 | * @param array $extensionArray |
||
| 642 | * @return Extension |
||
| 643 | */ |
||
| 644 | public static function createFromExtensionArray(array $extensionArray): self |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Converts string dependencies to an object storage of dependencies |
||
| 663 | * |
||
| 664 | * @param string $dependencies |
||
| 665 | * @return \SplObjectStorage<Dependency> |
||
| 666 | */ |
||
| 667 | protected function convertDependenciesToObjects(string $dependencies): \SplObjectStorage |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @param string $distributionImage |
||
| 694 | */ |
||
| 695 | public function setDistributionImage(string $distributionImage): void |
||
| 696 | { |
||
| 697 | $this->distributionImage = $distributionImage; |
||
| 698 | } |
||
| 699 | |||
| 700 | /** |
||
| 701 | * @return string |
||
| 702 | */ |
||
| 703 | public function getDistributionImage(): string |
||
| 704 | { |
||
| 705 | return $this->distributionImage; |
||
| 706 | } |
||
| 707 | } |
||
| 708 |