Conditions | 11 |
Paths | 16 |
Total Lines | 73 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
116 | protected function execute(InputInterface $input, OutputInterface $output) |
||
117 | { |
||
118 | $configDefaults = new \Vaimo\ComposerPatches\Config\Defaults(); |
||
119 | $defaults = $configDefaults->getPatcherConfig(); |
||
120 | |||
121 | $composer = $this->getComposer(); |
||
122 | |||
123 | $appIO = $this->getIO(); |
||
124 | |||
125 | $isExplicit = $input->getOption('explicit') || $input->getOption('show-reapplies'); |
||
126 | |||
127 | $isDevMode = !$input->getOption('no-dev'); |
||
128 | |||
129 | $behaviourFlags = $this->getBehaviourFlags($input); |
||
130 | $shouldUndo = !$behaviourFlags['redo'] && $behaviourFlags['undo']; |
||
131 | |||
132 | $bootstrapFactory = new \Vaimo\ComposerPatches\Factories\BootstrapFactory($composer, $appIO); |
||
133 | |||
134 | $filters = array( |
||
135 | Patch::SOURCE => $input->getOption('filter'), |
||
136 | Patch::TARGETS => $input->getArgument('targets') |
||
137 | ); |
||
138 | |||
139 | $configFactory = new \Vaimo\ComposerPatches\Factories\ConfigFactory($composer, array( |
||
140 | Config::PATCHER_FORCE_REAPPLY => $behaviourFlags['redo'], |
||
141 | Config::PATCHER_FROM_SOURCE => (bool)$input->getOption('from-source'), |
||
142 | Config::PATCHER_GRACEFUL => (bool)$input->getOption('graceful') |
||
143 | || $behaviourFlags['redo'] |
||
144 | || $behaviourFlags['undo'], |
||
145 | Config::PATCHER_SOURCES => array_fill_keys(array_keys($defaults[Config::PATCHER_SOURCES]), true) |
||
|
|||
146 | )); |
||
147 | |||
148 | if ($behaviourFlags['redo'] && !array_filter($filters)) { |
||
149 | $isExplicit = true; |
||
150 | } |
||
151 | |||
152 | $hasFilers = (bool)array_filter($filters); |
||
153 | |||
154 | if (!$hasFilers && $behaviourFlags['redo']) { |
||
155 | $filters[Patch::SOURCE] = array('*'); |
||
156 | } |
||
157 | |||
158 | $listResolver = $this->createListResolver($behaviourFlags, $filters); |
||
159 | |||
160 | $this->configureEnvironmentForBehaviour($behaviourFlags); |
||
161 | |||
162 | $outputTriggers = $this->resolveOutputTriggers($filters, $isExplicit); |
||
163 | $outputStrategy = new \Vaimo\ComposerPatches\Strategies\OutputStrategy($outputTriggers); |
||
164 | $bootstrap = $bootstrapFactory->create($configFactory, $listResolver, $outputStrategy); |
||
165 | |||
166 | $runtimeUtils = new \Vaimo\ComposerPatches\Utils\RuntimeUtils(); |
||
167 | $lockSanitizer = new \Vaimo\ComposerPatches\Repository\Lock\Sanitizer($appIO); |
||
168 | $repository = $composer->getRepositoryManager()->getLocalRepository(); |
||
169 | |||
170 | $result = $runtimeUtils->executeWithPostAction( |
||
171 | function () use ($shouldUndo, $filters, $bootstrap, $isDevMode) { |
||
172 | if ($shouldUndo && !array_filter($filters)) { |
||
173 | $bootstrap->stripPatches($isDevMode); |
||
174 | |||
175 | return true; |
||
176 | } |
||
177 | |||
178 | return $bootstrap->applyPatches($isDevMode); |
||
179 | }, |
||
180 | function () use ($repository, $lockSanitizer) { |
||
181 | $repository->write(); |
||
182 | $lockSanitizer->sanitize(); |
||
183 | } |
||
184 | ); |
||
185 | |||
186 | $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_INSTALL_CMD, $isDevMode); |
||
187 | |||
188 | return (int)!$result; |
||
189 | } |
||
237 |