Completed
Pull Request — master (#119)
by
unknown
01:20
created

canSolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Facade\Ignition\SolutionProviders;
4
5
use Throwable;
6
use LogicException;
7
use Facade\IgnitionContracts\BaseSolution;
8
use Facade\IgnitionContracts\HasSolutionsForThrowable;
9
10
class RedisClientNotInstalledSolutionProvider implements HasSolutionsForThrowable
11
{
12
    public function canSolve(Throwable $throwable): bool
13
    {
14
        if (! $throwable instanceof LogicException) {
15
            return false;
16
        }
17
18
        return true;
19
    }
20
21
    public function getSolutions(Throwable $throwable): array
22
    {
23
        $client = config('database.redis.client');
24
        [$message, $description] = $this->getSolutionMessage($client);
0 ignored issues
show
Bug introduced by
The variable $message does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $description does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
25
26
        return [
27
            BaseSolution::create($message)
28
                ->setSolutionDescription($description),
29
        ];
30
    }
31
32
    protected function getSolutionMessage(string $client): array
33
    {
34
        $predis = file_exists(base_path('vendor/predis/predis'));
35
        $phpredis = file_exists(base_path('vendor/phpredis/phpredis'));
36
37
        if ($client === 'predis') {
38
            if ($predis === false && $phpredis === true) {
39
                return [
40
                    'predis is set as client, but it wasn\'t installed.',
41
                    'either run `composer require predis/predis` or default to phpredis which is installed',
42
                ];
43
            }
44
        }
45
46
        if ($predis === true && $phpredis === false) {
47
            return [
48
                'phpredis is set as client, but it wasn\'t installed.',
49
                'either run `composer require phpredis/phpredis` or set the `REDIS_CLIENT` to predis in your `.env`.',
50
            ];
51
        }
52
53
        return [
54
            'there was no client installed.',
55
            'run `composer require phpredis/phpredis`',
56
        ];
57
    }
58
}
59