| Conditions | 9 |
| Paths | 16 |
| Total Lines | 85 |
| Code Lines | 51 |
| 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 |
||
| 77 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 78 | { |
||
| 79 | $packageName = $input->getArgument('name'); |
||
| 80 | |||
| 81 | $fromSource = $input->getOption('from-source'); |
||
| 82 | $briefMode = $input->getOption('brief'); |
||
| 83 | $version = $input->getOption('release'); |
||
| 84 | $format = $input->getOption('format'); |
||
| 85 | $branch = $input->getOption('branch'); |
||
| 86 | $showUpcoming = $input->getOption('upcoming'); |
||
| 87 | |||
| 88 | $composerRuntime = $this->getComposer(); |
||
| 89 | |||
| 90 | try { |
||
| 91 | $package = $this->resolvePackage($packageName); |
||
|
|
|||
| 92 | } catch (PackageResolverException $exception) { |
||
| 93 | $this->printException($exception, $output); |
||
| 94 | |||
| 95 | return 1; |
||
| 96 | } |
||
| 97 | |||
| 98 | $chLogLoaderFactory = new Factories\Changelog\LoaderFactory($composerRuntime); |
||
| 99 | $chLogLoader = $chLogLoaderFactory->create($fromSource); |
||
| 100 | |||
| 101 | $validator = new \Vaimo\ComposerChangelogs\Validators\ChangelogValidator($chLogLoader, array( |
||
| 102 | 'failure' => '<error>%s</error>', |
||
| 103 | 'success' => '<info>%s</info>' |
||
| 104 | )); |
||
| 105 | |||
| 106 | $result = $validator->validateForPackage($package, $output->getVerbosity()); |
||
| 107 | |||
| 108 | if (!$result()) { |
||
| 109 | array_map(array($output, 'writeln'), $result->getMessages()); |
||
| 110 | |||
| 111 | return 1; |
||
| 112 | } |
||
| 113 | |||
| 114 | $changelog = $chLogLoader->load($package); |
||
| 115 | |||
| 116 | if (!$version) { |
||
| 117 | $version = $this->resolveVersion($changelog, $branch, $showUpcoming); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (!$version || !isset($changelog[$version])) { |
||
| 121 | return 0; |
||
| 122 | } |
||
| 123 | |||
| 124 | $details = $changelog[$version]; |
||
| 125 | |||
| 126 | $detailsResolver = new \Vaimo\ComposerChangelogs\Resolvers\ReleaseDetailsResolver(); |
||
| 127 | |||
| 128 | $generalInfo = $detailsResolver->resolveOverview($details); |
||
| 129 | $groups = $detailsResolver->resolveChangeGroups($details); |
||
| 130 | |||
| 131 | if ($briefMode) { |
||
| 132 | $summary = array_map(function ($key, $group) { |
||
| 133 | return sprintf('%s (%s)', $key, count($group)); |
||
| 134 | }, array_keys($groups), $groups); |
||
| 135 | |||
| 136 | $generalInfo = $detailsResolver->resolveOverview($details); |
||
| 137 | |||
| 138 | $groups = array( |
||
| 139 | 'overview' => $generalInfo['overview'], |
||
| 140 | 'summary' => sprintf('Includes: %s', implode(', ', $summary)) |
||
| 141 | ); |
||
| 142 | } elseif ($generalInfo['overview']) { |
||
| 143 | $groups = array_merge( |
||
| 144 | $groups, |
||
| 145 | array('overview' => $generalInfo['overview']) |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | |||
| 149 | try { |
||
| 150 | $result = $this->generateOutput($groups, $format, $fromSource); |
||
| 151 | } catch (\Exception $exception) { |
||
| 152 | $output->writeln( |
||
| 153 | sprintf('<error>%s</error>', $exception->getMessage()) |
||
| 154 | ); |
||
| 155 | |||
| 156 | return 1; |
||
| 157 | } |
||
| 158 | |||
| 159 | $output->writeln($result); |
||
| 160 | |||
| 161 | return 0; |
||
| 162 | } |
||
| 242 |