Conditions | 9 |
Paths | 32 |
Total Lines | 60 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
9 | public function run() |
||
10 | { |
||
11 | $this->myMu = ModuleUpgrader::create(); |
||
|
|||
12 | $html = ''; |
||
13 | foreach (array_keys($this->mu()->getAvailableRecipes()) as $recipeKey) { |
||
14 | $this->mu()->applyRecipe($recipeKey); |
||
15 | $html .= '<h1>List of Tasks in run order for recipe: ' . $recipeKey . '</h1>'; |
||
16 | $count = 0; |
||
17 | $totalCount = count($this->mu()->getListOfTasks()); |
||
18 | $previousStep = ''; |
||
19 | foreach ($this->mu()->getListOfTasks() as $class => $params) { |
||
20 | $properClass = current(explode('-', $class)); |
||
21 | $nameSpacesArray = explode('\\', $class); |
||
22 | $shortClassCode = end($nameSpacesArray); |
||
23 | if (! class_exists($properClass)) { |
||
24 | $properClass = $this->mu()->getDefaultNamespaceForTasks() . '\\' . $properClass; |
||
25 | } |
||
26 | if (class_exists($properClass)) { |
||
27 | $count++; |
||
28 | // $runItNow = $this->mu()->shouldWeRunIt((string) $shortClassCode); |
||
29 | $params['taskName'] = $shortClassCode; |
||
30 | $obj = $properClass::create($this, $params); |
||
31 | if ($obj->getTaskName()) { |
||
32 | $params['taskName'] = $obj->getTaskName(); |
||
33 | } |
||
34 | $reflectionClass = new \ReflectionClass($properClass); |
||
35 | $path = 'https://github.com/sunnysideup/silverstripe-upgrade_to_silverstripe_4/tree/master/src/'; |
||
36 | $path .= str_replace('\\', '/', $reflectionClass->getName()) . '.php'; |
||
37 | $path = str_replace('Sunnysideup/UpgradeToSilverstripe4/', '', $path); |
||
38 | $currentStepCode = $obj->getTaskStepCode(); |
||
39 | $currentStep = $obj->getTaskStep($currentStepCode); |
||
40 | if ($currentStepCode === 's00') { |
||
41 | //do nothing when it is an anytime step |
||
42 | } else { |
||
43 | if ($previousStep !== $currentStep) { |
||
44 | $html .= '<h2>' . $currentStep . '</h2>'; |
||
45 | } |
||
46 | $previousStep = $currentStep; |
||
47 | } |
||
48 | $html .= '<h4>' . $count . '/' . $totalCount . ': ' . $obj->getTitle() . '</h4>'; |
||
49 | $html .= '<p>' . $obj->getDescription() . '<br />'; |
||
50 | $html .= '<strong>Class Code: </strong>' . $class; |
||
51 | $html .= '<br /><strong>Class Name: </strong>'; |
||
52 | $html .= '<a href="' . $path . '">' . $reflectionClass->getShortName() . '</a>'; |
||
53 | $html .= '</p>'; |
||
54 | $obj = $properClass::deleteTask($params); |
||
55 | } else { |
||
56 | user_error($properClass . ' could not be found as class', E_USER_ERROR); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | $dir = $this->mu()->checkIfPathExistsAndCleanItUp(__DIR__ . '/../../docs/en/'); |
||
61 | if ($dir) { |
||
62 | $html = str_replace(' _', ' \_', $html); |
||
63 | file_put_contents( |
||
64 | rtrim($dir, '/') . '/AvailableTasks.md', |
||
65 | $html |
||
66 | ); |
||
67 | } else { |
||
68 | user_error('Coult not find ' . $dir . ' directory'); |
||
69 | } |
||
77 |