| Conditions | 9 |
| Paths | 17 |
| Total Lines | 68 |
| Code Lines | 38 |
| 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 |
||
| 73 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 74 | { |
||
| 75 | $packageName = $input->getArgument('name'); |
||
| 76 | $fromSource = $input->getOption('from-source'); |
||
| 77 | $format = $input->getOption('format'); |
||
| 78 | $branch = $input->getOption('branch'); |
||
| 79 | $segmentsCount = $input->getOption('segments'); |
||
| 80 | |||
| 81 | $showUpcoming = $input->getOption('upcoming'); |
||
| 82 | $showTip = $input->getOption('tip'); |
||
| 83 | |||
| 84 | $composerRuntime = $this->getComposer(); |
||
| 85 | |||
| 86 | try { |
||
| 87 | $package = $this->resolvePackage(is_string($packageName) ? $packageName : ''); |
||
| 88 | } catch (PackageResolverException $exception) { |
||
| 89 | $this->printException($exception, $output); |
||
| 90 | |||
| 91 | return 1; |
||
| 92 | } |
||
| 93 | |||
| 94 | $chLogLoaderFactory = new Factories\Changelog\LoaderFactory($composerRuntime); |
||
| 95 | $chLogLoader = $chLogLoaderFactory->create($fromSource); |
||
| 96 | |||
| 97 | $validator = new \Vaimo\ComposerChangelogs\Validators\ChangelogValidator($chLogLoader, array( |
||
| 98 | 'failure' => '<error>%s</error>', |
||
| 99 | 'success' => '<info>%s</info>' |
||
| 100 | )); |
||
| 101 | |||
| 102 | $result = $validator->validateForPackage($package, $output->getVerbosity()); |
||
| 103 | |||
| 104 | if (!$result()) { |
||
| 105 | return 1; |
||
| 106 | } |
||
| 107 | |||
| 108 | $changelog = $chLogLoader->load($package); |
||
| 109 | |||
| 110 | $releaseResolver = new \Vaimo\ComposerChangelogs\Resolvers\ChangelogReleaseResolver(); |
||
| 111 | |||
| 112 | $version = key($changelog); |
||
| 113 | |||
| 114 | if (!$showTip) { |
||
| 115 | $version = $releaseResolver->resolveLatestVersionedRelease($changelog, $branch); |
||
| 116 | |||
| 117 | if ($showUpcoming) { |
||
| 118 | $version = $releaseResolver->resolveUpcomingRelease($changelog, $branch); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | if (!$version) { |
||
| 123 | return 0; |
||
| 124 | } |
||
| 125 | |||
| 126 | $versionResolver = new \Vaimo\ComposerChangelogs\Resolvers\VersionResolver(); |
||
| 127 | |||
| 128 | $version = $versionResolver->resolveValidVersion($version); |
||
| 129 | |||
| 130 | if ($format == 'regex') { |
||
| 131 | $version = preg_quote($version); |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($segmentsCount) { |
||
| 135 | $version = implode('.', array_slice(explode('.', $version), 0, $segmentsCount)); |
||
|
|
|||
| 136 | } |
||
| 137 | |||
| 138 | $output->writeln($version); |
||
| 139 | |||
| 140 | return 0; |
||
| 141 | } |
||
| 173 |