| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 42 | public function testTimestampType() |
||
| 43 | { |
||
| 44 | $input = new \DateTime("2014-10-21 15:23:38"); |
||
| 45 | |||
| 46 | // datetimetz |
||
| 47 | $type = Type::getType(Type::DATETIMETZ); |
||
| 48 | $expected = $input->format('Y-m-d\TH:i:sO'); |
||
| 49 | $output = $type->convertToDatabaseValue($input, $this->platform); |
||
| 50 | $this->assertEquals($output, $expected); |
||
| 51 | $inputRestored = $type->convertToPHPValue($output, $this->platform); |
||
| 52 | $this->assertEquals($inputRestored, $input); |
||
| 53 | $inputRestored = $type->convertToPHPValue($input, $this->platform); |
||
| 54 | $this->assertEquals($inputRestored, $input); |
||
| 55 | |||
| 56 | // datetime |
||
| 57 | $type = Type::getType(Type::DATETIME); |
||
| 58 | $expected = $input->format('Y-m-d\TH:i:s'); |
||
| 59 | $output = $type->convertToDatabaseValue($input, $this->platform); |
||
| 60 | $this->assertEquals($output, $expected); |
||
| 61 | $inputRestored = $type->convertToPHPValue($output, $this->platform); |
||
| 62 | $this->assertEquals($inputRestored, $input); |
||
| 63 | $inputRestored = $type->convertToPHPValue($input, $this->platform); |
||
| 64 | $this->assertEquals($inputRestored, $input); |
||
| 65 | |||
| 66 | // date |
||
| 67 | $type = Type::getType(Type::DATE); |
||
| 68 | $expected = $input->format('Y-m-d\TH:i:s'); |
||
| 69 | $output = $type->convertToDatabaseValue($input, $this->platform); |
||
| 70 | $this->assertEquals($output, $expected); |
||
| 71 | $inputRestored = $type->convertToPHPValue($output, $this->platform); |
||
| 72 | $this->assertEquals($inputRestored, $input); |
||
| 73 | $inputRestored = $type->convertToPHPValue($input, $this->platform); |
||
| 74 | $this->assertEquals($inputRestored, $input); |
||
| 75 | |||
| 76 | // time |
||
| 77 | $type = Type::getType(Type::TIME); |
||
| 78 | $expected = $input->format('Y-m-d\TH:i:s'); |
||
| 79 | $output = $type->convertToDatabaseValue($input, $this->platform); |
||
| 80 | $this->assertEquals($output, $expected); |
||
| 81 | $inputRestored = $type->convertToPHPValue($output, $this->platform); |
||
| 82 | $this->assertEquals($inputRestored, $input); |
||
| 83 | $inputRestored = $type->convertToPHPValue($input, $this->platform); |
||
| 84 | $this->assertEquals($inputRestored, $input); |
||
| 85 | |||
| 86 | // timestamp |
||
| 87 | $type = Type::getType(TimestampType::NAME); |
||
| 88 | $expected = $input->format('U')*TimestampType::S_TO_MS; |
||
| 89 | $output = $type->convertToDatabaseValue($input, $this->platform); |
||
| 90 | $this->assertEquals($output, $expected); |
||
| 91 | $inputRestored = $type->convertToPHPValue($output, $this->platform); |
||
| 92 | $this->assertEquals($inputRestored, $input); |
||
| 93 | $inputRestored = $type->convertToPHPValue($input, $this->platform); |
||
| 94 | $this->assertEquals($inputRestored, $input); |
||
| 95 | } |
||
| 180 |