Conditions | 13 |
Paths | 375 |
Total Lines | 93 |
Code Lines | 61 |
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 |
||
29 | protected function execute(InputInterface $input, OutputInterface $output) |
||
30 | { |
||
31 | $output->writeln('Reading composer vendors.'); |
||
32 | $packages = json_decode(file_get_contents('composer.lock'), true); |
||
33 | $packages = $packages['packages']; |
||
34 | |||
35 | $output->writeln('Generating output'); |
||
36 | |||
37 | $typeOrder = [ |
||
38 | 'zikula-module' => 'Zikula Modules', |
||
39 | 'zikula-theme' => 'Zikula Themes', |
||
40 | 'symfony-bundle' => 'Symfony Bundles', |
||
41 | 'component' => 'Web Components', |
||
42 | 'library' => 'PHP libraries', |
||
43 | 'composer-installer' => 'Composer Installers', |
||
44 | 'composer-plugin' => 'Composer Plugins', |
||
45 | 'symfony-pack' => 'Symfony Packages', |
||
46 | 'symfony-bridge' => 'Symfony Bridge', |
||
47 | 'symfony-mailer-bridge' => 'Symfony Mailer Bridge', |
||
48 | 'symfony-messenger-bridge' => 'Symfony Messenger Bridge', |
||
49 | ]; |
||
50 | $types = array_keys($typeOrder); |
||
51 | usort($packages, function ($a, $b) use ($types) { |
||
52 | $typeOrder = array_search($a['type'], $types) - array_search($b['type'], $types); |
||
53 | if (0 !== $typeOrder) { |
||
54 | return $typeOrder; |
||
55 | } |
||
56 | |||
57 | // inside same type order by name |
||
58 | return strcmp($a['name'], $b['name']); |
||
59 | }); |
||
60 | |||
61 | $content = "--- |
||
62 | currentMenu: vendor-info |
||
63 | --- |
||
64 | # Vendor information |
||
65 | "; |
||
66 | |||
67 | $currentType = ''; |
||
68 | $authors = []; |
||
69 | foreach ($packages as $package) { |
||
70 | if ($currentType !== $package['type']) { |
||
71 | if ('' !== $currentType) { |
||
72 | $content .= "\n"; |
||
73 | } |
||
74 | $content .= '## ' . $typeOrder[$package['type']] . "\n\n"; |
||
75 | $currentType = $package['type']; |
||
76 | } |
||
77 | $content .= "- **" . $package['name'] . "** `" . $package['version'] . "`"; |
||
78 | if (isset($package['license'])) { |
||
79 | $content .= ", License: `" . implode(', ', $package['license']) . "`\n"; |
||
80 | } else { |
||
81 | $content .= "\n"; |
||
82 | } |
||
83 | if (isset($package['description'])) { |
||
84 | $content .= " *" . $package['description'] . "*\n"; |
||
85 | } |
||
86 | if (isset($package['authors'])) { |
||
87 | $authors = array_merge($authors, $package['authors']); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $content .= "\n\n"; |
||
92 | $content .= "## Authors\n\n"; |
||
93 | $content .= "These are the main authors of all of the projects supporting Zikula:\n\n"; |
||
94 | |||
95 | $tmp = []; |
||
96 | foreach ($authors as $k => $author) { |
||
97 | if (in_array($author['name'], $tmp)) { |
||
98 | unset($authors[$k]); |
||
99 | continue; |
||
100 | } |
||
101 | $tmp[] = $author['name']; |
||
102 | } |
||
103 | usort($authors, function ($a, $b) { |
||
104 | return strcmp($a['name'], $b['name']); |
||
105 | }); |
||
106 | foreach ($authors as $author) { |
||
107 | $content .= "- **" . $author['name'] . "**"; |
||
108 | if (isset($author['homepage'])) { |
||
109 | $content .= " " . $author['homepage']; |
||
110 | } |
||
111 | if (isset($author['email'])) { |
||
112 | $content .= " *" . $author['email'] . "*"; |
||
113 | } |
||
114 | $content .= "\n"; |
||
115 | } |
||
116 | |||
117 | $output->writeln('Dumping vendors to ' . $input->getOption('write-to')); |
||
118 | |||
119 | file_put_contents($input->getOption('write-to'), $content); |
||
120 | |||
121 | return 0; |
||
122 | } |
||
124 |