Passed
Push — master ( e0f7b0...4354d2 )
by Vladimir
05:39 queued 20s
created

Check   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 30
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 23 4
1
<?php
2
/**
3
 * This file is part of the `tvi/monitor-bundle` project.
4
 *
5
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
10
11
namespace Tvi\MonitorBundle\Check\sys\CpuPerformance;
12
13
use ZendDiagnostics\Result\Failure;
14
use ZendDiagnostics\Result\Success;
15
use ZendDiagnostics\Result\Warning;
16
use Tvi\MonitorBundle\Check\CheckInterface;
17
use Tvi\MonitorBundle\Check\CheckTrait;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @author Vladimir Turnaev <[email protected]>
21
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
22
class Check extends \ZendDiagnostics\Check\CpuPerformance implements CheckInterface
23
{
24
    use CheckTrait;
25
26
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
     * @inheritdoc
28
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
29 2
    public function check()
30
    {
31
        // Check if bcmath extension is present
32
        // @codeCoverageIgnoreStart
33
        if (! extension_loaded('bcmath')) {
34
            return new Warning('Check\CpuPerformance requires BCMath extension to be loaded.');
35
        }
36
        // @codeCoverageIgnoreEnd
37
38 2
        $timeStart = microtime(true);
39 2
        $result = static::calcPi(1000);
40 2
        $duration = microtime(true) - $timeStart;
41 2
        $performance = round($duration / $this->baseline, 5);
42
43 2
        if ($result != $this->expectedResult) {
44
            // Ignore code coverage here because it's impractical to test against faulty calculations.
45
            // @codeCoverageIgnoreStart
46
            return new Warning('PI calculation failed. This might mean CPU or RAM failure', $result);
47
            // @codeCoverageIgnoreEnd
48 2
        } elseif ($performance > $this->minPerformance) {
49 2
            return new Success(sprintf('Cpu Performance is %.5f.', $performance), $performance);
50
        } else {
51 1
            return new Failure(null, $performance);
52
        }
53
    }
54
}
55