SkipOnErrorTrait::skipOnError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Trait;
6
7
/**
8
 * An implementation for {@see SkipOnErrorInterface} intended to be included in rules. Requires an additional private
9 27
 * class property `$skipOnError`. In package rules it's `false` by default:
10
 *
11 27
 * ```php
12 27
 * public function __construct(
13 27
 *     // ...
14
 *     private bool $skipOnError = false,
15
 *     // ...
16 811
 * ) {
17
 * }
18 811
 * ```
19
 */
20
trait SkipOnErrorTrait
21
{
22
    /**
23
     * An immutable setter to change `$skipOnError` property.
24
     *
25
     * @param bool $value A new value. `true` means to skip the current rule when the previous one errored and `false` -
26
     * do not skip.
27
     *
28
     * @return $this The new instance with a changed value.
29
     */
30
    public function skipOnError(bool $value): static
31
    {
32
        $new = clone $this;
33
        $new->skipOnError = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property skipOnError does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
        return $new;
35
    }
36
37
    /**
38
     * A getter for `$skipOnError` property.
39
     *
40
     * @return bool Current value. `true` means to skip the current rule when the previous one errored  and `false` - do
41
     * not skip.
42
     */
43
    public function shouldSkipOnError(): bool
44
    {
45
        return $this->skipOnError;
46
    }
47
}
48