| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 49 | private function createUserTables() |
||
| 50 | { |
||
| 51 | $this->createTable('users', array( |
||
| 52 | 'id' => 'pk', |
||
| 53 | 'email' => 'string NOT NULL', |
||
| 54 | 'password' => 'string NOT NULL', |
||
| 55 | 'username' => 'string NOT NULL', |
||
| 56 | 'user_role' => 'integer DEFAULT 1', |
||
| 57 | 'status' => 'integer DEFAULT 1', |
||
| 58 | 'created' => 'integer', |
||
| 59 | 'updated' => 'integer' |
||
| 60 | )); |
||
| 61 | |||
| 62 | $this->createTable('user_roles', array( |
||
| 63 | 'id' => 'pk', |
||
| 64 | 'name' => 'string NOT NULL', |
||
| 65 | 'created' => 'integer', |
||
| 66 | 'updated' => 'integer' |
||
| 67 | )); |
||
| 68 | |||
| 69 | $this->createTable('user_metadata', array( |
||
| 70 | 'user_id' => 'integer', |
||
| 71 | 'key' => 'string NOT NULL', |
||
| 72 | 'value' => 'text NOT NULL', |
||
| 73 | 'entity_type' => 'integer', |
||
| 74 | 'created' => 'integer', |
||
| 75 | 'updated' => 'integer' |
||
| 76 | )); |
||
| 77 | |||
| 78 | // Create the necessary indexes on the columns |
||
| 79 | $this->createIndex('user_email', 'users', 'email', true); |
||
| 80 | $this->createIndex('user_username', 'users', 'username', true); |
||
| 81 | $this->createIndex('user_metadata', 'user_metadata', 'user_id, key', false); |
||
| 82 | |||
| 83 | $this->addPrimaryKey('user_metadata_composite', 'user_metadata', 'user_id,key'); |
||
| 84 | |||
| 85 | // Setup the foreign key constraints |
||
| 86 | $this->addForeignKey('user_metadata_relation_fk', 'user_metadata', 'user_id', 'users', 'id', 'CASCADE', 'NO ACTION'); |
||
| 87 | |||
| 88 | // Insert data into the tables |
||
| 89 | $this->insert('user_roles', array( |
||
| 90 | 'id' => 1, |
||
| 91 | 'name' => 'User', |
||
| 92 | 'created' => $this->_moment, |
||
| 93 | 'updated' => $this->_moment |
||
| 94 | )); |
||
| 95 | |||
| 96 | $this->insert('user_roles', array( |
||
| 97 | 'id' => 2, |
||
| 98 | 'name' => 'Pending', |
||
| 99 | 'created' => $this->_moment, |
||
| 100 | 'updated' => $this->_moment |
||
| 101 | )); |
||
| 102 | |||
| 103 | $this->insert('user_roles', array( |
||
| 104 | 'id' => 3, |
||
| 105 | 'name' => 'Suspended', |
||
| 106 | 'created' => $this->_moment, |
||
| 107 | 'updated' => $this->_moment |
||
| 108 | )); |
||
| 109 | |||
| 110 | $this->insert('user_roles', array( |
||
| 111 | 'id' => 5, |
||
| 112 | 'name' => 'Collaborator', |
||
| 113 | 'created' => $this->_moment, |
||
| 114 | 'updated' => $this->_moment |
||
| 115 | )); |
||
| 116 | |||
| 117 | $this->insert('user_roles', array( |
||
| 118 | 'id' => 6, |
||
| 119 | 'name' => 'Author', |
||
| 120 | 'created' => $this->_moment, |
||
| 121 | 'updated' => $this->_moment |
||
| 122 | )); |
||
| 123 | |||
| 124 | $this->insert('user_roles', array( |
||
| 125 | 'id' => 7, |
||
| 126 | 'name' => 'User', |
||
| 127 | 'created' => $this->_moment, |
||
| 128 | 'updated' => $this->_moment |
||
| 129 | )); |
||
| 130 | |||
| 131 | $this->insert('user_roles', array( |
||
| 132 | 'id' => 8, |
||
| 133 | 'name' => 'Publisher', |
||
| 134 | 'created' => $this->_moment, |
||
| 135 | 'updated' => $this->_moment |
||
| 136 | )); |
||
| 137 | |||
| 138 | $this->insert('user_roles', array( |
||
| 139 | 'id' => 9, |
||
| 140 | 'name' => 'Administrator', |
||
| 141 | 'created' => $this->_moment, |
||
| 142 | 'updated' => $this->_moment |
||
| 143 | )); |
||
| 144 | } |
||
| 145 | |||
| 288 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.