Test Failed
Push — master ( 159af9...b2d1de )
by Banciu N. Cristian Mihai
03:26
created

CarrotMQServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 26
c 1
b 0
f 0
dl 0
loc 85
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A publishConfig() 0 6 1
A prepareApp() 0 19 2
A getConfigFile() 0 3 1
A register() 0 3 1
A boot() 0 4 1
A prepareCommands() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ\Support\Laravel;
6
7
use Psr\Log\LoggerInterface;
8
use BinaryCube\CarrotMQ\CarrotMQ;
9
use Illuminate\Foundation\Application;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use BinaryCube\CarrotMQ\Support\Laravel\Console\Commands as Commands;
11
12
use function is_array;
13
14
/**
15
 * Class CarrotMQServiceProvider
16
 */
17
class CarrotMQServiceProvider extends \Illuminate\Support\ServiceProvider
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\ServiceProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
{
19
20
    /**
21
     * @return void
22
     */
23
    public function register()
24
    {
25
        $this->publishConfig();
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function boot()
32
    {
33
        $this->prepareApp();
34
        $this->prepareCommands();
35
    }
36
37
    /**
38
     * @return void
39
     */
40
    protected function publishConfig()
41
    {
42
        $this
43
            ->publishes(
44
                [
45
                    $this->getConfigFile() => config_path('carrot_mq.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
                    $this->getConfigFile() => /** @scrutinizer ignore-call */ config_path('carrot_mq.php'),
Loading history...
46
                ]
47
            );
48
    }
49
50
    /**
51
     * @return void
52
     */
53
    protected function prepareApp()
54
    {
55
        $config = config('carrot_mq', []);
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $config = /** @scrutinizer ignore-call */ config('carrot_mq', []);
Loading history...
56
57
        if (! is_array($config)) {
58
            throw new \RuntimeException(
59
                'Invalid configuration provided for CarrotMQ-Laravel!'
60
            );
61
        }
62
63
        $this->app->bind('carrot.mq', function (Application $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
        $this->app->bind('carrot.mq', function (/** @scrutinizer ignore-unused */ Application $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
            return app(CarrotMQ::class);
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            return /** @scrutinizer ignore-call */ app(CarrotMQ::class);
Loading history...
65
        });
66
67
        $this->app->singleton(CarrotMQ::class, function (Application $app, $arguments) use ($config) {
0 ignored issues
show
Unused Code introduced by
The parameter $arguments is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

67
        $this->app->singleton(CarrotMQ::class, function (Application $app, /** @scrutinizer ignore-unused */ $arguments) use ($config) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
            $logger = $app->make(LoggerInterface::class);
69
            $carrot = new CarrotMQ($config, $logger);
70
71
            return $carrot;
72
        });
73
    }
74
75
    /**
76
     * @return void
77
     */
78
    protected function prepareCommands()
79
    {
80
        if (! $this->app->runningInConsole()) {
81
            return;
82
        }
83
84
        $this->commands(
85
            [
86
                Commands\ListCommand::class,
87
                Commands\SetupCommand::class,
88
                Commands\ConsumerCommand::class,
89
                Commands\DeleteAllCommand::class,
90
                Commands\PurgeCommand::class,
91
                Commands\PublisherCommand::class,
92
            ]
93
        );
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    protected function getConfigFile()
100
    {
101
        return (__DIR__ . '/config/carrot_mq.php');
102
    }
103
104
}
105