StatusGuesser::isOk()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
rs 9.6666
c 2
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Guesser;
17
18
use Hogosha\Monitor\Model\Result;
19
20
/**
21
 * Class StatusGuesser.
22
 */
23
class StatusGuesser
24
{
25
    const IDENTIFIED = 1;
26
    const RESOLVED = 0;
27
28
    /**
29
     * isOk.
30
     *
31
     * @param Result $result
32
     *
33
     * @return bool Return true is the condition is true
34
     */
35
    public function isOk(Result $result)
36
    {
37
        //The validator is used, so we can apply the rule
38
        if (null !== $result->getValidatorResult()) {
39
            return ($result->getUrl()->getExpectedStatus() == $result->getStatusCode()) && $result->getValidatorResult();
40
        }
41
42
        return $result->getUrl()->getExpectedStatus() == $result->getStatusCode();
43
    }
44
45
    /**
46
     * isFailed.
47
     *
48
     * @param Result $result
49
     *
50
     * @return bool Return true is the condition is false
51
     */
52
    public function isFailed(Result $result)
53
    {
54
        return !$this->isOk($result);
55
    }
56
}
57