Conditions | 10 |
Paths | 5 |
Total Lines | 47 |
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 |
||
79 | protected function checkDuplicates($path, array $vars = array()) |
||
80 | { |
||
81 | $packageType = substr($vars['type'], strlen('bitrix') + 1); |
||
82 | $localDir = explode('/', $vars['bitrix_dir']); |
||
83 | array_pop($localDir); |
||
84 | $localDir[] = 'local'; |
||
85 | $localDir = implode('/', $localDir); |
||
86 | |||
87 | $oldPath = str_replace( |
||
88 | array('{$bitrix_dir}', '{$name}'), |
||
89 | array($localDir, $vars['name']), |
||
90 | $this->locations[$packageType] |
||
91 | ); |
||
92 | |||
93 | if (in_array($oldPath, static::$checkedDuplicates)) { |
||
|
|||
94 | return; |
||
95 | } |
||
96 | |||
97 | if ($oldPath !== $path && file_exists($oldPath) && $this->io && $this->io->isInteractive()) { |
||
98 | |||
99 | $this->io->writeError(' <error>Duplication of packages:</error>'); |
||
100 | $this->io->writeError(' <info>Package ' . $oldPath . ' will be called instead package ' . $path . '</info>'); |
||
101 | |||
102 | while (true) { |
||
103 | switch ($this->io->ask(' <info>Delete ' . $oldPath . ' [y,n,?]?</info> ', '?')) { |
||
104 | case 'y': |
||
105 | $fs = new Filesystem(); |
||
106 | $fs->removeDirectory($oldPath); |
||
107 | break 2; |
||
108 | |||
109 | case 'n': |
||
110 | break 2; |
||
111 | |||
112 | case '?': |
||
113 | default: |
||
114 | $this->io->writeError(array( |
||
115 | ' y - delete package ' . $oldPath . ' and to continue with the installation', |
||
116 | ' n - don\'t delete and to continue with the installation', |
||
117 | )); |
||
118 | $this->io->writeError(' ? - print help'); |
||
119 | break; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | static::$checkedDuplicates[] = $oldPath; |
||
125 | } |
||
126 | } |
||
127 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: