| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 36 |
| 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 |
||
| 10 | public function up() |
||
| 11 | { |
||
| 12 | $data = [ |
||
| 13 | [ |
||
| 14 | 'id' => 1, |
||
| 15 | 'login' => 'system', |
||
| 16 | 'email' => 'system@localhost', |
||
| 17 | 'created' => date('Y-m-d H:i:s'), |
||
| 18 | 'status' => 'disabled' |
||
| 19 | ], |
||
| 20 | [ |
||
| 21 | 'id' => 2, |
||
| 22 | 'login' => 'admin', |
||
| 23 | 'email' => 'admin@localhost', |
||
| 24 | 'created' => date('Y-m-d H:i:s'), |
||
| 25 | 'status' => 'active' |
||
| 26 | ], |
||
| 27 | [ |
||
| 28 | 'id' => 3, |
||
| 29 | 'login' => 'member', |
||
| 30 | 'email' => 'member@localhost', |
||
| 31 | 'created' => date('Y-m-d H:i:s'), |
||
| 32 | 'status' => 'active' |
||
| 33 | ], |
||
| 34 | ]; |
||
| 35 | |||
| 36 | $users = $this->table('users'); |
||
| 37 | $users->insert($data) |
||
| 38 | ->save(); |
||
| 39 | |||
| 40 | $data = [ |
||
| 41 | [ |
||
| 42 | 'userId' => 2, |
||
| 43 | 'provider' => 'equals', |
||
| 44 | 'foreignKey' => 'admin', |
||
| 45 | 'token' => '$2y$10$4a454775178c3f89d510fud2T.xtw01Ir.Jo.91Dr3nL2sz3OyVpK', // admin |
||
| 46 | 'tokenType' => 'access', |
||
| 47 | 'created' => date('Y-m-d H:i:s') |
||
| 48 | ], |
||
| 49 | [ |
||
| 50 | 'userId' => 3, |
||
| 51 | 'provider' => 'equals', |
||
| 52 | 'foreignKey' => 'member', |
||
| 53 | 'token' => '$2y$10$poVyazyQKXlfsGuUwxj/su.w0nnNJKzgyQyAnN3zjx9In3BaBeusq', // member |
||
| 54 | 'tokenType' => 'access', |
||
| 55 | 'created' => date('Y-m-d H:i:s') |
||
| 56 | ], |
||
| 57 | ]; |
||
| 58 | |||
| 59 | $auth = $this->table('auth'); |
||
| 60 | $auth->insert($data) |
||
| 61 | ->save(); |
||
| 62 | } |
||
| 63 | |||
| 73 |
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.