Conditions | 4 |
Paths | 5 |
Total Lines | 65 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
28 | public function bootstrapChangelogGeneration(\Composer\Package\PackageInterface $package, $format = 'md') |
||
29 | { |
||
30 | $pluginConfig = new \Vaimo\ComposerChangelogs\Composer\Plugin\Config(); |
||
31 | |||
32 | $formats = $pluginConfig->getAvailableFormats(); |
||
33 | |||
34 | if (!isset($formats[$format])) { |
||
35 | $message = sprintf('Unknown format: %s', $format); |
||
36 | |||
37 | throw new \Vaimo\ComposerChangelogs\Exceptions\UpdaterException($message); |
||
38 | } |
||
39 | |||
40 | $composer = $this->composerCtx->getLocalComposer(); |
||
41 | |||
42 | $packageInfoResolver = new \Vaimo\ComposerChangelogs\Resolvers\PackageInfoResolver( |
||
43 | $composer->getInstallationManager() |
||
44 | ); |
||
45 | |||
46 | $configExtractor = new \Vaimo\ComposerChangelogs\Extractors\VendorConfigExtractor($packageInfoResolver); |
||
47 | |||
48 | $installPath = $packageInfoResolver->getInstallPath($package); |
||
49 | $config = $configExtractor->getPackageFullConfig($package); |
||
50 | |||
51 | $paths = array( |
||
52 | 'md' => 'CHANGELOG.md', |
||
53 | 'sphinx' => 'docs/changelog.rst', |
||
54 | 'rst' => 'docs/changelog.rst', |
||
55 | 'txt' => 'CHANGELOG.txt' |
||
56 | ); |
||
57 | |||
58 | $filePath = isset($paths[$format]) ? $paths[$format] : sprintf('CHANGELOG.%s', $format); |
||
59 | |||
60 | $update = array( |
||
61 | ComposerConfig::CONFIG_ROOT => array( |
||
62 | PluginConfig::ROOT => array( |
||
63 | 'source' => 'changelog.json', |
||
64 | 'output' => array($format => $filePath) |
||
65 | ) |
||
66 | ) |
||
67 | ); |
||
68 | |||
69 | $pathUtils = new \Vaimo\ComposerChangelogs\Utils\PathUtils(); |
||
70 | $jsonEncoder = new \Camspiers\JsonPretty\JsonPretty(); |
||
71 | |||
72 | $encodedConfig = $jsonEncoder->prettify(array_replace_recursive($config, $update), null, ' '); |
||
73 | |||
74 | $pkgConfigPath = $pathUtils->composePath($installPath, ComposerFiles::PACKAGE_CONFIG); |
||
75 | $chLogConfigPath = $pathUtils->composePath($installPath, 'changelog.json'); |
||
76 | |||
77 | file_put_contents($pkgConfigPath, $encodedConfig); |
||
78 | |||
79 | if (!file_exists($chLogConfigPath)) { |
||
80 | $changeLog = array( |
||
81 | '_readme' => array( |
||
82 | 'The contents of this file are used to generate CHANGELOG.md; It\'s kept in ' |
||
83 | . 'JSON/parsable format to make it', |
||
84 | 'possible to generate change-logs in other formats as well (when needed) and ' |
||
85 | . 'to do automatic releases based on', |
||
86 | 'added change-log records. More on how to use it: https://github.com/vaimo/composer-changelogs' |
||
87 | ) |
||
88 | ); |
||
89 | |||
90 | $encodedChangeLog = $jsonEncoder->prettify($changeLog, null, ' '); |
||
91 | |||
92 | file_put_contents($chLogConfigPath, $encodedChangeLog); |
||
93 | } |
||
96 |