Conditions | 4 |
Paths | 6 |
Total Lines | 70 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
31 | public function runActualTask($params = []): ?string |
||
32 | { |
||
33 | //project composer.json |
||
34 | // - app/src/... |
||
35 | // - app2/src/... |
||
36 | // DO FOR BOTH |
||
37 | //module composor.json |
||
38 | // ONLY FOR module |
||
39 | $baseCommands = ' |
||
40 | if(! isset($data["autoload"])) { |
||
41 | $data["autoload"] = []; |
||
42 | } |
||
43 | if(! isset($data["autoload"]["psr-4"])) { |
||
44 | $data["autoload"]["psr-4"] = []; |
||
45 | } |
||
46 | '; |
||
47 | $addPage = ''; |
||
48 | if ($this->mu()->getIsModuleUpgrade()) { |
||
49 | $addPage = ' |
||
50 | if(! isset($data["autoload"]["files"])) { |
||
51 | $data["autoload"]["files"] = [ |
||
52 | "app/src/Page.php", |
||
53 | "app/src/PageController.php" |
||
54 | ]; |
||
55 | }'; |
||
56 | } |
||
57 | |||
58 | $codeDirs = $this->mu()->findNameSpaceAndCodeDirs(); |
||
59 | $webRootLocation = $this->mu()->getWebRootDirLocation(); |
||
60 | $command = $baseCommands . $addPage; |
||
61 | $comment = 'Adding autoload Page and Page controller details in ' . $webRootLocation . '/composer.json'; |
||
62 | ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine( |
||
63 | $webRootLocation, |
||
64 | $command, |
||
65 | $comment |
||
66 | ); |
||
67 | foreach ($codeDirs as $baseNameSpace => $codeDir) { |
||
68 | $location = trim(str_replace($webRootLocation, '', $codeDir), '/') . '/'; |
||
69 | //update webroot composer file |
||
70 | //location: |
||
71 | $command = $baseCommands . ' |
||
72 | $data["autoload"]["psr-4"]["' . $this->doubleSlash($baseNameSpace) . '"] = "' . $location . '";'; |
||
73 | $comment = 'Adding autoload psr-4 details in ' . |
||
74 | $webRootLocation . '/composer.json: ' . |
||
75 | $baseNameSpace . ' => ' . $location; |
||
76 | ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine( |
||
77 | $webRootLocation, |
||
78 | $command, |
||
79 | $comment |
||
80 | ); |
||
81 | if ($this->mu()->getIsModuleUpgrade()) { |
||
82 | $moduleLocation = dirname($codeDir); |
||
83 | $location = trim(basename($codeDir), '/') . '/'; |
||
84 | $command = $baseCommands . ' |
||
85 | $data["autoload"]["psr-4"]["' . |
||
86 | $this->doubleSlash($baseNameSpace) . '"] = "' . |
||
87 | ltrim($location, '/') . '";'; |
||
88 | $comment = 'Adding autoload psr-4 details in ' . |
||
89 | $moduleLocation . '/composer.json: ' . |
||
90 | $baseNameSpace . ' => ' . $location; |
||
91 | ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine( |
||
92 | $moduleLocation, |
||
93 | $command, |
||
94 | $comment |
||
95 | ); |
||
96 | } |
||
97 | } |
||
98 | Composer::inst($this->mu()) |
||
99 | ->DumpAutoload(); |
||
100 | return null; |
||
101 | } |
||
113 |