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

canSolve()   A

Complexity

Conditions 3
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 3
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 && ! $throwable instanceof ViewException) {
0 ignored issues
show
Bug introduced by
The class Facade\Ignition\SolutionProviders\ViewException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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