Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ArrayValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class ArrayValidator extends \Phramework\Validate\BaseValidator
*/
public function __construct(
int $minItems = 0,
int $maxItems = null,
$items = null,
?int $maxItems = null,
?BaseValidator $items = null,
bool $uniqueItems = false
) {
parent::__construct();
Expand All @@ -98,7 +98,6 @@ public function validate($value)
$return = new Result($value, false);

if (!is_array($value)) {
$return->exception = 'properties validation';
//error
$return->exception = new IncorrectParameterException(
'type',
Expand Down
5 changes: 3 additions & 2 deletions src/BooleanValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class BooleanValidator extends \Phramework\Validate\BaseValidator
* BooleanValidator constructor.
* @param bool|null $default
*/
public function __construct(bool $default = null)
{
public function __construct(
?bool $default = null
) {
parent::__construct();

$this->default = $default;
Expand Down
4 changes: 2 additions & 2 deletions src/DateValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class DateValidator extends \Phramework\Validate\StringValidator
* ```
*/
public function __construct(
string $formatMinimum = null,
string $formatMaximum = null
?string $formatMinimum = null,
?string $formatMaximum = null
) {
parent::__construct();

Expand Down
4 changes: 2 additions & 2 deletions src/DatetimeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class DatetimeValidator extends \Phramework\Validate\StringValidator
* ```
*/
public function __construct(
string $formatMinimum = null,
string $formatMaximum = null
?string $formatMinimum = null,
?string $formatMaximum = null
) {
parent::__construct();

Expand Down
6 changes: 3 additions & 3 deletions src/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class EmailValidator extends \Phramework\Validate\StringValidator
protected static $type = 'email';

public function __construct(
$minLength = 0,
$maxLength = null
int $minLength = 0,
?int $maxLength = null
) {
parent::__construct(
$minLength,
Expand All @@ -62,7 +62,7 @@ public function validate($value)
$return = parent::validate($value);

//Apply additional rules
if ($return->status == true) {
if ($return->status === true) {
if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
//error
$return->exception = new IncorrectParameterException(
Expand Down
2 changes: 1 addition & 1 deletion src/EnumValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EnumValidator extends \Phramework\Validate\BaseValidator

public function __construct(
array $enum = [],
$validateType = false,
bool $validateType = false,
$default = null
) {
parent::__construct();
Expand Down
26 changes: 7 additions & 19 deletions src/IntegerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Integer validator
* @uses \Phramework\Validate\Number As base implementation's rules to
* validate that the value is a number and then applies additional rules
* to validate that this is a interger
* to validate that this is a integer
* @property integer|null minimum
* @property integer|null maximum
* @property boolean|null exclusiveMinimum
Expand All @@ -44,30 +44,18 @@ class IntegerValidator extends \Phramework\Validate\NumberValidator
protected static $type = 'integer';

/**
* @param integer|null $minimum
* @param integer|null $maximum
* @param boolean|null $exclusiveMinimum
* @param boolean|null $exclusiveMaximum
* @param integer|null $multipleOf
* @throws \Exception
* @throws \InvalidArgumentException When multipleOf is not positive integer
* @throws \DomainException
*/
public function __construct(
int $minimum = null,
int $maximum = null,
?int $minimum = null,
?int $maximum = null,
bool $exclusiveMinimum = null,
bool $exclusiveMaximum = null,
int $multipleOf = 1
) {
if ($minimum !== null && !is_int($minimum)) {
throw new \Exception('Minimum must be integer');
}

if ($maximum !== null && !is_int($maximum)) {
throw new \Exception('Maximum must be integer');
}

if (!is_int($multipleOf) || $multipleOf < 0) {
throw new \Exception('multipleOf must be a positive integer');
if ($multipleOf !== null && $multipleOf <= 0) {
throw new \InvalidArgumentException('multipleOf must be a positive integer');
}

parent::__construct(
Expand Down
39 changes: 9 additions & 30 deletions src/NumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,23 @@ class NumberValidator extends \Phramework\Validate\BaseValidator
protected static $type = 'number';

/**
* @param float|null $minimum
* @param float|null $maximum
* @param bool|null $exclusiveMinimum
* @param bool|null $exclusiveMaximum
* @param float|null $multipleOf
* @throws \Exception
* @throws \DomainException When minimum is not less than the maximum
*/
public function __construct(
float $minimum = null,
float $maximum = null,
bool $exclusiveMinimum = null,
bool $exclusiveMaximum = null,
float $multipleOf = null
?float $minimum = null,
?float $maximum = null,
?bool $exclusiveMinimum = null,
?bool $exclusiveMaximum = null,
?float $multipleOf = null
) {
parent::__construct();

if ($minimum !== null && !is_numeric($minimum)) {
throw new \Exception('Minimum must be numeric');
}

if ($maximum !== null && !is_numeric($maximum)) {
throw new \Exception('Maximum must be numeric');
}

if ($maximum !== null && $minimum !== null && $maximum < $minimum) {
throw new \Exception('maximum cant be less than minimum');
}

if ($exclusiveMinimum !== null && !is_bool($exclusiveMinimum)) {
throw new \Exception('exclusiveMinimum must be boolean');
}

if ($exclusiveMaximum !== null && !is_bool($exclusiveMaximum)) {
throw new \Exception('exclusiveMaximum must be boolean');
throw new \DomainException('maximum cant be less than minimum');
}

if ($multipleOf !== null && !is_numeric($multipleOf)) {
throw new \Exception('multipleOf must be numeric');
if ($multipleOf !== null && $multipleOf <= 0) {
throw new \InvalidArgumentException('multipleOf must be a positive number');
}

$this->minimum = $minimum;
Expand Down
2 changes: 1 addition & 1 deletion src/ObjectValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
array $required = [],
$additionalProperties = true,
int $minProperties = 0,
int $maxProperties = null,
?int $maxProperties = null,
\stdClass $dependencies = null,
\stdClass $xVisibility = null,
\stdClass $patternProperties = null
Expand Down
2 changes: 1 addition & 1 deletion src/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Result
public function __construct(
$value,
bool $status = false,
\Exception $exception = null
?\Exception $exception = null
) {
$this->value = $value;
$this->status = $status;
Expand Down
4 changes: 2 additions & 2 deletions src/StringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class StringValidator extends \Phramework\Validate\BaseValidator
*/
public function __construct(
int $minLength = 0,
int $maxLength = null,
string $pattern = null,
?int $maxLength = null,
?string $pattern = null,
bool $raw = false
) {
parent::__construct();
Expand Down
2 changes: 1 addition & 1 deletion src/URLValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class URLValidator extends \Phramework\Validate\StringValidator
*/
public function __construct(
int $minLength = 0,
int $maxLength = null
?int $maxLength = null
) {
parent::__construct(
$minLength,
Expand Down
14 changes: 5 additions & 9 deletions src/UnsignedIntegerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,18 @@ class UnsignedIntegerValidator extends \Phramework\Validate\IntegerValidator
protected static $type = 'unsignedinteger';

/**
* @param int $minimum
* @param int|null $maximum
* @param int|null $exclusiveMinimum
* @param bool|null $exclusiveMaximum
* @param int $multipleOf
* @throws \Exception
* @throws \InvalidArgumentException
* @throws \DomainException
*/
public function __construct(
int $minimum = 0,
int $maximum = null,
?int $maximum = null,
bool $exclusiveMinimum = null,
bool $exclusiveMaximum = null,
int $multipleOf = 1
?int $multipleOf = 1
) {
if ($minimum < 0) {
throw new \Exception('Minimum cannot be negative');
throw new \InvalidArgumentException('Minimum cannot be negative');
}

parent::__construct(
Expand Down
2 changes: 1 addition & 1 deletion src/UsernameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function getUsernamePattern() : string
*/
public function __construct(
int $minLength = 0,
int $maxLength = null
?int $maxLength = null
) {
parent::__construct(
$minLength,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/ArrayValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function tearDown()
}

/**
* @expectedException \Exception
* @expectedException \TypeError
*/
public function testConstructFailure1()
{
Expand All @@ -52,7 +52,7 @@ public function testConstructFailure3()
}

/**
* @expectedException \Exception
* @expectedException \TypeError
*/
public function testConstructFailure4()
{
Expand Down
15 changes: 14 additions & 1 deletion tests/src/IntegerValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class IntegerValidatorTest extends TestCase
{

/**
* @var IntegerValidator
*/
Expand Down Expand Up @@ -188,4 +187,18 @@ public function testForOverflow()

$this->assertSame($value, $parsed);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testShouldFailWhenMultipleOfIsNotPositiveInteger()
{
new IntegerValidator(
null,
null,
null,
null,
-1
);
}
}
Loading