Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hakobyansen committed Jan 20, 2019
1 parent 2b3bb8a commit a6b2765
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/Core/RBValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@

namespace RB\Core;

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Validator;

class RBValidator
{
use ValidatorTrait;

/**
* @param $data
* @param $rules
* @param $messages
* @return true
* @param Validator $validator
* @return bool
*/
public static function validate( $data, $rules, $messages = [] )
public static function validate( Validator $validator ): bool
{
$Validator = Validator::make( $data, $rules, $messages );

if( $Validator->fails() )
if( $validator->fails() )
{
self::throwResponseException( $Validator );
self::throwResponseException( $validator );
}

return true;
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/RBValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Unit;

use Illuminate\Support\Facades\Validator;
use Orchestra\Testbench\TestCase;
use RB\Core\RBValidator;

Expand Down Expand Up @@ -33,6 +34,8 @@ public function testValidate()
'city' => 'required'
];

$this->assertTrue( RBValidator::validate( $data, $rules ) );
$validator = Validator::make( $data, $rules );

$this->assertTrue( RBValidator::validate( $validator ) );
}
}

0 comments on commit a6b2765

Please sign in to comment.