Completed
Push — master ( 883653...0fb449 )
by Vladimir
10:59 queued 04:58
created

Check   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

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