| Conditions | 13 |
| Paths | 4096 |
| Total Lines | 100 |
| Code Lines | 73 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 45 | public function testIsValid() { |
||
| 46 | |||
| 47 | try { |
||
| 48 | ArgumentValidator::isValid(null, -1); |
||
| 49 | } catch (Exception $ex) { |
||
| 50 | $this->assertInstanceOf(IllegalArgumentException::class, $ex); |
||
| 51 | $this->assertEquals("The type \"-1\" is not implemented", $ex->getMessage()); |
||
| 52 | } |
||
| 53 | |||
| 54 | $rsc = fopen(getcwd() . "/Tests/Argument/ArgumentValidatorTest.php", "r"); |
||
| 55 | |||
| 56 | $this->assertTrue(ArgumentValidator::isValid([], ArgumentInterface::TYPE_ARRAY)); |
||
| 57 | $this->assertTrue(ArgumentValidator::isValid(true, ArgumentInterface::TYPE_BOOLEAN)); |
||
| 58 | $this->assertTrue(ArgumentValidator::isValid("2017-10-20", ArgumentInterface::TYPE_DATE)); |
||
| 59 | $this->assertTrue(ArgumentValidator::isValid(0.1, ArgumentInterface::TYPE_DOUBLE)); |
||
| 60 | $this->assertTrue(ArgumentValidator::isValid(1.0, ArgumentInterface::TYPE_FLOAT)); |
||
| 61 | $this->assertTrue(ArgumentValidator::isValid(1, ArgumentInterface::TYPE_INTEGER)); |
||
| 62 | $this->assertTrue(ArgumentValidator::isValid(2, ArgumentInterface::TYPE_NUMBER)); |
||
| 63 | $this->assertTrue(ArgumentValidator::isValid($this, ArgumentInterface::TYPE_OBJECT)); |
||
| 64 | $this->assertTrue(ArgumentValidator::isValid($rsc, ArgumentInterface::TYPE_RESOURCE)); |
||
| 65 | $this->assertTrue(ArgumentValidator::isValid("", ArgumentInterface::TYPE_STRING)); |
||
| 66 | $this->assertTrue(ArgumentValidator::isValid("2017-10-20 15:41:10", ArgumentInterface::TYPE_TIMESTAMP)); |
||
| 67 | |||
| 68 | try { |
||
| 69 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_ARRAY); |
||
| 70 | } catch (Exception $ex) { |
||
| 71 | $this->assertInstanceOf(ArrayArgumentException::class, $ex); |
||
| 72 | $this->assertEquals("The argument \"\" is not an array", $ex->getMessage()); |
||
| 73 | } |
||
| 74 | |||
| 75 | try { |
||
| 76 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_BOOLEAN); |
||
| 77 | } catch (Exception $ex) { |
||
| 78 | $this->assertInstanceOf(BooleanArgumentException::class, $ex); |
||
| 79 | $this->assertEquals("The argument \"\" is not a boolean", $ex->getMessage()); |
||
| 80 | } |
||
| 81 | |||
| 82 | try { |
||
| 83 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_DATE); |
||
| 84 | } catch (Exception $ex) { |
||
| 85 | $this->assertInstanceOf(DateArgumentException::class, $ex); |
||
| 86 | $this->assertEquals("The argument \"\" is not a date", $ex->getMessage()); |
||
| 87 | } |
||
| 88 | |||
| 89 | try { |
||
| 90 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_DOUBLE); |
||
| 91 | } catch (Exception $ex) { |
||
| 92 | $this->assertInstanceOf(DoubleArgumentException::class, $ex); |
||
| 93 | $this->assertEquals("The argument \"\" is not a double", $ex->getMessage()); |
||
| 94 | } |
||
| 95 | |||
| 96 | try { |
||
| 97 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_FLOAT); |
||
| 98 | } catch (Exception $ex) { |
||
| 99 | $this->assertInstanceOf(FloatArgumentException::class, $ex); |
||
| 100 | $this->assertEquals("The argument \"\" is not a float", $ex->getMessage()); |
||
| 101 | } |
||
| 102 | |||
| 103 | try { |
||
| 104 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_INTEGER); |
||
| 105 | } catch (Exception $ex) { |
||
| 106 | $this->assertInstanceOf(IntegerArgumentException::class, $ex); |
||
| 107 | $this->assertEquals("The argument \"\" is not an integer", $ex->getMessage()); |
||
| 108 | } |
||
| 109 | |||
| 110 | try { |
||
| 111 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_NUMBER); |
||
| 112 | } catch (Exception $ex) { |
||
| 113 | $this->assertInstanceOf(NumberArgumentException::class, $ex); |
||
| 114 | $this->assertEquals("The argument \"\" is not a number", $ex->getMessage()); |
||
| 115 | } |
||
| 116 | |||
| 117 | try { |
||
| 118 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_OBJECT); |
||
| 119 | } catch (Exception $ex) { |
||
| 120 | $this->assertInstanceOf(ObjectArgumentException::class, $ex); |
||
| 121 | $this->assertEquals("The argument \"\" is not an object", $ex->getMessage()); |
||
| 122 | } |
||
| 123 | |||
| 124 | try { |
||
| 125 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_RESOURCE); |
||
| 126 | } catch (Exception $ex) { |
||
| 127 | $this->assertInstanceOf(ResourceArgumentException::class, $ex); |
||
| 128 | $this->assertEquals("The argument \"\" is not a resource", $ex->getMessage()); |
||
| 129 | } |
||
| 130 | |||
| 131 | try { |
||
| 132 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_STRING); |
||
| 133 | } catch (Exception $ex) { |
||
| 134 | $this->assertInstanceOf(StringArgumentException::class, $ex); |
||
| 135 | $this->assertEquals("The argument \"\" is not a string", $ex->getMessage()); |
||
| 136 | } |
||
| 137 | |||
| 138 | try { |
||
| 139 | ArgumentValidator::isValid(null, ArgumentInterface::TYPE_TIMESTAMP); |
||
| 140 | } catch (Exception $ex) { |
||
| 141 | $this->assertInstanceOf(TimestampArgumentException::class, $ex); |
||
| 142 | $this->assertEquals("The argument \"\" is not a timestamp", $ex->getMessage()); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 147 |