DevBuild::getCalculatedAnswer()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 21
rs 9.7998
cc 3
nc 5
nop 0
1
<?php
2
3
namespace Sunnysideup\HealthCheckProvider\Checks\Database;
4
5
use Exception;
6
7
use SilverStripe\ORM\DatabaseAdmin;
8
use Sunnysideup\HealthCheckProvider\Checks\HealthCheckItemRunner;
9
10
class DevBuild extends HealthCheckItemRunner
11
{
12
    private static $include_dev_build = false;
0 ignored issues
show
introduced by
The private property $include_dev_build is not used, and could be removed.
Loading history...
13
14
    public function getCalculatedAnswer(): string
15
    {
16
        if ($this->Config()->get('include_dev_build')) {
17
            $db = new DatabaseAdmin();
18
            $start = microtime(true);
19
            $answer = '';
20
            try {
21
                $db->doBuild(true, false, false);
22
                $end = microtime(true) - $start;
23
24
                $answer = sprintf(
25
                    'Completed in %s seconds',
26
                    round($end, 2)
27
                );
28
            } catch (Exception $exception) {
29
                $answer = 'Error retrieving data: ' . $exception->getMessage();
30
            }
31
32
            return $answer;
33
        }
34
        return '
35
                Feature not enabled on host.
36
                Please set DevBuild::$include_dev_build = true in yml config files.
37
            ';
38
    }
39
}
40