Conditions | 11 |
Paths | 11 |
Total Lines | 33 |
Code Lines | 17 |
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 |
||
53 | public function shouldWriteFile(string $file, bool $overwrite): bool |
||
54 | { |
||
55 | if (isset($this->writtenFiles[$file])) { |
||
56 | return false; |
||
57 | } |
||
58 | $this->writtenFiles[$file] = true; |
||
59 | |||
60 | if (!file_exists($file)) { |
||
61 | return true; |
||
62 | } |
||
63 | |||
64 | if (!$overwrite) { |
||
65 | return false; |
||
66 | } |
||
67 | |||
68 | if (!filesize($file)) { |
||
69 | return true; |
||
70 | } |
||
71 | |||
72 | exec('git status --short --ignored --untracked-files=all -- '.ProcessExecutor::escape($file).' 2>&1', $output, $status); |
||
73 | |||
74 | if (0 !== $status) { |
||
75 | return $this->io && $this->io->askConfirmation(sprintf('Cannot determine the state of the "%s" file, overwrite anyway? [y/N] ', $file), false); |
||
76 | } |
||
77 | |||
78 | if (empty($output[0]) || preg_match('/^[ AMDRCU][ D][ \t]/', $output[0])) { |
||
79 | return true; |
||
80 | } |
||
81 | |||
82 | $name = basename($file); |
||
83 | $name = \strlen($output[0]) - \strlen($name) === strrpos($output[0], $name) ? substr($output[0], 3) : $name; |
||
84 | |||
85 | return $this->io && $this->io->askConfirmation(sprintf('File "%s" has uncommitted changes, overwrite? [y/N] ', $name), false); |
||
86 | } |
||
93 |