Completed
Push — develop ( 35ebd6...f6916d )
by Mohamed
13:11 queued 06:49
created

BusServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 42
ccs 17
cts 20
cp 0.85
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A register() 0 22 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Providers;
13
14
use Illuminate\Bus\Dispatcher;
15
use Illuminate\Support\ServiceProvider;
16
use Tinyissue\Form\FormInterface;
17
use Tinyissue\Http\Requests\Request as FormRequest;
18
use Illuminate\Foundation\Application;
19
20
/**
21
 * BusServiceProvider is the request service provider for bootstrapping and registering services in current request.
22
 *
23
 * @author Mohamed Alsharaf <[email protected]>
24
 */
25
class BusServiceProvider extends ServiceProvider
26
{
27
    /**
28
     * Bootstrap any application services.
29
     *
30
     * @param \Illuminate\Bus\Dispatcher $dispatcher
31
     */
32 59
    public function boot(Dispatcher $dispatcher)
33
    {
34
        $dispatcher->mapUsing(function ($command) {
35
            return Dispatcher::simpleMapping(
36
                            $command, 'Tinyissue\Commands', 'Tinyissue\Handlers\Commands'
37
            );
38 59
        });
39 59
    }
40
41
    /**
42
     * Register any application services.
43
     */
44 59
    public function register()
45
    {
46
        // Resolve form object by injecting the current model being edited
47
        $this->app->resolving(function (FormInterface $form, Application $app) {
0 ignored issues
show
Documentation introduced by
function (\Tinyissue\For...ute()->parameters()); } is of type object<Closure>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48 47
            $form->setup($app->router->getCurrentRoute()->parameters());
49 59
        });
50
51
        // Resolve form request by injecting the current model being edited
52
        $this->app->resolving(function (FormRequest $request, Application $app) {
0 ignored issues
show
Documentation introduced by
function (\Tinyissue\Htt... return $request; } is of type object<Closure>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
            $form = array_first($app->router->getCurrentRoute()->parameters(), function ($key, $value) {
54 13
                return $value instanceof FormInterface;
55 25
            }, function () use ($request, $app) {
56 25
                return $app->make($request->getFormClassName());
57 25
            });
58 25
            if ($form) {
59 25
                $form->setup($app->router->getCurrentRoute()->parameters());
60 25
                $request->setForm($form);
61 25
            }
62
63 25
            return $request;
64 59
        });
65 59
    }
66
}
67