Conditions | 13 |
Paths | 8 |
Total Lines | 49 |
Code Lines | 25 |
Lines | 10 |
Ratio | 20.41 % |
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 |
||
117 | public function handleRequest(array $aRequest) : bool |
||
118 | { |
||
119 | if (!count($_POST)) { return true; } |
||
120 | |||
121 | // Validation |
||
122 | foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
||
123 | |||
124 | if (!$sValue instanceof self && !$this->_validate($sValue)) { |
||
125 | |||
126 | return false; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | // Save |
||
131 | if ($this->_oForm->getIdEntity() > 0 && $this->_oForm->getSynchronizeEntity() !== null && count($aRequest) > 0) { |
||
132 | |||
133 | $sModelName = str_replace('Entity', 'Model', $this->_oForm->getSynchronizeEntity()); |
||
134 | $oModel = new $sModelName; |
||
|
|||
135 | |||
136 | $oEntity = new $this->_oForm->getSynchronizeEntity(); |
||
137 | $sPrimaryKey = LibEntity::getPrimaryKeyNameWithoutMapping($oEntity); |
||
138 | $sMethodName = 'set_'.$sPrimaryKey; |
||
139 | |||
140 | call_user_func_array(array(&$oEntity, $sMethodName), array($this->_oForm->getIdEntity())); |
||
141 | |||
142 | View Code Duplication | foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
143 | |||
144 | $sMethodName = 'set_'.$sValue->getName().''; |
||
145 | call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
||
146 | } |
||
147 | |||
148 | $oEntity->save(); |
||
149 | } else if ($this->_oForm->getSynchronizeEntity() !== null && isset($aRequest) && count($aRequest) > 0) { |
||
150 | |||
151 | $oEntity = new $this->_oForm->_sSynchronizeEntity; |
||
152 | |||
153 | View Code Duplication | foreach ($this->_oForm->getElement() as $sKey => $sValue) { |
|
154 | |||
155 | $sMethodName = 'set_'.$sValue->getName().''; |
||
156 | call_user_func_array(array(&$oEntity, $sMethodName), array($aRequest[$sValue->getName()])); |
||
157 | } |
||
158 | |||
159 | $this->_oForm->setIdEntityCreated($oEntity->save()); |
||
160 | } |
||
161 | |||
162 | $this->_bHandleRequestActivate = true; |
||
163 | $this->_aRequest = $aRequest; |
||
164 | return true; |
||
165 | } |
||
166 | |||
240 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.