| Conditions | 1 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 111 | public function indexProvider(){ |
||
| 112 | return array( |
||
| 113 | array( |
||
| 114 | array( |
||
| 115 | 'id' => 'admin', |
||
| 116 | 'displayname' => 'admin', |
||
| 117 | 'backends' => array ( |
||
| 118 | 'email' => array ( |
||
| 119 | 'id' => NULL, |
||
| 120 | 'displayname' => 'E-mail', |
||
| 121 | 'protocol' => 'email', |
||
| 122 | 'namespace' => ' email', |
||
| 123 | 'value' => array ( |
||
| 124 | 0 => array ( |
||
| 125 | ), |
||
| 126 | ), |
||
| 127 | ), |
||
| 128 | 'och' => array ( |
||
| 129 | 'id' => NULL, |
||
| 130 | 'displayname' => 'ownCloud Handle', |
||
| 131 | 'protocol' => 'x-owncloud-handle', |
||
| 132 | 'namespace' => 'och', |
||
| 133 | 'value' => 'admin', |
||
| 134 | ), |
||
| 135 | ), |
||
| 136 | 'address_book_id' => 'local', |
||
| 137 | 'address_book_backend' => '', |
||
| 138 | ), |
||
| 139 | array( |
||
| 140 | "timestamp" => time(), |
||
| 141 | "user" => array( |
||
| 142 | 'id' => 'admin', |
||
| 143 | 'displayname' => 'admin', |
||
| 144 | 'backends' => array ( |
||
| 145 | 'email' => array ( |
||
| 146 | 'id' => NULL, |
||
| 147 | 'displayname' => 'E-mail', |
||
| 148 | 'protocol' => 'email', |
||
| 149 | 'namespace' => ' email', |
||
| 150 | 'value' => array ( |
||
| 151 | 0 => array ( |
||
| 152 | ), |
||
| 153 | ), |
||
| 154 | ), |
||
| 155 | 'och' => array ( |
||
| 156 | 'id' => NULL, |
||
| 157 | 'displayname' => 'ownCloud Handle', |
||
| 158 | 'protocol' => 'x-owncloud-handle', |
||
| 159 | 'namespace' => 'och', |
||
| 160 | 'value' => 'admin', |
||
| 161 | ), |
||
| 162 | ), |
||
| 163 | 'address_book_id' => 'local', |
||
| 164 | 'address_book_backend' => '', |
||
| 165 | ), |
||
| 166 | ), |
||
| 167 | array( |
||
| 168 | "contacts" => "contacts", // dummy data |
||
| 169 | "contactsList" => array("contact1", "contact2"), |
||
| 170 | "contactsObj" => array("contacts"), |
||
| 171 | ), |
||
| 172 | array( |
||
| 173 | "backend1", |
||
| 174 | "backend2" |
||
| 175 | ), |
||
| 176 | array( |
||
| 177 | "initconv1", |
||
| 178 | "initconv2" |
||
| 179 | ), |
||
| 180 | array( |
||
| 181 | "session_id" => md5(time()) |
||
| 182 | ) |
||
| 183 | ) |
||
| 184 | ); |
||
| 185 | } |
||
| 186 | |||
| 265 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: