Completed
Push — master ( 03348d...edfc47 )
by Michał
08:06
created

Service   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 1
B registerMailer() 0 29 3
1
<?php namespace nyx\notify;
2
3
// External dependencies
4
use Illuminate\Contracts\Foundation\Application;
5
6
/**
7
 * Notify Service Provider
8
 *
9
 * @package     Nyx\Notify
10
 * @version     0.1.0
11
 * @author      Michal Chojnacki <[email protected]>
12
 * @copyright   2012-2017 Nyx Dev Team
13
 * @link        https://github.com/unyx/nyx
14
 * @todo        Make 'mailer' subservice registration optional? Drop the "mailer" name for the FQN of the interface?
15
 * @todo        Queue support for the Mailer?
16
 */
17
class Service extends \Illuminate\Support\ServiceProvider
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function register()
23
    {
24
        $this->app->singleton(TransportManager::class, function (Application $app) {
25
            return new TransportManager($app);
0 ignored issues
show
Documentation introduced by
$app is of type object<Illuminate\Contra...Foundation\Application>, but the function expects a object<Illuminate\Foundation\Application>.

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...
26
        });
27
28
        $this->app->alias(TransportManager::class, interfaces\Dispatcher::class);
29
30
        // Mailer (currently - see the to-do) gets made available as a standalone subservice. Subject to change.
31
        $this->registerMailer();
32
    }
33
34
    /**
35
     * Registers the Mail subcomponent as a standalone service for situations where Messages may need to get sent
36
     * bypassing the way Notifications are otherwise handled.
37
     */
38
    protected function registerMailer()
39
    {
40
        $this->app->singleton('mailer', function (Application $app) {
41
42
            $mailer = new transports\mail\Mailer($app->make('mailer.transport'), $app->make('view'));
43
44
            // Set the 'always from' and 'always to' options on the Mailer if they have been configured.
45
            $config = $app->make('config')->get('mail');
46
47
            if (isset($config['from'])) {
48
                $mailer->setAlwaysFrom($config['from']);
49
            }
50
51
            if (isset($config['to'])) {
52
                $mailer->setAlwaysTo($config['to']);
53
            }
54
55
            return $mailer;
56
        });
57
58
        // Make the humanized name an alias for the Mailer Interface's FQN so both can be used interchangeably.
59
        $this->app->alias('mailer', transports\mail\interfaces\Mailer::class);
60
61
        // We are going to need to instantiate the Mailer with a proper Driver.
62
        // @todo Drop the DriverManager in favour of handling the logic in this very Service Provider itself?
63
        $this->app->bind('mailer.transport', $this->app->share(function (Application $app) {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
            return (new transports\mail\DriverManager($app))->driver();
0 ignored issues
show
Documentation introduced by
$app is of type object<Illuminate\Contra...Foundation\Application>, but the function expects a object<Illuminate\Foundation\Application>.

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...
65
        }));
66
    }
67
}
68