InteractsWithValidationData   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A validated() 0 8 1
A only() 0 18 4
A replace() 0 4 1
1
<?php
2
3
namespace PerfectOblivion\Valid\ValidationService\Concerns;
4
5
use stdClass;
6
use Illuminate\Support\Arr;
7
8
trait InteractsWithValidationData
9
{
10
    /**
11
     * Get all data under validation.
12
     *
13
     * @return array
14
     */
15
    public function all()
16
    {
17
        return $this->data;
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
    }
19
20
    /**
21
     * Get the validated data from the request.
22
     *
23
     * @return array
24
     */
25
    public function validated()
26
    {
27
        $rules = $this->container->call([$this, 'rules']);
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
29
        return $this->only(collect($rules)->keys()->map(function ($rule) {
30
            return explode('.', $rule)[0];
31
        })->unique()->toArray());
32
    }
33
34
    /**
35
     * Get a subset containing the provided keys with values from the given data.
36
     *
37
     * @param  array|mixed  $keys
38
     *
39
     * @return array
40
     */
41
    public function only($keys)
42
    {
43
        $results = [];
44
45
        $input = $this->all();
46
47
        $placeholder = new stdClass;
48
49
        foreach (is_array($keys) ? $keys : func_get_args() as $key) {
50
            $value = data_get($input, $key, $placeholder);
51
52
            if ($value !== $placeholder) {
53
                Arr::set($results, $key, $value);
54
            }
55
        }
56
57
        return $results;
58
    }
59
60
    /**
61
     * Replaces the current parameters by a new set.
62
     *
63
     * @param  array  $parameters
0 ignored issues
show
Bug introduced by
There is no parameter named $parameters. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
64
     */
65
    public function replace(array $data)
66
    {
67
        $this->data = $data;
68
    }
69
}
70