InputPurifier::handleRuleViolation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Controller;
4
5
use WebTheory\Saveyour\Contracts\Controller\InputPurifierInterface;
6
use WebTheory\Saveyour\Contracts\Formatting\InputFormatterInterface;
7
use WebTheory\Saveyour\Contracts\Validation\ValidatorInterface;
8
9
class InputPurifier implements InputPurifierInterface
10
{
11
    protected ValidatorInterface $validator;
12
13
    protected InputFormatterInterface $formatter;
14
15 9
    public function __construct(ValidatorInterface $validator, InputFormatterInterface $formatter)
16
    {
17 9
        $this->validator = $validator;
18 9
        $this->formatter = $formatter;
19
    }
20
21 9
    public function handleInput($input)
22
    {
23 9
        $report = $this->validator->inspect($input);
24
25 9
        if (true === $report->validationStatus()) {
26 3
            return $this->formatter->formatInput($input);
27
        }
28
29 6
        foreach ($report->ruleViolations() as $violation) {
30 6
            $this->handleRuleViolation($violation);
31
        }
32
33 6
        return $this->returnIfFailed();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->returnIfFailed() targeting WebTheory\Saveyour\Contr...ifier::returnIfFailed() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
34
    }
35
36 6
    protected function returnIfFailed()
37
    {
38 6
        return null;
39
    }
40
41
    protected function handleRuleViolation($rule): void
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed. ( Ignorable by Annotation )

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

41
    protected function handleRuleViolation(/** @scrutinizer ignore-unused */ $rule): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        //
44
    }
45
}
46