Conditions | 5 |
Paths | 7 |
Total Lines | 57 |
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 |
||
42 | protected function execute(InputInterface $input, OutputInterface $output) |
||
43 | { |
||
44 | // prep some colors for the output |
||
45 | $output->getFormatter()->setStyle('error', new OutputFormatterStyle('white', 'red', array('bold'))); |
||
46 | $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('black', 'yellow', array('bold'))); |
||
47 | $output->getFormatter()->setStyle('good', new OutputFormatterStyle('white', 'green', array('bold'))); |
||
48 | |||
49 | // start print out |
||
50 | $output->writeln("\n<good>GitPolicy initialization</good>"); |
||
51 | |||
52 | // check if this is a git repo |
||
53 | exec('git status 2>&1', $return, $returnCode); |
||
54 | if ($returnCode > 0) { |
||
55 | $output->writeln("<error>This doesn't apprear to be a git repo.</error>"); |
||
56 | $output->writeln("\n<good>Stopping execution :(</good>\n"); |
||
57 | exit(0); |
||
58 | } |
||
59 | |||
60 | // check if git hook is already installed. |
||
61 | $output->writeln("\nGit hook"); |
||
62 | if (file_exists('.git/hooks/pre-push')) { |
||
63 | // quick and dirty check if this is already the GitPolicy hook |
||
64 | if (md5(file_get_contents('templates/pre-push')) == md5(file_get_contents('.git/hooks/pre-push'))) { |
||
65 | $output->writeln('<good>Is already in place :)</good>'); |
||
66 | } else { |
||
67 | $output->writeln( |
||
68 | '<warning>This repository already has a "pre-push" git hook.'. |
||
69 | 'Please ensure manually it works with GitPolicy. Continuing...</warning>' |
||
70 | ); |
||
71 | } |
||
72 | } else { |
||
73 | $output->writeln( |
||
74 | '<good>Adding the git hook :)</good>' |
||
75 | ); |
||
76 | |||
77 | // copy over the file and attempt to adjust the permissions |
||
78 | copy(realpath('templates/pre-push'), '.git/hooks/pre-push'); |
||
79 | chmod('.git/hooks/pre-push', 0755); |
||
80 | } |
||
81 | |||
82 | // check if there is already a configuration file |
||
83 | $output->writeln("\n.gitpolicy.yml file"); |
||
84 | if (file_exists('.gitpolicy.yml')) { |
||
85 | $output->writeln( |
||
86 | '<warning>.gitpolicy.yml already exists. Won\'t copy default config in. Continuing...</warning>' |
||
87 | ); |
||
88 | } else { |
||
89 | copy(realpath('templates/.gitpolicy.yml'), '.gitpolicy.yml'); |
||
90 | |||
91 | $output->writeln( |
||
92 | '<good>We copied an example of the .gitpolicy.yml into your folder. '. |
||
93 | 'Have a look and adjust it to your needs :)</good>' |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | $output->writeln("\n<good>Done</good>\n"); |
||
98 | } |
||
99 | } |
||
100 |