FilterFieldFromInput::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Entries\Middleware;
4
5
use League\Tactician\Middleware;
6
7
class FilterFieldFromInput implements Middleware
8
{
9
    /**
10
     * @param object $command
11
     * @param callable $next
12
     *
13
     * @return mixed
14
     */
15
    public function execute($command, callable $next)
16
    {
17
        $fields = $command->entity->fields->pluck('slug', 'slug')->toArray();
18
        foreach ($command->input as $key => $input) {
19
            if (!isset($fields[$key])) {
20
                unset($command->input[$key]);
21
            }
22
        }
23
        return $next($command);
24
    }
25
}
26