| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 16 | public function init() |
||
| 17 | { |
||
| 18 | // $this->db->setVerbose(); |
||
| 19 | $this->db->dropTableIfExists('user')->execute(); |
||
|
|
|||
| 20 | |||
| 21 | $this->db->createTable( |
||
| 22 | 'user', |
||
| 23 | [ |
||
| 24 | 'id' => ['integer', 'primary key', 'not null', 'auto_increment'], |
||
| 25 | 'acronym' => ['varchar(20)', 'unique', 'not null'], |
||
| 26 | 'email' => ['varchar(80)'], |
||
| 27 | 'name' => ['varchar(80)'], |
||
| 28 | 'points' => ['int'], |
||
| 29 | 'password' => ['varchar(255)'], |
||
| 30 | 'created' => ['datetime'], |
||
| 31 | 'updated' => ['datetime'], |
||
| 32 | 'deleted' => ['datetime'], |
||
| 33 | 'active' => ['datetime'], |
||
| 34 | ] |
||
| 35 | )->execute(); |
||
| 36 | $this->db->insert( |
||
| 37 | 'user', |
||
| 38 | ['acronym', 'email', 'name', 'points', 'password', 'created', 'active'] |
||
| 39 | ); |
||
| 40 | |||
| 41 | $now = gmdate('Y-m-d H:i:s'); |
||
| 42 | |||
| 43 | $this->db->execute([ |
||
| 44 | 'admin', |
||
| 45 | '[email protected]', |
||
| 46 | 'Administrator', |
||
| 47 | 0, |
||
| 48 | md5('admin'), |
||
| 49 | $now, |
||
| 50 | $now |
||
| 51 | ]); |
||
| 52 | |||
| 53 | $this->db->execute([ |
||
| 54 | 'bob', |
||
| 55 | '[email protected]', |
||
| 56 | 'Byggare Bob', |
||
| 57 | 0, |
||
| 58 | md5('bob'), |
||
| 59 | $now, |
||
| 60 | $now |
||
| 61 | ]); |
||
| 62 | |||
| 63 | $this->db->execute([ |
||
| 64 | 'fnlive', |
||
| 65 | '[email protected]', |
||
| 66 | 'Fredrik Nilsson', |
||
| 67 | 0, |
||
| 68 | md5('qwerty'), |
||
| 69 | $now, |
||
| 70 | $now |
||
| 71 | ]); |
||
| 72 | |||
| 73 | } |
||
| 74 | |||
| 134 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.