Test Failed
Push — master ( f043ce...f1785b )
by Antonio Carlos
04:03
created

Database   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 18
cts 36
cp 0.5
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 19 4
A findFirstModel() 0 8 1
A getConnectionName() 0 6 2
A rawQuery() 0 29 2
1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use Illuminate\Support\Facades\DB;
6
use SebastianBergmann\Timer\Timer;
7
use PragmaRX\Health\Support\Result;
8
9
class Database extends Base
10
{
11
    /**
12
     * @return Result
13
     */
14 1
    public function check()
15
    {
16
        try {
17 1
            switch ($this->target->type) {
0 ignored issues
show
Bug introduced by
The property type 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...
18
                case 'find_first_model':
19 1
                    return $this->findFirstModel();
20
                case 'raw_query':
21 1
                    return $this->rawQuery();
22
            }
23
24
            throw new \Exception(
25
                "Target type '{$this->target->type}' does not exists"
26
            );
27 1
        } catch (\Exception $exception) {
28 1
            report($exception);
29
30 1
            return $this->makeResultFromException($exception);
31
        }
32
    }
33
34 1
    protected function findFirstModel()
35
    {
36
        collect($this->target->models)->each(function ($model) {
0 ignored issues
show
Bug introduced by
The property models 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...
37 1
            instantiate($model)->first();
38 1
        });
39
40
        return $this->makeHealthyResult();
41
    }
42
43 1
    protected function getConnectionName()
44
    {
45 1
        return $this->target->connection == 'default'
0 ignored issues
show
Bug introduced by
The property connection 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...
46 1
            ? config('database.default')
47 1
            : $this->target->connection;
48
    }
49
50 1
    protected function rawQuery()
51
    {
52 1
        Timer::start();
53
54 1
        DB::connection($this->getConnectionName())->select(
55 1
            DB::raw($this->target->query)
0 ignored issues
show
Bug introduced by
The property query 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...
56
        );
57
58
        $took = round(Timer::stop(), 5);
59
        $tookHuman = "{$took}s";
60
61
        $this->target->setDisplay($this->target->name." ({$tookHuman})");
62
63
        $result =
64
            $took > $this->target->maximumTime
0 ignored issues
show
Bug introduced by
The property maximumTime 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...
65
                ? $this->makeResult(
66
                    false,
67
                    sprintf(
68
                        $this->target->errorMessage,
0 ignored issues
show
Bug introduced by
The property errorMessage 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...
69
                        $took,
70
                        $this->target->maximumTime
71
                    )
72
                )
73
                : $this->makeHealthyResult();
74
75
        $result->setValue($took)->setValueHuman($tookHuman);
76
77
        return $result;
78
    }
79
}
80