GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MailerServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 97.78%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 111
ccs 44
cts 45
cp 0.9778
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 104 3
1
<?php
2
namespace Germania\Mailer;
3
4
use Pimple\Container;
5
use Pimple\ServiceProviderInterface;
6
7
use \Swift_SmtpTransport;
8
use \Swift_Mailer;
9
use \Swift_Message;
10
11
use Psr\Log\NullLogger;
12
13
use Germania\SwiftMailerCallable\SwiftMailerCallable;
14
15
class MailerServiceProvider implements ServiceProviderInterface
16
{
17
18
    /**
19
     * @implements ServiceProviderInterface
20
     */
21 20
    public function register(Container $dic)
22
    {
23
24
25
        /**
26
         * @return  StdClass
27
         */
28 4
        $dic['Mailer.Config'] = function( $dic ) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic is not used and could be removed.

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

Loading history...
29
            return [
30 20
                'smtp' => null,
31 4
                'port' => null,
32 4
                'ssl' => null,
33 4
                'user' => null,
34 4
                'pass' => null,
35 4
                'from_name' => null,
36 4
                'from_mail' => null,
37 4
                'to' => null,
38
                'subject' => null
39 4
            ];
40
        };
41
42
43
        /**
44
         * @return LoggerInterface|NullLogger
45
         */
46 2
        $dic['Mailer.Logger'] = function( $dic ) {
0 ignored issues
show
Unused Code introduced by
The parameter $dic is not used and could be removed.

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

Loading history...
47 10
            return new NullLogger;
48
        };
49
50
51
        /**
52
         * @return Swift_SmtpTransport
53
         */
54 2
        $dic['SwiftMailer.Transport'] = function( $dic ) {
55 10
            $mail_config = $dic['Mailer.Config'];
56
57 10
            $transport = new Swift_SmtpTransport( $mail_config['smtp'], $mail_config['port'], $mail_config['ssl'] ? 'ssl' : null);
58
59 10
            $transport->setUsername( $mail_config['user'] )
60 10
                      ->setPassword( $mail_config['pass'] );
61 10
            return $transport;
62
        };
63
64
65
66
        /**
67
         * @return Swift_Mailer
68
         */
69 2
        $dic['SwiftMailer'] = function( $dic ) {
70 10
            $transport = $dic['SwiftMailer.Transport'];
71 10
            return new Swift_Mailer( $transport );
72
        };
73
74
75
76
77
        /**
78
         * Factory method to create a new Swift_Message
79
         *
80
         * @return Swift_Message
81
         */
82 5
        $dic['SwiftMailer.Message'] = $dic->factory(function( $dic ) {
83 5
            $mail_config = $dic['Mailer.Config'];
84 5
            $message = new Swift_Message();
85
86 5
            $from = array( $mail_config['from_mail'] => $mail_config['from_name'] );
87
88 5
            $to = is_string($mail_config['to']) ? array( $mail_config['to'] ) : $mail_config['to'];
89
90 5
            $message->setFrom( $from )
91 5
                    ->setTo( $to )
92 5
                    ->setSubject( $mail_config['subject'] );
93 5
            return $message;
94 25
        });
95
96
97
98
        /**
99
         * @return Swift_Message
100
         */
101 5
        $dic['SwiftMailer.HtmlMessage'] = $dic->factory(function( $dic ) {
102 5
            return $dic['SwiftMailer.Message']->setContentType( 'text/html');
103 25
        });
104
105
106
107
        /**
108
         * @return Callable
109
         */
110 5
        $dic['Mailer.Callable'] = $dic->factory(function( $dic ) {
111 5
            $mailer        = $dic['SwiftMailer'];
112 5
            $mailer_logger = $dic['Mailer.Logger'];
113
114 2
            $mailer_callable = new SwiftMailerCallable($mailer, function() use ($dic) {
115
                return $dic['SwiftMailer.HtmlMessage'];
116 5
            });
117
118 5
            $mailer_callable->setLogger( $mailer_logger );
119
120 5
            return $mailer_callable;
121 25
        });
122
123
124 25
    }
125
}
126
127