Conditions | 9 |
Paths | 192 |
Total Lines | 133 |
Code Lines | 79 |
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 | $pluginConfig = $this->createConfigWithEnabledSources($composer); |
||
110 | |||
111 | |||
112 | $filteredPool = $this->createLoaderPool(); |
||
113 | |||
114 | $packageInfoResolver = new \Vaimo\ComposerPatches\Package\InfoResolver( |
||
115 | $composer->getInstallationManager(), |
||
116 | $composer->getConfig()->get(\Vaimo\ComposerPatches\Composer\ConfigKeys::VENDOR_DIR) |
||
117 | ); |
||
118 | |||
119 | $unfilteredPool = $this->createLoaderPool(array( |
||
120 | 'constraints' => false, |
||
121 | 'platform' => false, |
||
122 | 'local-exclude' => false, |
||
123 | 'root-patch' => false, |
||
124 | 'global-exclude' => false, |
||
125 | 'targets-resolver' => new LoaderComponents\TargetsResolverComponent($packageInfoResolver, true) |
||
126 | )); |
||
127 | |||
128 | $hasFilers = (bool)array_filter($filters); |
||
129 | |||
130 | $listResolver = new ListResolvers\FilteredListResolver($filters); |
||
131 | |||
132 | $loaderFactory = new \Vaimo\ComposerPatches\Factories\PatchesLoaderFactory($composer); |
||
133 | |||
134 | $repository = $composer->getRepositoryManager()->getLocalRepository(); |
||
135 | |||
136 | $filteredLoader = $loaderFactory->create($filteredPool, $pluginConfig, $isDevMode); |
||
137 | $filteredPatches = $filteredLoader->loadFromPackagesRepository($repository); |
||
138 | |||
139 | $queueGenerator = $this->createQueueGenerator($composer, $pluginConfig, $listResolver); |
||
140 | |||
141 | $repoStateGenerator = $this->createStateGenerator($composer); |
||
142 | |||
143 | $repositoryState = $repoStateGenerator->generate($repository); |
||
144 | |||
145 | $applyQueue = $queueGenerator->generateApplyQueue($filteredPatches, $repositoryState); |
||
146 | $removeQueue = $queueGenerator->generateRemovalQueue($applyQueue, $repositoryState); |
||
147 | $applyQueue = array_map('array_filter', $applyQueue); |
||
148 | |||
149 | $patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils(); |
||
150 | |||
151 | $filteredPatches = $patchListUtils->mergeLists( |
||
152 | $filteredPatches, |
||
153 | $removeQueue |
||
154 | ); |
||
155 | |||
156 | if ($withAffected) { |
||
157 | $applyQueue = $patchListUtils->embedInfoToItems( |
||
158 | $applyQueue, |
||
159 | array(PatchDefinition::STATUS => 'affected'), |
||
160 | true |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | $filteredPatches = $patchListUtils->mergeLists( |
||
165 | $filteredPatches, |
||
166 | $patchListUtils->intersectListsByName($applyQueue, $filteredPatches) |
||
167 | ); |
||
168 | |||
169 | $filteredPatches = $patchListUtils->embedInfoToItems( |
||
170 | $filteredPatches, |
||
171 | array(PatchDefinition::STATUS => 'applied'), |
||
172 | true |
||
173 | ); |
||
174 | |||
175 | if ($hasFilers) { |
||
176 | $filteredPatches = $listResolver->resolvePatchesQueue($filteredPatches); |
||
177 | } |
||
178 | |||
179 | $filterUtils = new \Vaimo\ComposerPatches\Utils\FilterUtils(); |
||
180 | |||
181 | if ($statusFilters) { |
||
182 | $statusFilter = $filterUtils->composeRegex($statusFilters, '/'); |
||
183 | |||
184 | $filteredPatches = $patchListUtils->applyDefinitionFilter( |
||
185 | $filteredPatches, |
||
186 | $statusFilter, |
||
187 | PatchDefinition::STATUS |
||
188 | ); |
||
189 | } |
||
190 | |||
191 | $patches = array_filter($filteredPatches); |
||
192 | |||
193 | $shouldAddExcludes = $withExcluded |
||
194 | && (!$statusFilters || preg_match($filterUtils->composeRegex($statusFilters, '/'), 'excluded')); |
||
195 | |||
196 | if ($shouldAddExcludes) { |
||
197 | $unfilteredLoader = $loaderFactory->create($unfilteredPool, $pluginConfig, $isDevMode); |
||
198 | |||
199 | $allPatches = $unfilteredLoader->loadFromPackagesRepository($repository); |
||
200 | |||
201 | $patchesQueue = $listResolver->resolvePatchesQueue($allPatches); |
||
202 | |||
203 | $excludedPatches = $patchListUtils->updateStatuses( |
||
204 | array_filter($patchListUtils->diffListsByPath($patchesQueue, $filteredPatches)), |
||
205 | 'excluded' |
||
206 | ); |
||
207 | |||
208 | $patches = array_replace_recursive( |
||
209 | $patches, |
||
210 | $patchListUtils->updateStatuses($excludedPatches, 'excluded') |
||
211 | ); |
||
212 | |||
213 | array_walk($patches, function (array &$group) { |
||
214 | ksort($group); |
||
215 | }, $patches); |
||
216 | } |
||
217 | |||
218 | if ($beBrief) { |
||
219 | $patches = $patchListUtils->embedInfoToItems($patches, array( |
||
220 | PatchDefinition::LABEL => false, |
||
221 | PatchDefinition::OWNER => false |
||
222 | )); |
||
223 | } |
||
224 | |||
225 | $this->generateOutput($output, $patches); |
||
226 | } |
||
331 |