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

DefaultDbNameSolutionProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canSolve() 0 12 3
A getSolutions() 0 4 1
A canTryDatabaseConnection() 0 4 1
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