Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
67 | public function testSelectWithJoin() |
||
68 | { |
||
69 | $query = Query::factory() |
||
70 | ->insert('fwkdb_test_users') |
||
71 | ->set('username', 'joeBar'); |
||
72 | |||
73 | $this->connection->execute($query); |
||
74 | |||
75 | $query = Query::factory() |
||
76 | ->insert('fwkdb_test_emails') |
||
77 | ->values(array( |
||
78 | 'email' => '[email protected]', |
||
79 | 'verified' => true |
||
80 | )); |
||
81 | |||
82 | $this->connection->execute($query); |
||
83 | |||
84 | $query = Query::factory() |
||
85 | ->insert('fwkdb_test_emails') |
||
86 | ->values(array( |
||
87 | 'email' => '[email protected]', |
||
88 | 'verified' => false |
||
89 | )); |
||
90 | |||
91 | $this->connection->execute($query); |
||
92 | |||
93 | $query = Query::factory() |
||
94 | ->insert('fwkdb_test_users_emails') |
||
95 | ->values(array( |
||
96 | 'user_id' => 1, |
||
97 | 'email_id' => 1 |
||
98 | )); |
||
99 | |||
100 | $this->connection->execute($query); |
||
101 | |||
102 | $query = Query::factory() |
||
103 | ->insert('fwkdb_test_users_emails') |
||
104 | ->values(array( |
||
105 | 'user_id' => 1, |
||
106 | 'email_id' => 2 |
||
107 | )); |
||
108 | |||
109 | $this->connection->execute($query); |
||
110 | |||
111 | $this->assertEquals(1, count($this->connection->table('fwkdb_test_users')->finder()->all())); |
||
112 | $this->assertEquals(2, count($this->connection->table('fwkdb_test_emails')->finder()->all())); |
||
113 | $this->assertEquals(2, count($this->connection->table('fwkdb_test_users_emails')->finder()->all())); |
||
114 | |||
115 | $query = Query::factory() |
||
116 | ->select() |
||
117 | ->from('fwkdb_test_users u') |
||
118 | ->join('fwkdb_test_users_emails ue', 'u.id', 'ue.user_id', Query::JOIN_LEFT, array('skipped' => true)) |
||
119 | ->join('fwkdb_test_emails e', 'e.id', 'ue.email_id', Query::JOIN_LEFT, array('column' => 'emails')); |
||
120 | |||
121 | $res = $this->connection->execute($query); |
||
122 | |||
123 | $this->assertTrue(is_array($res)); |
||
124 | $this->assertEquals(1, count($res)); |
||
125 | $entity = $res[0]; |
||
126 | |||
127 | $this->assertTrue(is_object($entity)); |
||
128 | $this->assertEquals(2, count($entity->emails)); |
||
129 | } |
||
130 | |||
198 |