Conditions | 13 |
Paths | 384 |
Total Lines | 50 |
Code Lines | 31 |
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 | #!/usr/bin/env php |
||
21 | |||
22 | if (isset($argv[1]) && '--dev' === $argv[1]) { |
||
23 | $config['dev'] = true; |
||
24 | array_splice($argv, 1, 1); |
||
25 | } |
||
26 | |||
27 | if (isset($argv[1]) && '' !== $argv[1]) { |
||
28 | $config['composer_dir'] = $argv[1]; |
||
29 | } |
||
30 | |||
31 | $composerFile = $config['composer_dir'] . '/composer.json'; |
||
32 | $project = json_decode((string)@file_get_contents($composerFile), true); |
||
33 | if (!is_array($project)) { |
||
34 | fprintf(STDERR, "fatal: not a composer.json: '%s'\n", $composerFile); |
||
35 | exit(1); |
||
36 | } |
||
37 | $project += array('require' => array(), 'require-dev' => array()); |
||
38 | |||
39 | $require = $project['require']; |
||
40 | $config['dev'] && $require += $project['require-dev']; |
||
41 | $pkgs = packages($require, dirname($composerFile) . '/vendor'); |
||
42 | |||
43 | tpl_render_pkgs($pkgs); |
||
44 | |||
45 | // done |
||
46 | |||
47 | /** |
||
48 | * render packages as markdown |
||
49 | * |
||
50 | * @param array $pkgs |
||
51 | */ |
||
52 | function tpl_render_pkgs(array $pkgs) |
||
53 | { |
||
54 | foreach ($pkgs as $pkg) { |
||
55 | list($pkg, $lic, $lic_file) = array_values($pkg); |
||
56 | ?> |
||
57 | ### <?= tpl_func_name_nice($pkg) ?> (<?= tpl_func_spdx_full($lic) ?>) |
||
58 | |||
59 | From the package https://packagist.org/packages/<?= $pkg ?> |
||
60 | |||
61 | |||
62 | ``` |
||
63 | <?= rtrim(file_get_contents($lic_file)), "\n"; ?> |
||
64 | ``` |
||
65 | |||
66 | #### SPDX |
||
67 | |||
68 | * Full Name: `<?= tpl_func_spdx_full($lic) ?>` |
||
69 | * Short Identifier: `<?= $lic ?>` |
||
70 | * Reference: <?= tpl_func_spdx_url($lic) ?> |
||
71 | |||
193 |