Skip to content

Commit

Permalink
Merge pull request #6 from kodumbeats/feat-validator-gettype
Browse files Browse the repository at this point in the history
Get expected types from validators
  • Loading branch information
eldadfux authored Apr 13, 2021
2 parents 78be43a + 6a17af8 commit b54ee9c
Show file tree
Hide file tree
Showing 36 changed files with 370 additions and 853 deletions.
27 changes: 27 additions & 0 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

abstract class Validator
{

const TYPE_BOOLEAN = "boolean";
const TYPE_INTEGER = "integer";
const TYPE_FLOAT = "double"; /* gettype() returns "double" for historical reasons */
const TYPE_STRING = "string";
const TYPE_ARRAY = "array";
const TYPE_OBJECT = "object";
const TYPE_MIXED = "mixed";

/**
* Get Description
*
Expand All @@ -23,6 +32,15 @@ abstract class Validator
*/
abstract public function getDescription();

/**
* Is array
*
* Returns true if an array or false if not.
*
* @return bool
*/
abstract public function isArray();

/**
* Is valid
*
Expand All @@ -32,4 +50,13 @@ abstract public function getDescription();
* @return bool
*/
abstract public function isValid($value);

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
abstract public function getType();
}
24 changes: 24 additions & 0 deletions src/Validator/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ public function getDescription()
return 'Value must be an array and ' . $this->validator->getDescription();
}

/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return true;
}

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return $this->validator->getType();
}

/**
* Is valid
*
Expand Down
24 changes: 24 additions & 0 deletions src/Validator/Assoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ public function getDescription()
return 'Value must be a valid object.';
}

/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return true;
}

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_ARRAY;
}

/**
* Is valid
*
Expand Down
24 changes: 24 additions & 0 deletions src/Validator/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ public function getDescription()
return 'Value must be a boolean';
}

/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_BOOLEAN;
}

/**
* Is valid
*
Expand Down
57 changes: 0 additions & 57 deletions src/Validator/Domain.php

This file was deleted.

54 changes: 0 additions & 54 deletions src/Validator/Email.php

This file was deleted.

24 changes: 24 additions & 0 deletions src/Validator/FloatValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ public function getDescription()
return 'Value must be a valid float';
}

/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_FLOAT;
}

/**
* Is valid
*
Expand Down
24 changes: 24 additions & 0 deletions src/Validator/HexColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ public function getDescription()
return 'Value must be a valid Hex color code';
}

/**
* Is array
*
* Function will return true if object is array.
*
* @return bool
*/
public function isArray(): bool
{
return false;
}

/**
* Get Type
*
* Returns validator type.
*
* @return string
*/
public function getType(): string
{
return self::TYPE_STRING;
}

/**
* @param mixed $value
* @return bool
Expand Down
70 changes: 0 additions & 70 deletions src/Validator/Host.php

This file was deleted.

Loading

0 comments on commit b54ee9c

Please sign in to comment.