Test Failed
Push — master ( 2c2c87...ed1c51 )
by Chris
25:05 queued 37s
created

AbstractInputManager::getRule()   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
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Leonidas\Library\Admin\Processing;
4
5
use WebTheory\Saveyour\Contracts\InputFormatterInterface;
6
use WebTheory\Saveyour\Contracts\ValidatorInterface;
7
8
abstract class AbstractInputManager
9
{
10
    protected ValidatorInterface $validator;
11
12
    protected InputFormatterInterface $formatter;
13
14
    public function __construct(ValidatorInterface $validator, InputFormatterInterface $formatter)
15
    {
16
        $this->validator = $validator;
17
        $this->formatter = $formatter;
18
    }
19
20
    public function handleInput($input)
21
    {
22
        $result = $this->validator->validate($input);
23
24
        if (true === $result->getStatus()) {
25
            return $this->formatter->formatInput($input);
26
        }
27
28
        foreach ($result->getViolations() as $violation) {
29
            $this->handleRuleViolation($violation);
30
        }
31
32
        return $this->returnIfFailed();
33
    }
34
35
    abstract protected function returnIfFailed();
36
37
    abstract protected function handleRuleViolation($rule): void;
38
}
39