-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a061506
commit 437ca1e
Showing
8 changed files
with
331 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* Integer rule. | ||
* | ||
* PHP Version 7.2.11-3 | ||
* | ||
* @package Verum-PHP | ||
* @license MIT https://github.com/SandroMiguel/verum-php/blob/master/LICENSE | ||
* @author Sandro Miguel Marques <[email protected]> | ||
* @copyright 2022 Sandro | ||
* @since Verum-PHP 2.1.0 | ||
* @version 1.0.0 (2022/07/13) | ||
* @link https://github.com/SandroMiguel/verum-php | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Verum\Rules; | ||
|
||
/** | ||
* Class Integer | src/Rules/Integer.php | ||
* Checks whether the value is integer. | ||
*/ | ||
final class Integer extends Rule | ||
{ | ||
/** | ||
* Integer constructor. | ||
* | ||
* @param mixed $fieldValue Field Value to validate. | ||
* | ||
* @version 1.0.0 (2022/07/13) | ||
* @since Verum 2.1.0 | ||
*/ | ||
public function __construct(mixed $fieldValue) | ||
{ | ||
$this->fieldValue = $fieldValue; | ||
} | ||
|
||
/** | ||
* Validates the field value against the rule. | ||
* | ||
* @return bool Returns TRUE if it passes the validation, FALSE otherwise. | ||
* | ||
* @version 1.0.0 (2022/07/13) | ||
* @since Verum 2.1.0 | ||
*/ | ||
public function validate(): bool | ||
{ | ||
if ($this->fieldValue === null || $this->fieldValue === '') { | ||
return true; | ||
} | ||
|
||
return is_int($this->fieldValue); | ||
} | ||
|
||
/** | ||
* Error Message Parameters. | ||
* | ||
* @return array<int, string> Returns the parameters for the error message. | ||
* | ||
* @version 1.0.0 (2022/07/13) | ||
* @since Verum 2.1.0 | ||
*/ | ||
public function getErrorMessageParameters(): array | ||
{ | ||
return [$this->fieldLabel]; | ||
} | ||
} |
Oops, something went wrong.