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.

Mailer::__invoke()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 1
1
<?php
2
namespace RbComment\Mvc\Controller\Plugin;
3
4
use Zend\Mail\Message;
5
use Zend\Mime\Part as MimePart;
6
use Zend\Mime\Message as MimeMessage;
7
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
8
9
class Mailer extends AbstractPlugin
10
{
11
    private $serverUrlHelper;
12
    private $mailerService;
13
    private $configService;
14
15
    public function __construct(
16
        $serverUrlHelper,
17
        $mailerService,
18
        array $configService
19
    ) {
20
        $this->serverUrlHelper = $serverUrlHelper;
21
        $this->mailerService   = $mailerService;
22
        $this->configService   = $configService;
23
    }
24
25
    public function __invoke($comment)
26
    {
27
        $mailerConfig = $this->configService['rb_comment']['email'];
28
29
        $htmlContent = $comment->content;
30
        $htmlContent .= '<br><br>';
31
        $htmlContent .=
32
            '<a href="' . $this->serverUrlHelper->__invoke() . $comment->uri . '#rbcomment-' . $comment->id . '">' .
33
                $mailerConfig['context_link_text'] .
34
            '</a>';
35
36
        $html = new MimePart($htmlContent);
37
        $html->type = "text/html";
38
39
        $body = new MimeMessage();
40
        $body->setParts([$html]);
41
42
        $message = new Message();
43
        $message->addFrom($mailerConfig['from'])
44
                ->setSubject($mailerConfig['subject'])
45
                ->setBody($body);
46
47
        foreach ($mailerConfig['to'] as $mConfig) {
48
            $message->addTo($mConfig);
49
        }
50
51
        $this->mailerService->send($message);
52
    }
53
}
54