| Conditions | 5 |
| Paths | 8 |
| Total Lines | 80 |
| Code Lines | 45 |
| 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 |
||
| 47 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 48 | { |
||
| 49 | $packageName = $input->getArgument('name'); |
||
| 50 | |||
| 51 | $fromSource = $input->getOption('from-source'); |
||
| 52 | $repositoryUrl = $input->getOption('url'); |
||
| 53 | |||
| 54 | $composerRuntime = $this->getComposer(); |
||
| 55 | |||
| 56 | $packageRepoFactory = new Factories\PackageRepositoryFactory($composerRuntime); |
||
| 57 | $errOutputGenerator = new \Vaimo\ComposerChangelogs\Console\OutputGenerator(); |
||
| 58 | |||
| 59 | if (!$packageName) { |
||
| 60 | $packageName = $composerRuntime->getPackage()->getName(); |
||
| 61 | } |
||
| 62 | |||
| 63 | $packageRepo = $packageRepoFactory->create(); |
||
| 64 | |||
| 65 | try { |
||
| 66 | $package = $packageRepo->getByName($packageName); |
||
| 67 | } catch (PackageResolverException $exception) { |
||
| 68 | \array_map( |
||
| 69 | array($output, 'writeln'), |
||
| 70 | $errOutputGenerator->generateForResolverException($exception) |
||
| 71 | ); |
||
| 72 | |||
| 73 | return 1; |
||
| 74 | } |
||
| 75 | |||
| 76 | $confResolverFactory = new Factories\Changelog\ConfigResolverFactory($composerRuntime); |
||
| 77 | |||
| 78 | $confResolver = $confResolverFactory->create($fromSource); |
||
| 79 | |||
| 80 | $changelogLoader = new \Vaimo\ComposerChangelogs\Loaders\ChangelogLoader($confResolver); |
||
| 81 | |||
| 82 | $validator = new \Vaimo\ComposerChangelogs\Validators\ChangelogValidator($changelogLoader, array( |
||
| 83 | 'failure' => '<error>%s</error>', |
||
| 84 | 'success' => '<info>%s</info>' |
||
| 85 | )); |
||
| 86 | |||
| 87 | $result = $validator->validateForPackage($package, $output->getVerbosity()); |
||
|
|
|||
| 88 | |||
| 89 | if (!$result()) { |
||
| 90 | array_map(array($output, 'writeln'), $result->getMessages()); |
||
| 91 | |||
| 92 | return 1; |
||
| 93 | } |
||
| 94 | |||
| 95 | $output->writeln( |
||
| 96 | sprintf('Generating changelog output for <info>%s</info>', $package->getName()) |
||
| 97 | ); |
||
| 98 | |||
| 99 | $infoResolver = new Resolvers\PackageInfoResolver( |
||
| 100 | $composerRuntime->getInstallationManager() |
||
| 101 | ); |
||
| 102 | |||
| 103 | $featureFlags = $confResolver->getFeatureFlags($package); |
||
| 104 | |||
| 105 | $urlResolver = $this->createUrlResolver($repositoryUrl, $featureFlags); |
||
| 106 | |||
| 107 | $docsGenerator = new \Vaimo\ComposerChangelogs\Generators\DocumentationGenerator( |
||
| 108 | $confResolver, |
||
| 109 | $changelogLoader, |
||
| 110 | $infoResolver, |
||
| 111 | $urlResolver |
||
| 112 | ); |
||
| 113 | |||
| 114 | try { |
||
| 115 | $docsGenerator->generate($package); |
||
| 116 | } catch (\Vaimo\ComposerChangelogs\Exceptions\GeneratorException $exception) { |
||
| 117 | $output->writeln( |
||
| 118 | sprintf('<error>%s</error>', $exception->getMessage()) |
||
| 119 | ); |
||
| 120 | |||
| 121 | return 1; |
||
| 122 | } |
||
| 123 | |||
| 124 | $output->writeln('<info>Done</info>'); |
||
| 125 | |||
| 126 | return 0; |
||
| 127 | } |
||
| 144 |