Completed
Push — master ( 2caffe...d6bf0c )
by Ryan
06:45
created

StreamsMailProvider::register()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 54
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 54
rs 7.8331
cc 7
eloc 28
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Anomaly\Streams\Platform;
2
3
use Anomaly\Streams\Platform\Mail\Mailer;
4
use Illuminate\Support\ServiceProvider;
5
6
/**
7
 * Class StreamsMailProvider
8
 *
9
 * @link          http://pyrocms.com/
10
 * @author        PyroCMS, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\Streams\Platform
13
 */
14
class StreamsMailProvider extends ServiceProvider
15
{
16
17
    /**
18
     * Register the service provider.
19
     *
20
     * @return void
21
     */
22
    public function register()
23
    {
24
        $this->app->singleton(
25
            'mailer',
26
            function () {
27
28
                $mailer = new Mailer(
29
                    $this->app['view'], $this->app['swift.mailer'], $this->app['events']
30
                );
31
32
                $mailer->setContainer($this->app);
33
34
                if ($this->app->bound('Psr\Log\LoggerInterface')) {
35
                    $mailer->setLogger($this->app->make('Psr\Log\LoggerInterface'));
36
                }
37
38
                if ($this->app->bound('queue')) {
39
                    $mailer->setQueue($this->app['queue.connection']);
40
                }
41
42
                $from = $this->app['config']['mail.from'];
43
44
                if (is_array($from) && isset($from['address'])) {
45
                    $mailer->alwaysFrom($from['address'], $from['name']);
46
                }
47
48
                $to = $this->app['config']['mail.to'];
49
50
                if (is_array($to) && isset($to['address'])) {
51
                    $mailer->alwaysTo($to['address'], $to['name']);
52
                }
53
54
                $pretend = $this->app['config']->get('mail.pretend', false);
55
56
                $mailer->pretend($pretend);
57
58
                return $mailer;
59
            }
60
        );
61
62
        $this->app->singleton(
63
            'Illuminate\Mail\Mailer',
64
            function () {
65
                return $this->app->make('mailer');
66
            }
67
        );
68
69
        $this->app->singleton(
70
            'Illuminate\Contracts\Mail\Mailer',
71
            function () {
72
                return $this->app->make('mailer');
73
            }
74
        );
75
    }
76
}
77