Conditions | 9 |
Paths | 24 |
Total Lines | 71 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
12 | public function up() |
||
13 | { |
||
14 | // Allow Custom .ENV |
||
15 | $custom_base_path = getenv('LCI_ORCHESTRATOR_BASE_PATH'); |
||
16 | $custom_base_url = getenv('LCI_ORCHESTRATOR_BASE_URL'); |
||
17 | $custom_vendor_path = getenv('LCI_ORCHESTRATOR_VENDOR_PATH'); |
||
18 | |||
19 | // 1. MODX namespace |
||
20 | $orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator'); |
||
21 | |||
22 | if (!$orchestratorNamespace) { |
||
23 | /** @var \modNamespace $orchestratorNamespace */ |
||
24 | $orchestratorNamespace = $this->modx->newObject('modNamespace'); |
||
25 | $orchestratorNamespace->set('name', 'orchestrator'); |
||
26 | $orchestratorNamespace->set('path', '{core_path}vendor/'); |
||
27 | $orchestratorNamespace->set('assets_path', '{assets_path}orchestrator/'); |
||
28 | |||
29 | if ($orchestratorNamespace->save()) { |
||
30 | $this->blender->outSuccess('The modNamespace orchestrator has been created'); |
||
31 | } else { |
||
32 | $this->blender->out('The modNamespace orchestrator was not created', true); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | // 2. Media source |
||
37 | $orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator'); |
||
38 | $saved = $orchestratorMediaSource |
||
39 | ->setFieldDescription('Orchestrator packages') |
||
40 | ->setPropertyBasePath(!$custom_base_path ? 'core/vendor/' : $custom_base_path) |
||
41 | ->setPropertyBaseUrl(!$custom_base_url ? 'core/vendor/' : $custom_base_url) |
||
42 | ->blend(); |
||
43 | |||
44 | if ($saved) { |
||
45 | $this->blender->outSuccess('orchestrator MediaSource has been installed'); |
||
46 | } else { |
||
47 | $this->blender->out('orchestrator MediaSource was not installed', true); |
||
48 | } |
||
49 | |||
50 | // 3. System setting |
||
51 | /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */ |
||
52 | $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path'); |
||
53 | $saved = $systemSetting |
||
54 | ->setSeedsDir($this->getSeedsDir()) |
||
55 | ->setFieldValue(!$custom_vendor_path ? MODX_CORE_PATH.'vendor/' : $custom_vendor_path) |
||
56 | ->setFieldArea('Composer') |
||
57 | ->setFieldNamespace('orchestrator') |
||
58 | ->blend(); |
||
59 | |||
60 | if ($saved) { |
||
61 | $this->blender->outSuccess('orchestrator.vendor_path System Setting has been created'); |
||
62 | } else { |
||
63 | $this->blender->outError('orchestrator.vendor_path System Setting was not created'); |
||
64 | } |
||
65 | |||
66 | // 4. plugin |
||
67 | $plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader'); |
||
68 | |||
69 | $saved = $plugin |
||
70 | ->setFieldCategory('Orchestrator') |
||
71 | ->setFieldDescription('Will load the composer autoloader.php file inside of MODX') |
||
72 | ->setAsStatic('lci/orchestrator/src/elements/plugins/requireComposerAutoloader.php', 'orchestrator') |
||
73 | ->attachOnEvent('OnInitCulture') |
||
74 | ->blend(); |
||
75 | |||
76 | if ($saved) { |
||
77 | $this->blender->outSuccess('requireComposerAutoloader Plugin has been installed'); |
||
78 | } else { |
||
79 | $this->blender->outError('requireComposerAutoloader Plugin has been installed'); |
||
80 | } |
||
81 | |||
82 | $this->modx->cacheManager->refresh(); |
||
83 | } |
||
168 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.