| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 36 |
| 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 |
||
| 10 | public function testBuilder() |
||
| 11 | { |
||
| 12 | /* Assertion 1 */ |
||
| 13 | $parser = new Parser( |
||
| 14 | 'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)' |
||
| 15 | ); |
||
| 16 | $stmt = $parser->statements[0]; |
||
| 17 | $this->assertEquals( |
||
| 18 | 'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)', |
||
| 19 | $stmt->build() |
||
| 20 | ); |
||
| 21 | |||
| 22 | /* Assertion 2 */ |
||
| 23 | /* Reserved keywords (with backqoutes as field name) */ |
||
| 24 | $parser = new Parser( |
||
| 25 | 'INSERT INTO tbl(`order`) VALUES (1)' |
||
| 26 | ); |
||
| 27 | $stmt = $parser->statements[0]; |
||
| 28 | $this->assertEquals( |
||
| 29 | 'INSERT INTO tbl(`order`) VALUES (1)', |
||
| 30 | $stmt->build() |
||
| 31 | ); |
||
| 32 | |||
| 33 | /* Assertion 3 */ |
||
| 34 | /* INSERT ... SET ... */ |
||
| 35 | $parser = new Parser( |
||
| 36 | 'INSERT INTO tbl SET FOO = 1' |
||
| 37 | ); |
||
| 38 | $stmt = $parser->statements[0]; |
||
| 39 | $this->assertEquals( |
||
| 40 | 'INSERT INTO tbl SET FOO = 1', |
||
| 41 | $stmt->build() |
||
| 42 | ); |
||
| 43 | |||
| 44 | /* Assertion 4 */ |
||
| 45 | /* INSERT ... SELECT ... */ |
||
| 46 | $parser = new Parser( |
||
| 47 | 'INSERT INTO tbl SELECT * FROM bar' |
||
| 48 | ); |
||
| 49 | $stmt = $parser->statements[0]; |
||
| 50 | $this->assertEquals( |
||
| 51 | 'INSERT INTO tbl SELECT * FROM bar', |
||
| 52 | $stmt->build() |
||
| 53 | ); |
||
| 54 | |||
| 55 | /* Assertion 5 */ |
||
| 56 | /* INSERT ... ON DUPLICATE KEY UPDATE ... */ |
||
| 57 | $parser = new Parser( |
||
| 58 | 'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1' |
||
| 59 | ); |
||
| 60 | $stmt = $parser->statements[0]; |
||
| 61 | $this->assertEquals( |
||
| 62 | 'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1', |
||
| 63 | $stmt->build() |
||
| 64 | ); |
||
| 65 | |||
| 66 | /* Assertion 6 */ |
||
| 67 | /* INSERT array(OPTIONS] INTO ... */ |
||
| 68 | $parser = new Parser( |
||
| 69 | 'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar' |
||
| 70 | ); |
||
| 71 | $stmt = $parser->statements[0]; |
||
| 72 | $this->assertEquals( |
||
| 73 | 'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar', |
||
| 74 | $stmt->build() |
||
| 75 | ); |
||
| 78 |