LessThanCheck   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A getIdentifier() 0 3 1
A run() 0 6 2
1
<?php
2
3
namespace Leankoala\HealthFoundation\Check\Basic\Number;
4
5
use Leankoala\HealthFoundation\Check\Check;
6
use Leankoala\HealthFoundation\Check\Result;
7
8
/**
9
 * Class LessThanCheck
10
 *
11
 * Checks if a given number is less than an expected value
12
 *
13
 * @package Leankoala\HealthFoundation\Check\Basic\Number
14
 */
15
class LessThanCheck implements Check
16
{
17
    const IDENTIFIER = 'base:basic:number:lessThan';
18
19
    private $maxValue;
20
    private $currentValue;
21
    private $valueName = "";
22
23
    public function init($currentValue, $maxValue, $valueName)
24
    {
25
        $this->maxValue = $maxValue;
26
        $this->currentValue = $currentValue;
27
        $this->valueName = $valueName;
28
    }
29
30
    public function run()
31
    {
32
        if ($this->currentValue > $this->maxValue) {
33
            return new Result(Result::STATUS_FAIL, 'The given value ("' . $this->valueName . '") is ' . $this->currentValue . ' and too big, it must be less than ' . $this->maxValue . '.');
34
        } else {
35
            return new Result(Result::STATUS_PASS, 'The value ("' . $this->valueName . '") was ' . $this->currentValue . '. Maximum was < ' . $this->maxValue . '.');
36
        }
37
    }
38
39
    public function getIdentifier()
40
    {
41
        return self::IDENTIFIER . ':' . $this->valueName;
42
    }
43
}
44