Conditions | 5 |
Paths | 8 |
Total Lines | 75 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
73 | public function loadConfiguration() |
||
74 | { |
||
75 | // Get container builder |
||
76 | $builder = $this->getContainerBuilder(); |
||
77 | // Get extension configuration |
||
78 | $configuration = $this->getConfig($this->defaults); |
||
79 | |||
80 | /** |
||
81 | * Load packages configuration |
||
82 | */ |
||
83 | |||
84 | $builder->parameters['packages'] = []; |
||
85 | |||
86 | if (is_file($configuration['dirs']['configDir'] . DIRECTORY_SEPARATOR . 'packages.php')) { |
||
87 | $packages = require $configuration['dirs']['configDir'] . DIRECTORY_SEPARATOR . 'packages.php'; |
||
88 | |||
89 | foreach ($packages as $name => $data) { |
||
90 | $builder->parameters['packages'][$name] = $data; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Register services |
||
96 | */ |
||
97 | |||
98 | $builder->addDefinition($this->prefix('loader')) |
||
99 | ->setClass(Loaders\Loader::CLASS_NAME, [ |
||
100 | 'packageFiles' => $configuration['loader']['packageFiles'], |
||
101 | 'metadataSources' => $configuration['sources'], |
||
102 | 'vendorDir' => $configuration['dirs']['vendorDir'], |
||
103 | ]) |
||
104 | ->addTag('cms.packages'); |
||
105 | |||
106 | $repository = $builder->addDefinition($this->prefix('repository')) |
||
107 | ->setClass(Repository\Repository::CLASS_NAME) |
||
108 | ->addTag('cms.packages'); |
||
109 | |||
110 | if ($configuration['path']) { |
||
111 | $repository->addSetup('addPath', [$configuration['path']]); |
||
112 | } |
||
113 | |||
114 | $builder->addDefinition($this->prefix('manager')) |
||
115 | ->setClass(Packages\PackagesManager::CLASS_NAME, [ |
||
116 | 'vendorDir' => $configuration['dirs']['vendorDir'], |
||
117 | 'configDir' => $configuration['dirs']['configDir'], |
||
118 | ]) |
||
119 | ->addTag('cms.packages'); |
||
120 | |||
121 | $builder->addDefinition($this->prefix('pathResolver')) |
||
122 | ->setClass(Helpers\PathResolver::CLASS_NAME) |
||
123 | ->addTag('cms.packages'); |
||
124 | |||
125 | $builder->addDefinition($this->prefix('scripts.configuration')) |
||
126 | ->setClass(Packages\Scripts\ConfigurationScript::CLASS_NAME, [ |
||
127 | 'configDir' => $configuration['dirs']['configDir'], |
||
128 | 'configFile' => $configuration['configFile'], |
||
129 | ]) |
||
130 | ->addTag('cms.packages'); |
||
131 | |||
132 | // Define all console commands |
||
133 | $commands = [ |
||
134 | 'packagesSync' => Commands\SyncCommand::class, |
||
135 | 'packagesList' => Commands\ListCommand::class, |
||
136 | 'packageEnable' => Commands\EnableCommand::class, |
||
137 | 'packageDisable' => Commands\DisableCommand::class, |
||
138 | 'packageInstall' => Commands\InstallCommand::class, |
||
139 | 'packageUninstall' => Commands\UninstallCommand::class, |
||
140 | ]; |
||
141 | |||
142 | foreach ($commands as $name => $cmd) { |
||
143 | $builder->addDefinition($this->prefix('commands' . lcfirst($name))) |
||
144 | ->setClass($cmd) |
||
145 | ->addTag(Console\DI\ConsoleExtension::TAG_COMMAND); |
||
146 | } |
||
147 | } |
||
148 | |||
178 |