Conditions | 12 |
Paths | 289 |
Total Lines | 54 |
Code Lines | 27 |
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 |
||
43 | public function alterColumn( |
||
44 | AbstractTable $table, |
||
45 | AbstractColumn $initial, |
||
46 | AbstractColumn $column |
||
47 | ) { |
||
48 | if (!$initial instanceof SQLServerColumn || !$column instanceof SQLServerColumn) { |
||
49 | throw new SchemaException('SQlServer handler can work only with SQLServer columns.'); |
||
50 | } |
||
51 | |||
52 | //In SQLServer we have to drop ALL related indexes and foreign keys while |
||
53 | //applying type change... yeah... |
||
54 | |||
55 | $indexesBackup = []; |
||
56 | $foreignBackup = []; |
||
57 | foreach ($table->getIndexes() as $index) { |
||
58 | if (in_array($column->getName(), $index->getColumns())) { |
||
59 | $indexesBackup[] = $index; |
||
60 | $this->dropIndex($table, $index); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | foreach ($table->getForeigns() as $foreign) { |
||
65 | if ($column->getName() == $foreign->getColumn()) { |
||
66 | $foreignBackup[] = $foreign; |
||
67 | $this->dropForeign($table, $foreign); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | //Column will recreate needed constraints |
||
72 | foreach ($column->getConstraints() as $constraint) { |
||
73 | $this->dropConstrain($table, $constraint); |
||
74 | } |
||
75 | |||
76 | //Rename is separate operation |
||
77 | if ($column->getName() != $initial->getName()) { |
||
78 | $this->renameColumn($table, $initial, $column); |
||
79 | |||
80 | //This call is required to correctly built set of alter operations |
||
81 | $initial->setName($column->getName()); |
||
82 | } |
||
83 | |||
84 | foreach ($column->alterOperations($this->driver, $initial) as $operation) { |
||
85 | $this->run("ALTER TABLE {$this->identify($table)} {$operation}"); |
||
86 | } |
||
87 | |||
88 | //Restoring indexes and foreign keys |
||
89 | foreach ($indexesBackup as $index) { |
||
90 | $this->createIndex($table, $index); |
||
91 | } |
||
92 | |||
93 | foreach ($foreignBackup as $foreign) { |
||
94 | $this->createForeign($table, $foreign); |
||
95 | } |
||
96 | } |
||
97 | |||
128 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.