| Conditions | 2 |
| Paths | 2 |
| Total Lines | 110 |
| 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 |
||
| 57 | public function __construct($target) |
||
| 58 | { |
||
| 59 | $this->helper = $target->helper; |
||
| 60 | |||
| 61 | $this->targetObject = $target; |
||
| 62 | |||
| 63 | $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_FRIENDSHIP_ADD) : \sprintf( |
||
| 64 | \AM_YOGURT_FRIENDSHIP_EDIT |
||
| 65 | ); |
||
| 66 | |||
| 67 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 68 | |||
| 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 | |||
| 79 | $this->addElement($hidden); |
||
| 80 | |||
| 81 | unset($hidden); |
||
| 82 | |||
| 83 | // Friendship_id |
||
| 84 | |||
| 85 | $this->addElement( |
||
| 86 | new XoopsFormLabel( |
||
| 87 | \AM_YOGURT_FRIENDSHIP_FRIENDSHIP_ID, $this->targetObject->getVar( |
||
| 88 | 'friendship_id' |
||
| 89 | ), 'friendship_id' |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | |||
| 93 | // Friend1_uid |
||
| 94 | |||
| 95 | $this->addElement( |
||
| 96 | new XoopsFormSelectUser( |
||
| 97 | \AM_YOGURT_FRIENDSHIP_FRIEND1_UID, 'friend1_uid', false, $this->targetObject->getVar( |
||
| 98 | 'friend1_uid' |
||
| 99 | ), 1, false |
||
| 100 | ), |
||
| 101 | false |
||
| 102 | ); |
||
| 103 | |||
| 104 | // Friend2_uid |
||
| 105 | |||
| 106 | $this->addElement( |
||
| 107 | new XoopsFormSelectUser( |
||
| 108 | \AM_YOGURT_FRIENDSHIP_FRIEND2_UID, 'friend2_uid', false, $this->targetObject->getVar( |
||
| 109 | 'friend2_uid' |
||
| 110 | ), 1, false |
||
| 111 | ), |
||
| 112 | false |
||
| 113 | ); |
||
| 114 | |||
| 115 | // Level |
||
| 116 | |||
| 117 | $this->addElement( |
||
| 118 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_LEVEL, 'level', 50, 255, $this->targetObject->getVar('level')), |
||
| 119 | false |
||
| 120 | ); |
||
| 121 | |||
| 122 | // Hot |
||
| 123 | |||
| 124 | $this->addElement( |
||
| 125 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_HOT, 'hot', 50, 255, $this->targetObject->getVar('hot')), |
||
| 126 | false |
||
| 127 | ); |
||
| 128 | |||
| 129 | // Trust |
||
| 130 | |||
| 131 | $this->addElement( |
||
| 132 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_TRUST, 'trust', 50, 255, $this->targetObject->getVar('trust')), |
||
| 133 | false |
||
| 134 | ); |
||
| 135 | |||
| 136 | // Cool |
||
| 137 | |||
| 138 | $this->addElement( |
||
| 139 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_COOL, 'cool', 50, 255, $this->targetObject->getVar('cool')), |
||
| 140 | false |
||
| 141 | ); |
||
| 142 | |||
| 143 | // Fan |
||
| 144 | |||
| 145 | $this->addElement( |
||
| 146 | new XoopsFormText(\AM_YOGURT_FRIENDSHIP_FAN, 'fan', 50, 255, $this->targetObject->getVar('fan')), |
||
| 147 | false |
||
| 148 | ); |
||
| 149 | |||
| 150 | // Data_creation |
||
| 151 | |||
| 152 | $this->addElement( |
||
| 153 | new \XoopsFormTextDateSelect( |
||
| 154 | \AM_YOGURT_FRIENDSHIP_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
|
|
|||
| 155 | ) |
||
| 156 | ); |
||
| 157 | |||
| 158 | $this->addElement( |
||
| 159 | new \XoopsFormTextDateSelect( |
||
| 160 | \AM_YOGURT_FRIENDSHIP_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's') |
||
| 161 | ) |
||
| 162 | ); |
||
| 163 | |||
| 164 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
| 165 | |||
| 166 | $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
| 167 | } |
||
| 169 |