Completed
Pull Request — develop (#43)
by A.
09:18
created

AttributeSupportMailService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4286
cc 1
eloc 11
nc 1
nop 5
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 Swift_Mailer as Mailer;
23
use Swift_Message as Message;
24
use Symfony\Component\Templating\EngineInterface;
25
26
final class AttributeSupportMailService
27
{
28
    /**
29
     * @var string
30
     */
31
    private $mailFrom;
32
33
    /**
34
     * @var string
35
     */
36
    private $mailTo;
37
38
    /**
39
     * @var Mailer
40
     */
41
    private $mailer;
42
43
    /**
44
     * @var EngineInterface
45
     */
46
    private $templateEngine;
47
48
    /**
49
     * @var UserService
50
     */
51
    private $userService;
52
53
    public function __construct(
54
        EmailAddress $mailFrom,
55
        EmailAddress $mailTo,
56
        Mailer $mailer,
57
        EngineInterface $templateEngine,
58
        UserService $userService
59
    ) {
60
        $this->mailFrom       = $mailFrom;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mailFrom of type object<OpenConext\Profile\Value\EmailAddress> is incompatible with the declared type string of property $mailFrom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
        $this->mailTo         = $mailTo;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mailTo of type object<OpenConext\Profile\Value\EmailAddress> is incompatible with the declared type string of property $mailTo.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
        $this->mailer         = $mailer;
63
        $this->templateEngine = $templateEngine;
64
        $this->userService    = $userService;
65
    }
66
67
    public function sendAttributeSupportMail()
68
    {
69
        $user = $this->userService->getUser();
70
71
        $body = $this->templateEngine->render(
72
            'OpenConextProfileBundle:AttributeSupport:email.html.twig',
73
            ['attributes' => $user->getAttributes()]
74
        );
75
76
        /** @var Message $message */
77
        $message = $this->mailer->createMessage();
78
        $message
79
            ->setFrom($this->mailFrom->getEmailAddress())
0 ignored issues
show
Bug introduced by
The method getEmailAddress cannot be called on $this->mailFrom (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
80
            ->setTo($this->mailTo->getEmailAddress())
0 ignored issues
show
Bug introduced by
The method getEmailAddress cannot be called on $this->mailTo (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
81
            ->setSubject(sprintf('Personal debug info of %s', $user->getId()))
82
            ->setBody($body, 'text/html', 'utf-8');
83
84
        $this->mailer->send($message);
85
    }
86
}
87