NoiseIsAcceptable::evaluate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace XSolve\FaceValidatorBundle\Validator\Specification;
4
5
use XSolve\FaceValidatorBundle\Result\FaceDetectionResult;
6
use XSolve\FaceValidatorBundle\Result\NoiseLevel;
7
use XSolve\FaceValidatorBundle\Validator\Constraints\Face;
8
9
class NoiseIsAcceptable implements FaceValidationSpecification
10
{
11
    public function evaluate(FaceDetectionResult $result, Face $constraint): Evaluation
12
    {
13
        $acceptableLevel = new NoiseLevel($constraint->maxNoiseLevel);
14
        $actualLevel = $result->getNoise()->getLevel();
15
16
        if ($actualLevel->isLowerOrEqual($acceptableLevel)) {
17
            return new Evaluation(true);
18
        }
19
20
        return new Evaluation(false, $constraint->noiseMessage);
21
    }
22
}
23