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