| Conditions | 1 |
| Paths | 1 |
| Total Lines | 101 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| 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 |
||
| 23 | public function __construct($name = null) |
||
| 24 | { |
||
| 25 | |||
| 26 | // we want to ignore the name passed |
||
| 27 | parent::__construct('settings'); |
||
| 28 | $oModule = new Module(); |
||
| 29 | $cfg = $oModule->getConfig(); |
||
|
|
|||
| 30 | |||
| 31 | $this->setAttribute('method', 'post'); |
||
| 32 | $this->add( |
||
| 33 | array( |
||
| 34 | 'name' => 'settings_id', |
||
| 35 | 'attributes' => array( |
||
| 36 | 'type' => 'hidden', |
||
| 37 | ), |
||
| 38 | ) |
||
| 39 | ); |
||
| 40 | $this->add( |
||
| 41 | array( |
||
| 42 | 'name' => 'scope', |
||
| 43 | 'attributes' => array( |
||
| 44 | 'type' => 'text', |
||
| 45 | ), |
||
| 46 | 'options' => array( |
||
| 47 | 'label' => 'scope', |
||
| 48 | ), |
||
| 49 | ) |
||
| 50 | ); |
||
| 51 | $this->add( |
||
| 52 | array( |
||
| 53 | 'name' => 'ref_id', |
||
| 54 | 'attributes' => array( |
||
| 55 | 'type' => 'text', |
||
| 56 | ), |
||
| 57 | 'options' => array( |
||
| 58 | 'label' => 'reference', |
||
| 59 | ), |
||
| 60 | ) |
||
| 61 | ); |
||
| 62 | $this->add( |
||
| 63 | array( |
||
| 64 | 'name' => 'type', |
||
| 65 | 'attributes' => array( |
||
| 66 | 'type' => 'text', |
||
| 67 | ), |
||
| 68 | 'options' => array( |
||
| 69 | 'label' => 'type', |
||
| 70 | ), |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | $this->add( |
||
| 74 | array( |
||
| 75 | 'name' => 'name', |
||
| 76 | 'attributes' => array( |
||
| 77 | 'type' => 'text', |
||
| 78 | ), |
||
| 79 | 'options' => array( |
||
| 80 | 'label' => 'name', |
||
| 81 | ), |
||
| 82 | ) |
||
| 83 | ); |
||
| 84 | $this->add( |
||
| 85 | array( |
||
| 86 | 'name' => 'value', |
||
| 87 | 'attributes' => array( |
||
| 88 | 'type' => 'text', |
||
| 89 | ), |
||
| 90 | 'options' => array( |
||
| 91 | 'label' => 'value', |
||
| 92 | ), |
||
| 93 | ) |
||
| 94 | ); |
||
| 95 | |||
| 96 | $this->add( |
||
| 97 | array( |
||
| 98 | 'name' => 'submit', |
||
| 99 | 'attributes' => array( |
||
| 100 | 'type' => 'submit', |
||
| 101 | 'value' => 'save', |
||
| 102 | 'id' => 'submitbutton', |
||
| 103 | ), |
||
| 104 | 'options' => array( |
||
| 105 | 'label' => 'save', |
||
| 106 | ), |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | |||
| 110 | $this->add( |
||
| 111 | array( |
||
| 112 | 'name' => 'reset', |
||
| 113 | 'attributes' => array( |
||
| 114 | 'type' => 'reset', |
||
| 115 | 'value' => 'reset', |
||
| 116 | 'id' => 'resetbutton', |
||
| 117 | ), |
||
| 118 | 'options' => array( |
||
| 119 | 'label' => 'reset', |
||
| 120 | ), |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.