| Conditions | 9 |
| Paths | 256 |
| Total Lines | 66 |
| Code Lines | 48 |
| 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 |
||
| 38 | public function testConvert() { |
||
| 39 | |||
| 40 | try { |
||
| 41 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_ARRAY); |
||
| 42 | } catch (Exception $ex) { |
||
| 43 | $this->assertInstanceOf(IllegalArgumentException::class, $ex); |
||
| 44 | $this->assertEquals("The type \"63\" is not implemented", $ex->getMessage()); |
||
| 45 | } |
||
| 46 | |||
| 47 | try { |
||
| 48 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_DATE); |
||
| 49 | } catch (Exception $ex) { |
||
| 50 | $this->assertInstanceOf(NullPointerException::class, $ex); |
||
| 51 | $this->assertEquals("The date format is null", $ex->getMessage()); |
||
| 52 | } |
||
| 53 | |||
| 54 | try { |
||
| 55 | ArgumentConverter::convert("exception", ArgumentInterface::TYPE_DATE, "Y-m-d"); |
||
| 56 | } catch (Exception $ex) { |
||
| 57 | $this->assertInstanceOf(DateArgumentException::class, $ex); |
||
| 58 | $this->assertEquals("The argument \"exception\" is not a date", $ex->getMessage()); |
||
| 59 | } |
||
| 60 | |||
| 61 | try { |
||
| 62 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_NUMBER); |
||
| 63 | } catch (Exception $ex) { |
||
| 64 | $this->assertInstanceOf(IllegalArgumentException::class, $ex); |
||
| 65 | $this->assertEquals("The type \"73\" is not implemented", $ex->getMessage()); |
||
| 66 | } |
||
| 67 | |||
| 68 | try { |
||
| 69 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_OBJECT); |
||
| 70 | } catch (Exception $ex) { |
||
| 71 | $this->assertInstanceOf(IllegalArgumentException::class, $ex); |
||
| 72 | $this->assertEquals("The type \"55\" is not implemented", $ex->getMessage()); |
||
| 73 | } |
||
| 74 | |||
| 75 | try { |
||
| 76 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_RESOURCE); |
||
| 77 | } catch (Exception $ex) { |
||
| 78 | $this->assertInstanceOf(IllegalArgumentException::class, $ex); |
||
| 79 | $this->assertEquals("The type \"104\" is not implemented", $ex->getMessage()); |
||
| 80 | } |
||
| 81 | |||
| 82 | try { |
||
| 83 | ArgumentConverter::convert(null, ArgumentInterface::TYPE_TIMESTAMP); |
||
| 84 | } catch (Exception $ex) { |
||
| 85 | $this->assertInstanceOf(NullPointerException::class, $ex); |
||
| 86 | $this->assertEquals("The datetime format is null", $ex->getMessage()); |
||
| 87 | } |
||
| 88 | |||
| 89 | try { |
||
| 90 | ArgumentConverter::convert("exception", ArgumentInterface::TYPE_TIMESTAMP, "Y-m-d H:m:s"); |
||
| 91 | } catch (Exception $ex) { |
||
| 92 | $this->assertInstanceOf(TimestampArgumentException::class, $ex); |
||
| 93 | $this->assertEquals("The argument \"exception\" is not a timestamp", $ex->getMessage()); |
||
| 94 | } |
||
| 95 | |||
| 96 | $this->assertEquals(true, ArgumentConverter::convert("1", ArgumentInterface::TYPE_BOOLEAN)); |
||
| 97 | $this->assertInstanceOf(DateTime::class, ArgumentConverter::convert("2017-11-27", ArgumentInterface::TYPE_DATE, "Y-m-d")); |
||
| 98 | $this->assertEquals(1, ArgumentConverter::convert("1", ArgumentInterface::TYPE_DOUBLE)); |
||
| 99 | $this->assertEquals(1, ArgumentConverter::convert("1", ArgumentInterface::TYPE_FLOAT)); |
||
| 100 | $this->assertEquals(1, ArgumentConverter::convert("1", ArgumentInterface::TYPE_INTEGER)); |
||
| 101 | $this->assertEquals("1", ArgumentConverter::convert("1", ArgumentInterface::TYPE_STRING)); |
||
| 102 | $this->assertInstanceOf(DateTime::class, ArgumentConverter::convert("2017-11-27 11:20:00", ArgumentInterface::TYPE_TIMESTAMP, "Y-m-d H:m:s")); |
||
| 103 | } |
||
| 104 | |||
| 106 |