Completed
Pull Request — develop (#79)
by
unknown
02:13
created

InformationRequestMailService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 70
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A sendInformationRequestMail() 0 21 1
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\Service;
20
21
use OpenConext\Profile\Value\EmailAddress;
22
use OpenConext\ProfileBundle\Attribute\AttributeFilter;
23
use Swift_Mailer as Mailer;
24
use Swift_Message as Message;
25
use Symfony\Component\Templating\EngineInterface;
26
27
final class InformationRequestMailService
28
{
29
    /**
30
     * @var EmailAddress
31
     */
32
    private $mailFrom;
33
34
    /**
35
     * @var EmailAddress
36
     */
37
    private $mailTo;
38
39
    /**
40
     * @var Mailer
41
     */
42
    private $mailer;
43
44
    /**
45
     * @var EngineInterface
46
     */
47
    private $templateEngine;
48
49
    /**
50
     * @var UserService
51
     */
52
    private $userService;
53
54
    /**
55
     * @var AttributeFilter
56
     */
57
    private $attributeFilter;
58
59
    public function __construct(
60
        EmailAddress $mailFrom,
61
        EmailAddress $mailTo,
62
        Mailer $mailer,
63
        EngineInterface $templateEngine,
64
        UserService $userService,
65
        AttributeFilter $attributeFilter
66
    ) {
67
        $this->mailFrom = $mailFrom;
68
        $this->mailTo = $mailTo;
69
        $this->mailer = $mailer;
70
        $this->templateEngine = $templateEngine;
71
        $this->userService = $userService;
72
        $this->attributeFilter = $attributeFilter;
73
    }
74
75
    public function sendInformationRequestMail()
76
    {
77
        $user = $this->userService->getUser();
78
79
        $attributes = $this->attributeFilter->filter($user->getAttributes());
80
81
        $body = $this->templateEngine->render(
82
            'OpenConextProfileBundle:InformationRequest:email.html.twig',
83
            ['attributes' => $attributes]
84
        );
85
86
        /** @var Message $message */
87
        $message = $this->mailer->createMessage();
88
        $message
89
            ->setFrom($this->mailFrom->getEmailAddress())
90
            ->setTo($this->mailTo->getEmailAddress())
91
            ->setSubject(sprintf('Information request for user: %s', $user->getId()))
92
            ->setBody($body, 'text/html', 'utf-8');
93
94
        $this->mailer->send($message);
95
    }
96
}
97