| Conditions | 2 |
| Paths | 2 |
| Total Lines | 88 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 60 | public function __construct($target) |
||
| 61 | { |
||
| 62 | $this->helper = $target->helper; |
||
| 63 | $this->targetObject = $target; |
||
| 64 | |||
| 65 | $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_FRIENDSHIP_ADD) : \sprintf( |
||
| 66 | \AM_YOGURT_FRIENDSHIP_EDIT |
||
| 67 | ); |
||
| 68 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 69 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 70 | |||
| 71 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 72 | |||
| 73 | $hidden = new XoopsFormHidden( |
||
| 74 | 'friendship_id', $this->targetObject->getVar( |
||
| 75 | 'friendship_id' |
||
| 76 | ) |
||
| 77 | ); |
||
| 78 | $this->addElement($hidden); |
||
| 79 | unset($hidden); |
||
| 80 | |||
| 81 | // Friendship_id |
||
| 82 | $this->addElement( |
||
| 83 | new XoopsFormLabel( |
||
| 84 | \AM_YOGURT_FRIENDSHIP_FRIENDSHIP_ID, $this->targetObject->getVar( |
||
| 85 | 'friendship_id' |
||
| 86 | ), 'friendship_id' |
||
| 87 | ) |
||
| 88 | ); |
||
| 89 | // Friend1_uid |
||
| 90 | $this->addElement( |
||
| 91 | new XoopsFormSelectUser( |
||
| 92 | \AM_YOGURT_FRIENDSHIP_FRIEND1_UID, 'friend1_uid', false, $this->targetObject->getVar( |
||
| 93 | 'friend1_uid' |
||
| 94 | ), 1, false |
||
| 95 | ), |
||
| 96 | false |
||
| 97 | ); |
||
| 98 | // Friend2_uid |
||
| 99 | $this->addElement( |
||
| 100 | new XoopsFormSelectUser( |
||
| 101 | \AM_YOGURT_FRIENDSHIP_FRIEND2_UID, 'friend2_uid', false, $this->targetObject->getVar( |
||
| 102 | 'friend2_uid' |
||
| 103 | ), 1, false |
||
| 104 | ), |
||
| 105 | false |
||
| 106 | ); |
||
| 107 | // Level |
||
| 108 | $this->addElement( |
||
| 109 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_LEVEL, 'level', 50, 255, $this->targetObject->getVar('level')), |
||
| 110 | false |
||
| 111 | ); |
||
| 112 | // Hot |
||
| 113 | $this->addElement( |
||
| 114 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_HOT, 'hot', 50, 255, $this->targetObject->getVar('hot')), |
||
| 115 | false |
||
| 116 | ); |
||
| 117 | // Trust |
||
| 118 | $this->addElement( |
||
| 119 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_TRUST, 'trust', 50, 255, $this->targetObject->getVar('trust')), |
||
| 120 | false |
||
| 121 | ); |
||
| 122 | // Cool |
||
| 123 | $this->addElement( |
||
| 124 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_COOL, 'cool', 50, 255, $this->targetObject->getVar('cool')), |
||
| 125 | false |
||
| 126 | ); |
||
| 127 | // Fan |
||
| 128 | $this->addElement( |
||
| 129 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_FAN, 'fan', 50, 255, $this->targetObject->getVar('fan')), |
||
| 130 | false |
||
| 131 | ); |
||
| 132 | |||
| 133 | // Data_creation |
||
| 134 | $this->addElement( |
||
| 135 | new \XoopsFormTextDateSelect( |
||
| 136 | \AM_YOGURT_FRIENDSHIP_DATE_CREATED, 'date_created', 0, formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
|
|
|||
| 137 | ) |
||
| 138 | ); |
||
| 139 | |||
| 140 | $this->addElement( |
||
| 141 | new \XoopsFormTextDateSelect( |
||
| 142 | \AM_YOGURT_FRIENDSHIP_DATE_UPDATED, 'date_updated', 0, formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | |||
| 146 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
| 147 | $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
| 148 | } |
||
| 150 |