Passed
Push — master ( 908b7b...7b39fe )
by Arthur
02:58
created

GeneralRules::unique()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
4
namespace Larapie\Actions\Attributes\Rules;
5
6
7
use Illuminate\Validation\Rule;
8
use Larapie\Actions\Attribute;
9
10
trait GeneralRules
11
{
12
    /**
13
     * @return static
14
     */
15 1
    public function nullable()
16
    {
17 1
        return $this->rule('nullable');
0 ignored issues
show
Bug introduced by
It seems like rule() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        return $this->/** @scrutinizer ignore-call */ rule('nullable');
Loading history...
18
    }
19
20
    /**
21
     * @param \Closure|bool $callback
22
     * @return GeneralRules
23
     */
24
    public function requireIf($callback)
25
    {
26
        if (is_callable($callback)) {
27
            return call_user_func($callback) ? $this->require() : $this;
0 ignored issues
show
Bug introduced by
It seems like $callback can also be of type boolean; however, parameter $function of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            return call_user_func(/** @scrutinizer ignore-type */ $callback) ? $this->require() : $this;
Loading history...
Bug introduced by
The method require() does not exist on Larapie\Actions\Attributes\Rules\GeneralRules. Did you maybe mean requireIf()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
            return call_user_func($callback) ? $this->/** @scrutinizer ignore-call */ require() : $this;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
        }
29
30
        return $callback ? $this->require() : $this;
31
    }
32
33
    public function requiredIfField(string $field, ...$values)
34
    {
35
        return $this->rule("required_if:$field, " . implode(',', $values));
36
    }
37
38
    public function requiredUnlessField(string $field, ...$values)
39
    {
40
        return $this->rule("required_unless:$field," . implode(',', $values));
41
    }
42
43
44
    public function requiredWith(string ...$fields)
45
    {
46
        return $this->rule("required_with:" . implode(',', $fields));
47
    }
48
49
    public function requiredWithAll(string ...$fields)
50
    {
51
        return $this->rule("required_with_all:" . implode(',', $fields));
52
    }
53
54
    public function requiredWithout(string ...$fields)
55
    {
56
        return $this->rule("required_without:" . implode(',', $fields));
57
    }
58
59
    public function requiredWithoutAll(string ...$fields)
60
    {
61
        return $this->rule("required_without_all:" . implode(',', $fields));
62
    }
63
64
    public function distinct()
65
    {
66
        return $this->rule('distinct');
67
    }
68
69
    public function same(string $field)
70
    {
71
        return $this->rule("same:$field");
72
    }
73
74
    public function excludeIf(string $field, $value)
75
    {
76
        return $this->rule("exclude_if:$field,$value");
77
    }
78
79
    public function excludeUnless(string $field, $value)
80
    {
81
        return $this->rule("exclude_unless:$field,$value");
82
    }
83
84
    public function exists(string $table, string $column)
85
    {
86
        return $this->rule("exists:$table,$column");
87
    }
88
89
    public function filled()
90
    {
91
        return $this->rule('filled');
92
    }
93
94
    public function present()
95
    {
96
        return $this->rule('present');
97
    }
98
99
    public function url()
100
    {
101
        return $this->rule('url');
102
    }
103
104
    public function uuid()
105
    {
106
        return $this->rule('uuid');
107
    }
108
109
    public function unique(string $tableOrModel, string $column)
110
    {
111
        return $this->rule("unique:$tableOrModel,$column");
112
    }
113
}