| Conditions | 10 |
| Paths | 24 |
| Total Lines | 42 |
| Code Lines | 32 |
| 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 |
||
| 35 | public function getForm($instance){ |
||
| 36 | $form=$this->jquery->semantic()->dataForm("frmEdit", $instance); |
||
| 37 | $className=\get_class($instance); |
||
| 38 | $form->setFields($this->controller->getAdminData()->getFormFieldNames($className)); |
||
| 39 | $form->setSubmitParams("Admin/update", "#table-details"); |
||
| 40 | $fieldTypes=OrmUtils::getFieldTypes($className); |
||
| 41 | foreach ($fieldTypes as $property=>$type){ |
||
| 42 | switch ($type){ |
||
| 43 | case "boolean": |
||
| 44 | $form->fieldAsCheckbox($property); |
||
| 45 | break; |
||
| 46 | case "int": |
||
| 47 | $form->fieldAsInput($property,["inputType"=>"number"]); |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | $relations = OrmUtils::getFieldsInRelations($className); |
||
| 52 | foreach ($relations as $member){ |
||
| 53 | if(OrmUtils::getAnnotationInfoMember($className, "#manyToOne",$member)!==false){ |
||
| 54 | $joinColumn=OrmUtils::getAnnotationInfoMember($className, "#joinColumn", $member); |
||
| 55 | if($joinColumn){ |
||
| 56 | $fkObject=Reflexion::getMemberValue($instance, $member); |
||
| 57 | $fkClass=$joinColumn["className"]; |
||
| 58 | $fkId=OrmUtils::getFirstKey($fkClass); |
||
| 59 | $fkIdGetter="get".\ucfirst($fkId); |
||
| 60 | if(\method_exists($fkObject, "__toString") && \method_exists($fkObject, $fkIdGetter)){ |
||
| 61 | $fkField=$joinColumn["name"]; |
||
| 62 | |||
| 63 | $fkValue=OrmUtils::getFirstKeyValue($fkObject); |
||
| 64 | if(!Reflexion::setMemberValue($instance, $fkField, $fkValue)){ |
||
| 65 | $instance->$fkField=OrmUtils::getFirstKeyValue($fkObject); |
||
| 66 | $form->addField($fkField); |
||
| 67 | } |
||
| 68 | $form->fieldAsDropDown($fkField,JArray::modelArray(DAO::getAll($fkClass),$fkIdGetter,"__toString")); |
||
| 69 | $form->setCaption($fkField, \ucfirst($member)); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return $form; |
||
| 76 | } |
||
| 77 | } |