Completed
Push — master ( 67caad...51f9cb )
by Abdelrahman
08:50 queued 07:47
created

ValidatingTrait::mergeRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Support\Traits;
6
7
use Watson\Validating\Injectors\UniqueWithInjector;
8
use Watson\Validating\ValidatingTrait as BaseValidatingTrait;
9
10
trait ValidatingTrait
11
{
12
    use UniqueWithInjector;
13
    use BaseValidatingTrait;
14
15
    /**
16
     * Merge new validation rules with existing validation rules on the model.
17
     *
18
     * @param array $rules
19
     *
20
     * @return $this
21
     */
22
    public function mergeRules(array $rules)
23
    {
24
        $this->rules = array_merge($this->rules, $rules);
0 ignored issues
show
Bug introduced by
The property rules 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...
25
26
        return $this;
27
    }
28
29
    /**
30
     * Register a validating event with the dispatcher.
31
     *
32
     * @param \Closure|string $callback
33
     *
34
     * @return void
35
     */
36
    public static function validating($callback)
37
    {
38
        static::registerModelEvent('validating', $callback);
39
    }
40
41
    /**
42
     * Register a validated event with the dispatcher.
43
     *
44
     * @param \Closure|string $callback
45
     *
46
     * @return void
47
     */
48
    public static function validated($callback)
49
    {
50
        static::registerModelEvent('validated', $callback);
51
    }
52
}
53