Passed
Push — main ( 46058f...95f3d8 )
by Breno
01:32
created

StopOnFailure::setStopSign()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation;
5
6
use InvalidArgumentException;
7
8
trait StopOnFailure
9
{
10
    private int $stopOnFailure;
11
12
    public function withStopSign(int $stopSign): static
13
    {
14
        $instance = clone $this;
15
        $instance->setStopSign($stopSign);
16
        return $instance;
17
    }
18
19
    protected function setStopSign(int $stopSign): void
20
    {
21
        if (! in_array($stopSign, StopSign::allowed())) {
22
            throw new InvalidArgumentException(sprintf('Invalid stop sign (%s)', $stopSign));
23
        }
24
25
        $this->stopOnFailure = $stopSign;
26
    }
27
28
    public function stopOnFailure(): int
29
    {
30
        return $this->stopOnFailure;
31
    }
32
}
33