diff --git a/src/StringParser.php b/src/StringParser.php index 731f635..0972cc5 100644 --- a/src/StringParser.php +++ b/src/StringParser.php @@ -3,11 +3,11 @@ namespace MPScholten\RequestParser; use MPScholten\RequestParser\Validator\EmailParser; -use MPScholten\RequestParser\Validator\StringBetweenParser; -use MPScholten\RequestParser\Validator\StringLargerThanOrEqualToParser; -use MPScholten\RequestParser\Validator\StringLargerThanParser; -use MPScholten\RequestParser\Validator\StringSmallerThanOrEqualToParser; -use MPScholten\RequestParser\Validator\StringSmallerThanParser; +use MPScholten\RequestParser\Validator\StringLengthBetween; +use MPScholten\RequestParser\Validator\StringLengthLargerThanOrEqualToParser; +use MPScholten\RequestParser\Validator\StringLengthLargerThanParser; +use MPScholten\RequestParser\Validator\StringLengthSmallerThanOrEqualToParser; +use MPScholten\RequestParser\Validator\StringLengthSmallerThanParser; use MPScholten\RequestParser\Validator\UrlParser; class StringParser extends AbstractValueParser @@ -83,46 +83,51 @@ public function rightTrim() /** * @param int $minValue * @param int $maxValue - * @return StringBetweenParser + * + * @return StringLengthBetween */ - public function between($minValue, $maxValue) + public function lengthBetween($minValue, $maxValue) { - return new StringBetweenParser($this->config, $this->name, $this->value, $minValue, $maxValue); + return new StringLengthBetween($this->config, $this->name, $this->value, $minValue, $maxValue); } /** * @param int $minValue - * @return StringLargerThanParser + * + * @return StringLengthLargerThanParser */ - public function largerThan($minValue) + public function lengthLargerThan($minValue) { - return new StringLargerThanParser($this->config, $this->name, $this->value, $minValue); + return new StringLengthLargerThanParser($this->config, $this->name, $this->value, $minValue); } /** * @param int $minValue - * @return StringLargerThanOrEqualToParser + * + * @return StringLengthLargerThanOrEqualToParser */ - public function largerThanOrEqualTo($minValue) + public function lengthLargerThanOrEqualTo($minValue) { - return new StringLargerThanOrEqualToParser($this->config, $this->name, $this->value, $minValue); + return new StringLengthLargerThanOrEqualToParser($this->config, $this->name, $this->value, $minValue); } /** * @param int $maxValue - * @return StringSmallerThanParser + * + * @return StringLengthSmallerThanParser */ - public function smallerThan($maxValue) + public function lengthSmallerThan($maxValue) { - return new StringSmallerThanParser($this->config, $this->name, $this->value, $maxValue); + return new StringLengthSmallerThanParser($this->config, $this->name, $this->value, $maxValue); } /** * @param int $maxValue - * @return StringSmallerThanOrEqualToParser + * + * @return StringLengthSmallerThanOrEqualToParser */ - public function smallerThanOrEqualTo($maxValue) + public function lengthSmallerThanOrEqualTo($maxValue) { - return new StringSmallerThanOrEqualToParser($this->config, $this->name, $this->value, $maxValue); + return new StringLengthSmallerThanOrEqualToParser($this->config, $this->name, $this->value, $maxValue); } } diff --git a/src/Validator/StringBetweenParser.php b/src/Validator/StringLengthBetween.php similarity index 94% rename from src/Validator/StringBetweenParser.php rename to src/Validator/StringLengthBetween.php index 6d50a4b..d0df507 100644 --- a/src/Validator/StringBetweenParser.php +++ b/src/Validator/StringLengthBetween.php @@ -2,7 +2,7 @@ namespace MPScholten\RequestParser\Validator; -class StringBetweenParser extends AbstractBetweenParser +class StringLengthBetween extends AbstractBetweenParser { protected function describe() { diff --git a/src/Validator/StringLargerThanOrEqualToParser.php b/src/Validator/StringLengthLargerThanOrEqualToParser.php similarity index 91% rename from src/Validator/StringLargerThanOrEqualToParser.php rename to src/Validator/StringLengthLargerThanOrEqualToParser.php index 2b28660..112e5ec 100644 --- a/src/Validator/StringLargerThanOrEqualToParser.php +++ b/src/Validator/StringLengthLargerThanOrEqualToParser.php @@ -2,7 +2,7 @@ namespace MPScholten\RequestParser\Validator; -class StringLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser +class StringLengthLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser { protected function describe() { diff --git a/src/Validator/StringLargerThanParser.php b/src/Validator/StringLengthLargerThanParser.php similarity index 93% rename from src/Validator/StringLargerThanParser.php rename to src/Validator/StringLengthLargerThanParser.php index c1696da..eb4b1a7 100644 --- a/src/Validator/StringLargerThanParser.php +++ b/src/Validator/StringLengthLargerThanParser.php @@ -2,7 +2,7 @@ namespace MPScholten\RequestParser\Validator; -class StringLargerThanParser extends AbstractLargerThanParser +class StringLengthLargerThanParser extends AbstractLargerThanParser { protected function describe() { diff --git a/src/Validator/StringSmallerThanOrEqualToParser.php b/src/Validator/StringLengthSmallerThanOrEqualToParser.php similarity index 91% rename from src/Validator/StringSmallerThanOrEqualToParser.php rename to src/Validator/StringLengthSmallerThanOrEqualToParser.php index 66095d7..32143cb 100644 --- a/src/Validator/StringSmallerThanOrEqualToParser.php +++ b/src/Validator/StringLengthSmallerThanOrEqualToParser.php @@ -2,7 +2,7 @@ namespace MPScholten\RequestParser\Validator; -class StringSmallerThanOrEqualToParser extends AbstractSmallerThanOrEqualToParser +class StringLengthSmallerThanOrEqualToParser extends AbstractSmallerThanOrEqualToParser { protected function describe() { diff --git a/src/Validator/StringSmallerThanParser.php b/src/Validator/StringLengthSmallerThanParser.php similarity index 92% rename from src/Validator/StringSmallerThanParser.php rename to src/Validator/StringLengthSmallerThanParser.php index a1f778b..d2d0691 100644 --- a/src/Validator/StringSmallerThanParser.php +++ b/src/Validator/StringLengthSmallerThanParser.php @@ -2,7 +2,7 @@ namespace MPScholten\RequestParser\Validator; -class StringSmallerThanParser extends AbstractSmallerThanParser +class StringLengthSmallerThanParser extends AbstractSmallerThanParser { protected function describe() { diff --git a/tests/ParserSpecTest.php b/tests/ParserSpecTest.php index e251aba..10707db 100644 --- a/tests/ParserSpecTest.php +++ b/tests/ParserSpecTest.php @@ -166,10 +166,10 @@ public function testBetweenValidatorWithValidValues() $this->assertEquals(101.12, $parser->required()); $parser = new StringParser(new Config(), 'name', ''); - $parser->between(0, 1); + $parser->lengthBetween(0, 1); $this->assertEquals('', $parser->required()); $parser = new StringParser(new Config(), 'groupId', 'A'); - $parser->between(0, 1); + $parser->lengthBetween(0, 1); $this->assertEquals('A', $parser->required()); } @@ -192,11 +192,11 @@ public function testLargerThanValidatorWithValidValues() $this->assertEquals(1.01, $parser->required()); $parser = new StringParser(new Config(), 'name', 'A'); - $parser->largerThan(0); + $parser->lengthLargerThan(0); $this->assertEquals('A', $parser->required()); $parser = new StringParser(new Config(), 'groupId', 'A'); - $parser->largerThanOrEqualTo(1); + $parser->lengthLargerThanOrEqualTo(1); $this->assertEquals('A', $parser->required()); } @@ -219,11 +219,11 @@ public function testSmallerThanValidatorWithValidValues() $this->assertEquals(-2.01, $parser->required()); $parser = new StringParser(new Config(), 'groupId', 'A'); - $parser->smallerThan(2); + $parser->lengthSmallerThan(2); $this->assertEquals('A', $parser->required()); $parser = new StringParser(new Config(), 'groupId', 'A'); - $parser->largerThanOrEqualTo(1); + $parser->lengthLargerThanOrEqualTo(1); $this->assertEquals('A', $parser->required()); } @@ -245,7 +245,7 @@ public function testStringBetweenValidatorWithValuesOutOfRange() { $this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string with character length between 0 and 1, but got "AB"'); $parser = new StringParser(new Config(), 'name', 'AB'); - $parser->between(0, 1)->required(); + $parser->lengthBetween(0, 1)->required(); } public function testIntLargerThanValidatorWithValuesOutOfRange() @@ -280,14 +280,14 @@ public function testStringLargerThanValidatorWithValuesOutOfRange() { $this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string longer than 0 characters, but got ""'); $parser = new StringParser(new Config(), 'name', ''); - $parser->largerThan(0)->required(); + $parser->lengthLargerThan(0)->required(); } public function testStringLargerThanOrEqualToValidatorWithValuesOutOfRange() { $this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string longer than or equal to 2 characters, but got "A"'); $parser = new StringParser(new Config(), 'name', 'A'); - $parser->largerThanOrEqualTo(2)->required(); + $parser->lengthLargerThanOrEqualTo(2)->required(); } public function testIntSmallerThanValidatorWithValuesOutOfRange() @@ -322,13 +322,13 @@ public function testStringSmallerThanValidatorWithValuesOutOfRange() { $this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string shorter than 1 characters, but got "A"'); $parser = new StringParser(new Config(), 'name', 'A'); - $parser->smallerThan(1)->required(); + $parser->lengthSmallerThan(1)->required(); } public function testStringSmallerThanOrEqualToValidatorWithValuesOutOfRange() { $this->setExpectedException(InvalidValueException::class, 'Invalid value for parameter "name". Expected a string shorter than or equal to 1 characters, but got "AB"'); $parser = new StringParser(new Config(), 'name', 'AB'); - $parser->smallerThanOrEqualTo(1)->required(); + $parser->lengthSmallerThanOrEqualTo(1)->required(); } } diff --git a/tests/TypeSpecTest.php b/tests/TypeSpecTest.php index a942e58..7c694bc 100644 --- a/tests/TypeSpecTest.php +++ b/tests/TypeSpecTest.php @@ -18,11 +18,11 @@ use MPScholten\RequestParser\FloatParser; use MPScholten\RequestParser\TrimParser; use MPScholten\RequestParser\Validator\IntLargerThanOrEqualToParser; -use MPScholten\RequestParser\Validator\StringBetweenParser; -use MPScholten\RequestParser\Validator\StringLargerThanOrEqualToParser; -use MPScholten\RequestParser\Validator\StringLargerThanParser; -use MPScholten\RequestParser\Validator\StringSmallerThanOrEqualToParser; -use MPScholten\RequestParser\Validator\StringSmallerThanParser; +use MPScholten\RequestParser\Validator\StringLengthBetween; +use MPScholten\RequestParser\Validator\StringLengthLargerThanOrEqualToParser; +use MPScholten\RequestParser\Validator\StringLengthLargerThanParser; +use MPScholten\RequestParser\Validator\StringLengthSmallerThanOrEqualToParser; +use MPScholten\RequestParser\Validator\StringLengthSmallerThanParser; use MPScholten\RequestParser\Validator\UrlParser; use MPScholten\RequestParser\Validator\FloatLargerThanOrEqualToParser; use MPScholten\RequestParser\Validator\FloatLargerThanParser; @@ -224,30 +224,30 @@ public function testCommaSeparatedBoolean() public function testStringBetween() { $spec = new TypeParser(new Config(), 'groupId', 'A'); - $this->assertInstanceOf(StringBetweenParser::class, $spec->string()->between(0, 1)); + $this->assertInstanceOf(StringLengthBetween::class, $spec->string()->lengthBetween(0, 1)); } public function testStringLargerThan() { $spec = new TypeParser(new Config(), 'groupId', 'A'); - $this->assertInstanceOf(StringLargerThanParser::class, $spec->string()->largerThan(0)); + $this->assertInstanceOf(StringLengthLargerThanParser::class, $spec->string()->lengthLargerThan(0)); } public function testStringLargerThanOrEqualTo() { $spec = new TypeParser(new Config(), 'groupId', 'A'); - $this->assertInstanceOf(StringLargerThanOrEqualToParser::class, $spec->string()->largerThanOrEqualTo(1)); + $this->assertInstanceOf(StringLengthLargerThanOrEqualToParser::class, $spec->string()->lengthLargerThanOrEqualTo(1)); } public function testStringSmallerThan() { $spec = new TypeParser(new Config(), 'groupId', 'A'); - $this->assertInstanceOf(StringSmallerThanParser::class, $spec->string()->smallerThan(2)); + $this->assertInstanceOf(StringLengthSmallerThanParser::class, $spec->string()->lengthSmallerThan(2)); } public function testStringSmallerThanOrEqualTo() { $spec = new TypeParser(new Config(), 'groupId', 'A'); - $this->assertInstanceOf(StringSmallerThanOrEqualToParser::class, $spec->string()->smallerThanOrEqualTo(1)); + $this->assertInstanceOf(StringLengthSmallerThanOrEqualToParser::class, $spec->string()->lengthSmallerThanOrEqualTo(1)); } }