Test Failed
Push — master ( bfe357...41d8e8 )
by Antonio Carlos
25:24
created

src/Checkers/Database.php (6 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    public function check()
15
    {
16
        try {
17
            switch ($this->target->type) {
0 ignored issues
show
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
                    return $this->findFirstModel();
20
                case 'raw_query':
21
                    return $this->rawQuery();
22
            }
23
24
            throw new \Exception(
25
                "Target type '{$this->target->type}' does not exists"
26
            );
27
        } catch (\Exception $exception) {
28
            report($exception);
29
30
            return $this->makeResultFromException($exception);
31
        }
32
    }
33
34
    protected function findFirstModel()
35
    {
36
        collect($this->target->models)->each(function ($model) {
0 ignored issues
show
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
            instantiate($model)->first();
38
        });
39
40
        return $this->makeHealthyResult();
41
    }
42
43
    protected function getConnectionName()
44
    {
45
        return $this->target->connection == 'default'
0 ignored issues
show
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
            ? config('database.default')
47
            : $this->target->connection;
48
    }
49
50
    protected function rawQuery()
51
    {
52
        Timer::start();
53
54
        DB::connection($this->getConnectionName())->select(
55
            DB::raw($this->target->query)
0 ignored issues
show
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
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
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