Conditions | 9 |
Paths | 192 |
Total Lines | 152 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
93 | protected function execute(InputInterface $input, OutputInterface $output) |
||
94 | { |
||
95 | $composer = $this->getComposer(); |
||
96 | |||
97 | $isDevMode = !$input->getOption('no-dev'); |
||
98 | $withExcluded = $input->getOption('excluded') || $input->getOption('with-excludes'); |
||
99 | $withAffected = $input->getOption('with-affected'); |
||
100 | $beBrief = $input->getOption('brief'); |
||
101 | |||
102 | $filters = array( |
||
103 | PatchDefinition::SOURCE => $input->getOption('filter'), |
||
104 | PatchDefinition::TARGETS => $input->getArgument('targets') |
||
105 | ); |
||
106 | |||
107 | $statusFilters = array_map('strtolower', $input->getOption('status')); |
||
|
|||
108 | |||
109 | $configDefaults = new \Vaimo\ComposerPatches\Config\Defaults(); |
||
110 | |||
111 | $defaultValues = $configDefaults->getPatcherConfig(); |
||
112 | |||
113 | $sourceKeys = array_keys($defaultValues[Config::PATCHER_SOURCES]); |
||
114 | |||
115 | $pluginConfig = array( |
||
116 | Config::PATCHER_SOURCES => array_fill_keys($sourceKeys, true) |
||
117 | ); |
||
118 | |||
119 | $filterUtils = new \Vaimo\ComposerPatches\Utils\FilterUtils(); |
||
120 | $patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils(); |
||
121 | |||
122 | $configFactory = new \Vaimo\ComposerPatches\Factories\ConfigFactory($composer); |
||
123 | $configInstance = $configFactory->create(array($pluginConfig)); |
||
124 | |||
125 | $filteredPool = $this->createLoaderPool(); |
||
126 | |||
127 | $installationManager = $composer->getInstallationManager(); |
||
128 | $composerConfig = clone $composer->getConfig(); |
||
129 | |||
130 | $vendorRoot = $composerConfig->get(\Vaimo\ComposerPatches\Composer\ConfigKeys::VENDOR_DIR); |
||
131 | |||
132 | $packageInfoResolver = new \Vaimo\ComposerPatches\Package\InfoResolver( |
||
133 | $installationManager, |
||
134 | $vendorRoot |
||
135 | ); |
||
136 | |||
137 | $unfilteredPool = $this->createLoaderPool(array( |
||
138 | 'constraints' => false, |
||
139 | 'platform' => false, |
||
140 | 'local-exclude' => false, |
||
141 | 'root-patch' => false, |
||
142 | 'global-exclude' => false, |
||
143 | 'targets-resolver' => new LoaderComponents\TargetsResolverComponent($packageInfoResolver, true) |
||
144 | )); |
||
145 | |||
146 | $hasFilers = (bool)array_filter($filters); |
||
147 | |||
148 | $listResolver = new ListResolvers\FilteredListResolver($filters); |
||
149 | |||
150 | $loaderFactory = new \Vaimo\ComposerPatches\Factories\PatchesLoaderFactory($composer); |
||
151 | $packageCollector = new \Vaimo\ComposerPatches\Package\Collector( |
||
152 | array($composer->getPackage()) |
||
153 | ); |
||
154 | |||
155 | $repository = $composer->getRepositoryManager()->getLocalRepository(); |
||
156 | |||
157 | $filteredLoader = $loaderFactory->create($filteredPool, $configInstance, $isDevMode); |
||
158 | $filteredPatches = $filteredLoader->loadFromPackagesRepository($repository); |
||
159 | |||
160 | $queueGenerator = $this->createQueueGenerator($composer, $configInstance, $listResolver); |
||
161 | |||
162 | $repoStateGenerator = new \Vaimo\ComposerPatches\Repository\StateGenerator( |
||
163 | $packageCollector |
||
164 | ); |
||
165 | |||
166 | $repositoryState = $repoStateGenerator->generate($repository); |
||
167 | |||
168 | $applyQueue = $queueGenerator->generateApplyQueue($filteredPatches, $repositoryState); |
||
169 | $removeQueue = $queueGenerator->generateRemovalQueue($applyQueue, $repositoryState); |
||
170 | $applyQueue = array_map('array_filter', $applyQueue); |
||
171 | |||
172 | $filteredPatches = $patchListUtils->mergeLists( |
||
173 | $filteredPatches, |
||
174 | $removeQueue |
||
175 | ); |
||
176 | |||
177 | if ($withAffected) { |
||
178 | $applyQueue = $patchListUtils->embedInfoToItems( |
||
179 | $applyQueue, |
||
180 | array(PatchDefinition::STATUS => 'affected'), |
||
181 | true |
||
182 | ); |
||
183 | } |
||
184 | |||
185 | $filteredPatches = $patchListUtils->mergeLists( |
||
186 | $filteredPatches, |
||
187 | $patchListUtils->intersectListsByName($applyQueue, $filteredPatches) |
||
188 | ); |
||
189 | |||
190 | $filteredPatches = $patchListUtils->embedInfoToItems( |
||
191 | $filteredPatches, |
||
192 | array(PatchDefinition::STATUS => 'applied'), |
||
193 | true |
||
194 | ); |
||
195 | |||
196 | if ($hasFilers) { |
||
197 | $filteredPatches = $listResolver->resolvePatchesQueue($filteredPatches); |
||
198 | } |
||
199 | |||
200 | if ($statusFilters) { |
||
201 | $statusFilter = $filterUtils->composeRegex($statusFilters, '/'); |
||
202 | |||
203 | $filteredPatches = $patchListUtils->applyDefinitionFilter( |
||
204 | $filteredPatches, |
||
205 | $statusFilter, |
||
206 | PatchDefinition::STATUS |
||
207 | ); |
||
208 | } |
||
209 | |||
210 | $patches = array_filter($filteredPatches); |
||
211 | |||
212 | $shouldAddExcludes = $withExcluded |
||
213 | && (!$statusFilters || preg_match($filterUtils->composeRegex($statusFilters, '/'), 'excluded')); |
||
214 | |||
215 | if ($shouldAddExcludes) { |
||
216 | $unfilteredLoader = $loaderFactory->create($unfilteredPool, $configInstance, $isDevMode); |
||
217 | |||
218 | $allPatches = $unfilteredLoader->loadFromPackagesRepository($repository); |
||
219 | |||
220 | $patchesQueue = $listResolver->resolvePatchesQueue($allPatches); |
||
221 | |||
222 | $excludedPatches = $patchListUtils->updateStatuses( |
||
223 | array_filter($patchListUtils->diffListsByPath($patchesQueue, $filteredPatches)), |
||
224 | 'excluded' |
||
225 | ); |
||
226 | |||
227 | $patches = array_replace_recursive( |
||
228 | $patches, |
||
229 | $patchListUtils->updateStatuses($excludedPatches, 'excluded') |
||
230 | ); |
||
231 | |||
232 | array_walk($patches, function (array &$group) { |
||
233 | ksort($group); |
||
234 | }, $patches); |
||
235 | } |
||
236 | |||
237 | if ($beBrief) { |
||
238 | $patches = $patchListUtils->embedInfoToItems($patches, array( |
||
239 | PatchDefinition::LABEL => false, |
||
240 | PatchDefinition::OWNER => false |
||
241 | )); |
||
242 | } |
||
243 | |||
244 | $this->generateOutput($output, $patches); |
||
245 | } |
||
317 |