Conditions | 11 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | Features | 3 |
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 |
||
95 | private function getCommand(DatabaseObjectInterface $databaseObject, $isCreate = true) |
||
96 | { |
||
97 | if ($databaseObject instanceof Column) { |
||
98 | $command = $this->container |
||
99 | ->get($isCreate ? 'rentgen.add_column' : 'rentgen.drop_column') |
||
100 | ->setColumn($databaseObject); |
||
101 | } elseif ($databaseObject instanceof ConstraintInterface) { |
||
102 | $command = $this->container |
||
103 | ->get($isCreate ? 'rentgen.add_constraint' : 'rentgen.drop_constraint') |
||
104 | ->setConstraint($databaseObject); |
||
105 | } elseif ($databaseObject instanceof Index) { |
||
106 | $command = $this->container |
||
107 | ->get($isCreate ? 'rentgen.create_index' : 'rentgen.drop_index') |
||
108 | ->setIndex($databaseObject); |
||
109 | } elseif ($databaseObject instanceof Schema) { |
||
110 | $command = $this->container |
||
111 | ->get($isCreate ? 'rentgen.create_schema' : 'rentgen.drop_schema') |
||
112 | ->setSchema($databaseObject); |
||
113 | } elseif ($databaseObject instanceof Table) { |
||
114 | $command = $this->container |
||
115 | ->get($isCreate ? 'rentgen.create_table' : 'rentgen.drop_table') |
||
116 | ->setTable($databaseObject); |
||
117 | } else { |
||
118 | throw new \Exception(sprintf("Class %s is not supported", get_class($databaseObject))); |
||
119 | } |
||
120 | |||
121 | return $command; |
||
122 | } |
||
123 | } |
||
124 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.