| Conditions | 3 |
| Paths | 2 |
| Total Lines | 59 |
| Code Lines | 44 |
| 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 |
||
| 40 | function definition() { |
||
|
|
|||
| 41 | global $DB; |
||
| 42 | |||
| 43 | $mform =& $this->_form; |
||
| 44 | |||
| 45 | $relationshipid = $this->_customdata['relationshipid']; |
||
| 46 | |||
| 47 | $mform->addElement('text', 'namingscheme', get_string('namingscheme', 'local_relationship')); |
||
| 48 | $mform->addHelpButton('namingscheme', 'namingscheme', 'local_relationship'); |
||
| 49 | $mform->addRule('namingscheme', get_string('required'), 'required', null, 'client'); |
||
| 50 | $mform->setType('namingscheme', PARAM_TEXT); |
||
| 51 | $mform->setDefault('namingscheme', get_string('grouptemplate', 'group')); |
||
| 52 | |||
| 53 | $mform->addElement('text', 'userlimit', get_string('userlimit', 'local_relationship'), 'maxlength="5" size="4"'); |
||
| 54 | $mform->setType('userlimit', PARAM_INT); |
||
| 55 | $mform->addRule('userlimit', null, 'numeric', null, 'client'); |
||
| 56 | $mform->setDefault('userlimit', 0); |
||
| 57 | $mform->addHelpButton('userlimit', 'userlimit', 'local_relationship'); |
||
| 58 | |||
| 59 | $mform->addElement('text', 'number', get_string('numbergroups', 'local_relationship'), 'maxlength="4" size="4"'); |
||
| 60 | $mform->setType('number', PARAM_INT); |
||
| 61 | $mform->addRule('number', null, 'numeric', null, 'client'); |
||
| 62 | $mform->setDefault('number', 0); |
||
| 63 | $mform->disabledIf('number', 'relationshipcohortid', 'gt', 0); |
||
| 64 | |||
| 65 | $sql = "SELECT rc.id, rc.cohortid, rc.roleid, ch.name |
||
| 66 | FROM {relationship_cohorts} rc |
||
| 67 | JOIN {cohort} ch ON (ch.id = rc.cohortid) |
||
| 68 | WHERE rc.relationshipid = :relationshipid |
||
| 69 | ORDER BY ch.name"; |
||
| 70 | $rcs = $DB->get_records_sql($sql, array('relationshipid' => $relationshipid)); |
||
| 71 | if ($rcs) { |
||
| 72 | $options = array(0 => get_string('none')); |
||
| 73 | $r = get_string('role'); |
||
| 74 | foreach ($rcs AS $rc) { |
||
| 75 | $role = $DB->get_record('role', array('id' => $rc->roleid)); |
||
| 76 | $role_name = role_get_name($role); |
||
| 77 | $options[$rc->id] = "{$rc->name} ({$r}: {$role_name})"; |
||
| 78 | } |
||
| 79 | $mform->addElement('select', 'relationshipcohortid', get_string('fromcohort', 'local_relationship'), $options); |
||
| 80 | $mform->setDefault('relationshipcohortid', '0'); |
||
| 81 | $mform->addHelpButton('relationshipcohortid', 'fromcohort', 'local_relationship'); |
||
| 82 | $mform->disabledIf('relationshipcohortid', 'number', 'gt', 0); |
||
| 83 | } else { |
||
| 84 | $mform->addElement('hidden', 'relationshipcohortid'); |
||
| 85 | $mform->setType('relationshipcohortid', PARAM_INT); |
||
| 86 | $mform->setConstant('relationshipcohortid', '0'); |
||
| 87 | } |
||
| 88 | |||
| 89 | $mform->addElement('hidden', 'relationshipid'); |
||
| 90 | $mform->setType('relationshipid', PARAM_INT); |
||
| 91 | |||
| 92 | $buttonarray = array(); |
||
| 93 | $buttonarray[] = & $mform->createElement('submit', 'preview', get_string('preview', 'local_relationship')); |
||
| 94 | $buttonarray[] = & $mform->createElement('submit', 'submitbutton', get_string('creategroups', 'local_relationship')); |
||
| 95 | $buttonarray[] = & $mform->createElement('cancel'); |
||
| 96 | $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); |
||
| 97 | $mform->closeHeaderBefore('buttonar'); |
||
| 98 | } |
||
| 99 | |||
| 113 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.