Conditions | 1 |
Paths | 1 |
Total Lines | 79 |
Code Lines | 18 |
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 |
||
93 | public function getCode() : string |
||
94 | { |
||
95 | $singularName = $this->getSingularName(); |
||
96 | $pluralName = $this->getPluralName(); |
||
97 | $remoteBeanName = TDBMDaoGenerator::getBeanNameFromTableName($this->remoteFk->getForeignTableName()); |
||
98 | $variableName = '$'.TDBMDaoGenerator::toVariableName($remoteBeanName); |
||
99 | $pluralVariableName = $variableName.'s'; |
||
100 | |||
101 | $str = ' /** |
||
102 | * Returns the list of %s associated to this bean via the %s pivot table. |
||
103 | * |
||
104 | * @return %s[] |
||
105 | */ |
||
106 | public function get%s() |
||
107 | { |
||
108 | return $this->_getRelationships(%s); |
||
109 | } |
||
110 | '; |
||
111 | |||
112 | $getterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralName, var_export($this->remoteFk->getLocalTableName(), true)); |
||
113 | |||
114 | $str = ' /** |
||
115 | * Adds a relationship with %s associated to this bean via the %s pivot table. |
||
116 | * |
||
117 | * @param %s %s |
||
118 | */ |
||
119 | public function add%s(%s %s) |
||
120 | { |
||
121 | return $this->addRelationship(%s, %s); |
||
122 | } |
||
123 | '; |
||
124 | |||
125 | $adderCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
||
126 | |||
127 | $str = ' /** |
||
128 | * Deletes the relationship with %s associated to this bean via the %s pivot table. |
||
129 | * |
||
130 | * @param %s %s |
||
131 | */ |
||
132 | public function remove%s(%s %s) |
||
133 | { |
||
134 | return $this->_removeRelationship(%s, %s); |
||
135 | } |
||
136 | '; |
||
137 | |||
138 | $removerCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
||
139 | |||
140 | $str = ' /** |
||
141 | * Returns whether this bean is associated with %s via the %s pivot table. |
||
142 | * |
||
143 | * @param %s %s |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function has%s(%s %s) : bool |
||
147 | { |
||
148 | return $this->hasRelationship(%s, %s); |
||
149 | } |
||
150 | '; |
||
151 | |||
152 | $hasCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $variableName, $singularName, $remoteBeanName, $variableName, var_export($this->remoteFk->getLocalTableName(), true), $variableName); |
||
153 | |||
154 | $str = ' /** |
||
155 | * Sets all relationships with %s associated to this bean via the %s pivot table. |
||
156 | * Exiting relationships will be removed and replaced by the provided relationships. |
||
157 | * |
||
158 | * @param %s[] %s |
||
159 | */ |
||
160 | public function set%s(array %s) |
||
161 | { |
||
162 | return $this->setRelationships(%s, %s); |
||
163 | } |
||
164 | '; |
||
165 | |||
166 | $setterCode = sprintf($str, $remoteBeanName, $this->pivotTable->getName(), $remoteBeanName, $pluralVariableName, $pluralName, $pluralVariableName, var_export($this->remoteFk->getLocalTableName(), true), $pluralVariableName); |
||
167 | |||
168 | $code = $getterCode.$adderCode.$removerCode.$hasCode.$setterCode; |
||
169 | |||
170 | return $code; |
||
171 | } |
||
172 | |||
201 |
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.