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

getSolutionMessage()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 26

Duplication

Lines 14
Ratio 53.85 %

Importance

Changes 0
Metric Value
dl 14
loc 26
rs 8.8817
c 0
b 0
f 0
cc 6
nc 5
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
22
    public function getSolutions(Throwable $throwable): array
23
    {
24
        $client = config('database.redis.client');
25
        list($message, $description) = $this->getSolutionMessage($client);
26
27
        return [
28
            BaseSolution::create($message)
29
                ->setSolutionDescription($description),
30
        ];
31
    }
32
33
    protected function getSolutionMessage(string $client): array
34
    {
35
        $predis = file_exists(base_path('vendor/predis/predis'));
36
        $phpredis = file_exists(base_path('vendor/phpredis/phpredis'));
37
38 View Code Duplication
        if ($client === 'predis') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
            if ($predis === false && $phpredis === true) {
40
                return [
41
                    'predis is set as client, but it wasn\'t installed.',
42
                    'either run `composer require predis/predis` or default to phpredis which is installed',
43
                ];
44
            }
45
        }
46
47 View Code Duplication
        if ($predis === true && $phpredis === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
            return [
49
                'phpredis is set as client, but it wasn\'t installed.',
50
                'either run `composer require phpredis/phpredis` or set the `REDIS_CLIENT` to predis in your `.env`.',
51
            ];
52
        }
53
54
        return [
55
            'there was no client installed.',
56
            'run `composer require phpredis/phpredis`',
57
        ];
58
    }
59
}
60