for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Napp\Core\Api\Validation;
use Illuminate\Contracts\Validation\Factory as ValidatorFactory;
use Illuminate\Contracts\Validation\Validator;
use Napp\Core\Api\Exceptions\Exceptions\ValidationException;
/**
* Trait ValidateTrait.
*/
trait ValidateTrait
{
* @param array $attributes
* @param array $rules
*
* @throws ValidationException
* @return void
public static function validate(array $attributes, array $rules)
/** @var Validator $validator */
$validator = static::getValidatorFactory()->make($attributes, $rules);
if (true === $validator->fails()) {
$message = $validator->messages()->first();
$exception = new ValidationException();
$exception->statusMessage = $exception->statusMessage . ': ' . $message;
$exception->validation = $validator->messages();
$validator->messages()
Illuminate\Support\MessageBag
array
$validation
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
throw $exception;
}
* @return ValidatorFactory
protected static function getValidatorFactory()
return app(ValidatorFactory::class);
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..