-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dyer, Andy
committed
Aug 15, 2018
1 parent
d03ebf1
commit c1728c7
Showing
1 changed file
with
13 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,66 +6,59 @@ | |
use Respect\Validation\Exceptions\NestedValidationException; | ||
|
||
/** | ||
* Class Validator | ||
* | ||
* @author Andrew Dyer <[email protected]> | ||
* @category Validation | ||
* @see https://github.com/andrewdyer/slim3-validator | ||
* Class Validator. | ||
*/ | ||
class Validator | ||
{ | ||
|
||
/** @var array */ | ||
private $_errors = []; | ||
|
||
/** | ||
* | ||
* @return array | ||
*/ | ||
public function getErrors() | ||
public function getErrors(): array | ||
{ | ||
return $this->_errors; | ||
} | ||
|
||
/** | ||
* | ||
* @return boolean | ||
* @return bool | ||
*/ | ||
public function hasPassed() | ||
public function hasPassed(): bool | ||
{ | ||
return empty($this->_errors); | ||
} | ||
|
||
/** | ||
* | ||
* @param string $key | ||
* @param array $messages | ||
* @param array $messages | ||
* | ||
* @return $this | ||
*/ | ||
public function setErrors(string $key, array $messages) | ||
public function setErrors(string $key, array $messages): self | ||
{ | ||
$this->_errors[$key] = $messages; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
* @param string $string | ||
* | ||
* @return string | ||
*/ | ||
protected function formatName(string $string) | ||
protected function formatName(string $string): string | ||
{ | ||
return str_replace(["-", "_"], " ", ucfirst(strtolower($string))); | ||
return str_replace(['-', '_'], ' ', ucfirst(strtolower($string))); | ||
} | ||
|
||
/** | ||
* | ||
* @param Request $request | ||
* @param array $rules | ||
* @param array $rules | ||
* | ||
* @return $this | ||
*/ | ||
public function validate(Request $request, array $rules) | ||
public function validate(Request $request, array $rules): self | ||
{ | ||
foreach ($rules as $field => $validator) { | ||
try { | ||
|
@@ -78,5 +71,4 @@ public function validate(Request $request, array $rules) | |
|
||
return $this; | ||
} | ||
|
||
} |