FieldGeneratorValidator::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware;
4
5
use Validator;
6
use League\Tactician\Middleware;
7
use Hechoenlaravel\JarvisFoundation\Exceptions\FieldValidationException;
8
9
/**
10
 * Class FieldGeneratorValidator
11
 * @package Hechoenlaravel\JarvisFoundation\FieldGenerator\Middleware
12
 */
13 View Code Duplication
class FieldGeneratorValidator 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
     * Rules to validate a Field
17
     * @var array
18
     */
19
    protected $rules = [
20
        'name' => 'required',
21
        'description' => 'required',
22
        'entity_id' => 'required|exists:app_entities,id',
23
        'type' => 'required'
24
    ];
25
26
    /**
27
     * Validate field type information
28
     * @param object $command
29
     * @param callable $next
30
     *
31
     * @return mixed
32
     */
33
    public function execute($command, callable $next)
34
    {
35
        $validator = Validator::make((array) $command, $this->rules);
36
        if ($validator->fails()) {
37
            throw new FieldValidationException($validator);
38
        }
39
        return $next($command);
40
    }
41
}
42