Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve db name solution #289

Merged
merged 1 commit into from Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/SolutionProviders/DefaultDbNameSolutionProvider.php
Expand Up @@ -2,10 +2,9 @@

namespace Facade\Ignition\SolutionProviders;

use Exception;
use Facade\Ignition\Solutions\SuggestUsingCorrectDbNameSolution;
use Facade\IgnitionContracts\HasSolutionsForThrowable;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\QueryException;
use Throwable;

class DefaultDbNameSolutionProvider implements HasSolutionsForThrowable
Expand All @@ -14,24 +13,23 @@ class DefaultDbNameSolutionProvider implements HasSolutionsForThrowable

public function canSolve(Throwable $throwable): bool
{
try {
DB::connection()->select('SELECT 1');
} catch (Exception $exception) {
if ($this->isUnknownDatabaseCode($exception->getCode())) {
return in_array(env('DB_DATABASE'), ['homestead', 'laravel']);
}
if (! $throwable instanceof QueryException) {
return false;
}

return false;
if ($throwable->getCode() !== self::MYSQL_UNKNOWN_DATABASE_CODE) {
return false;
}

if (! in_array(env('DB_DATABASE'), ['homestead', 'laravel'])) {
return false;
}

return true;
}

public function getSolutions(Throwable $throwable): array
{
return [new SuggestUsingCorrectDbNameSolution()];
}

protected function isUnknownDatabaseCode($code): bool
{
return $code === static::MYSQL_UNKNOWN_DATABASE_CODE;
}
}