Passed
Push — master ( e32a81...12baf4 )
by Antonio Carlos
02:26
created

Expression::expressionIsOk()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 16
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use PragmaRX\Health\Support\Result;
6
7
class Expression extends Base
8
{
9
    /**
10
     * Check resource.
11
     *
12
     * @return Result
13
     */
14 1
    public function check()
15
    {
16 1
        return $this->expressionIsOk()
17 1
            ? $this->makeHealthyResult()
18 1
            : $this->makeResult(false, $this->target->getErrorMessage());
19
    }
20
21 1
    public function expressionIsOk()
22
    {
23 1
        $expressionResult = $this->executeExpression(
24 1
            $this->target->expressionValue
0 ignored issues
show
Bug introduced by
The property expressionValue does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
25
        );
26
27 1
        if ($this->target->shouldReturn === true) {
0 ignored issues
show
Bug introduced by
The property shouldReturn does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
28 1
            return (bool) $expressionResult;
29
        }
30
31 1
        if ($this->target->shouldReturn === false) {
32 1
            return ! $expressionResult;
33
        }
34
35
        return preg_match("|{$this->target->shouldReturn}|", $expressionResult);
36
    }
37
38 1
    public function executeExpression($expression)
39
    {
40 1
        return eval("return {$expression} ;");
41
    }
42
}
43