Skip to content

Commit

Permalink
bug fix in src/Validation/Rules.php
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfaramarzi committed Sep 9, 2021
1 parent 0a38219 commit 181d9bd
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ trait Rules
protected function required(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if (! $item || empty($item)){
if (!$item || !isset($index) || empty($item)){
$this->saveError($parameters , $index);
}
}
return;
}
if (! $data || empty($data)){
if (!$data || !isset($data) || empty($data)){
$this->saveError($parameters);
}
}

protected function string(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !is_string($item)){
$this->saveError($parameters , $index);
Expand All @@ -42,7 +42,7 @@ protected function string(array $parameters): void
protected function integer(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !is_int($item)){
$this->saveError($parameters , $index);
Expand All @@ -58,7 +58,7 @@ protected function integer(array $parameters): void
protected function boolean(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !is_bool($item)){
$this->saveError($parameters , $index);
Expand All @@ -74,7 +74,7 @@ protected function boolean(array $parameters): void
protected function array(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !is_array($item)){
$this->saveError($parameters , $index);
Expand All @@ -90,7 +90,7 @@ protected function array(array $parameters): void
protected function email(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && false === filter_var($item, FILTER_VALIDATE_EMAIL)){
$this->saveError($parameters , $index);
Expand All @@ -106,7 +106,7 @@ protected function email(array $parameters): void
protected function regex(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !preg_match($parameters['value'], $item)){
$this->saveError($parameters , $index);
Expand All @@ -122,7 +122,7 @@ protected function regex(array $parameters): void
protected function notRegex(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && preg_match($parameters['value'], $item)){
$this->saveError($parameters , $index);
Expand All @@ -138,7 +138,7 @@ protected function notRegex(array $parameters): void
protected function max(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
if (is_string($item) && $this->strlen($item) >= $parameters['value']){
Expand Down Expand Up @@ -167,7 +167,7 @@ protected function max(array $parameters): void
protected function min(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
if (is_string($item) && $this->strlen($item) <= $parameters['value']){
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function min(array $parameters): void
protected function size(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
if (is_string($item) && $this->strlen($item) != $parameters['value']){
Expand Down Expand Up @@ -225,15 +225,15 @@ protected function size(array $parameters): void
protected function date(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && ! $this->validateDate($item , is_null($parameters['value']) ? 'Y-m-d H:i:s' : $parameters['value'])){
if ($item && !$this->validateDate($item , is_null($parameters['value']) ? 'Y-m-d H:i:s' : $parameters['value'])){
$this->saveError($parameters , $index);
}
}
return;
}
if ($data && ! $this->validateDate($data , is_null($parameters['value']) ? 'Y-m-d H:i:s' : $parameters['value'])){
if ($data && !$this->validateDate($data , is_null($parameters['value']) ? 'Y-m-d H:i:s' : $parameters['value'])){
$this->saveError($parameters);
}
}
Expand All @@ -242,7 +242,7 @@ protected function after(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
$value = $this->get($this->data , $parameters['value']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && $value && $item <= $value){
$this->saveError($parameters , $index);
Expand All @@ -259,7 +259,7 @@ protected function before(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
$value = $this->get($this->data , $parameters['value']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && $value && $item >= $value){
$this->saveError($parameters , $index);
Expand All @@ -276,7 +276,7 @@ protected function in(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
$array = explode(',' , $parameters['value']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item && !in_array($item , $array)){
$this->saveError($parameters , $index);
Expand All @@ -292,10 +292,10 @@ protected function in(array $parameters): void
protected function nationalCode(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
if(! preg_match('/^[0-9]{10}$/' , $item)){
if(!preg_match('/^[0-9]{10}$/' , $item)){
$this->saveError($parameters , $index);
return;
}
Expand All @@ -322,7 +322,7 @@ protected function nationalCode(array $parameters): void
return;
}
if ($data){
if(! preg_match('/^[0-9]{10}$/' , $data)){
if(!preg_match('/^[0-9]{10}$/' , $data)){
$this->saveError($parameters);
return;
}
Expand Down Expand Up @@ -350,7 +350,7 @@ protected function nationalCode(array $parameters): void
protected function exists(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
$check = $this->checkDB($item , $parameters['value']);
Expand All @@ -374,7 +374,7 @@ protected function exists(array $parameters): void
protected function unique(array $parameters): void
{
$data = $this->get($this->data , $parameters['rule']);
if (is_array($data)){
if (str_contains($parameters['rule'] , '*') && $data) {
foreach ($data as $index => $item){
if ($item){
$check = $this->checkDB($item , $parameters['value']);
Expand Down Expand Up @@ -433,8 +433,8 @@ protected function saveError(array $parameters , ?int $index = null): void
$this->errors[] = [
'message' => $parameters['message'] ,
'field' => [
'local' => $parameters['localeField'] ,
'nonLocal' => $parameters['rule'] ,
'locale' => $parameters['localeField'] ,
'nonLocale' => $parameters['rule'] ,
]
];
return;
Expand All @@ -443,8 +443,8 @@ protected function saveError(array $parameters , ?int $index = null): void
$this->errors[] = [
'message' => $parameters['message'] ,
'field' => [
'local' => $parameters['localeField'] ,
'nonLocal' => $parameters['rule'] ,
'locale' => $parameters['localeField'] ,
'nonLocale' => $parameters['rule'] ,
]
];
}
Expand Down

0 comments on commit 181d9bd

Please sign in to comment.