EntityGeneratorValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\EntityGenerator\Middleware;
4
5
use Hechoenlaravel\JarvisFoundation\Exceptions\CommandValidationException;
6
use League\Tactician\Middleware;
7
use Illuminate\Support\Facades\Validator;
8
9
/**
10
 * Class EntityGeneratorValidator
11
 * @package Hechoenlaravel\JarvisFoundation\EntityGenerator\Middleware
12
 */
13 View Code Duplication
class EntityGeneratorValidator implements Middleware
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @var
17
     */
18
    public $validator;
19
20
    /**
21
     * validation rules
22
     * @var array
23
     */
24
    public $rules = [
25
        'name' => 'required',
26
        'description' => 'required',
27
        'slug' => 'required',
28
        'locked' => 'required|boolean'
29
    ];
30
31
    /**
32
     * @param Validator $validator
33
     */
34
    public function __construct(Validator $validator)
35
    {
36
        $this->validator = $validator;
37
    }
38
39
40
    /**
41
     * Validates the data coming into the handler
42
     * @param object $command
43
     * @param callable $next
44
     * @return mixed
45
     * @throws CommandValidationException
46
     */
47
    public function execute($command, callable $next)
48
    {
49
        $validator = Validator::make((array) $command, $this->rules);
50
        if ($validator->fails()) {
51
            throw new CommandValidationException($validator);
52
        }
53
        return $next($command);
54
    }
55
}
56