Completed
Push — master ( 88a2af...23feda )
by Marcel
01:37
created

canTryDatabaseConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Facade\Ignition\SolutionProviders;
4
5
use Throwable;
6
use Illuminate\Support\Facades\DB;
7
use Facade\IgnitionContracts\HasSolutionsForThrowable;
8
use Facade\Ignition\Solutions\SuggestUsingCorrectDbNameSolution;
9
10
class DefaultDbNameSolutionProvider implements HasSolutionsForThrowable
11
{
12
    public function canSolve(Throwable $throwable): bool
13
    {
14
        if ($this->canTryDatabaseConnection()) {
15
            try {
16
                DB::connection()->select('SELECT 1');
17
            } catch (\Exception $e) {
18
                return env('DB_DATABASE') === 'homestead';
19
            }
20
        }
21
22
        return false;
23
    }
24
25
    public function getSolutions(Throwable $throwable): array
26
    {
27
        return [new SuggestUsingCorrectDbNameSolution()];
28
    }
29
30
    protected function canTryDatabaseConnection()
31
    {
32
        return version_compare(app()->version(), '5.6.0', '>=');
33
    }
34
}
35