Completed
Pull Request — master (#10)
by Dejan
03:34
created

ImpersonatePlugin::beforeSendPerformed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the pixelart Swiftmailer manipulator bundle.
5
 *
6
 * (c) pixelart GmbH
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pixelart\Bundle\SwiftmailerManipulatorBundle\Swift\Plugins;
13
14
use Swift_Events_SendEvent;
15
16
/**
17
 * Allows changing sender's address before sending the message.
18
 *
19
 * @author Dejan Angelov <[email protected]>
20
 */
21
class ImpersonatePlugin implements \Swift_Events_SendListener
22
{
23
    /**
24
     * @var string
25
     */
26
    private $fromAddress;
27
28
    /**
29
     * @var string[]
30
     */
31
    private $originalAddresses = [];
32
33
    /**
34
     * @param string $address Address the message should be sent from
0 ignored issues
show
Documentation introduced by
There is no parameter named $address. Did you maybe mean $fromAddress?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
35
     */
36
    public function __construct($fromAddress)
37
    {
38
        $this->fromAddress = $fromAddress;
39
    }
40
41
    /**
42
     * @param Swift_Events_SendEvent $event
43
     */
44
    public function beforeSendPerformed(Swift_Events_SendEvent $event)
45
    {
46
        $message = $event->getMessage();
47
48
        $this->originalAddresses = $message->getFrom();
49
50
        $message->setFrom($this->fromAddress);
51
    }
52
53
    /**
54
     * @param Swift_Events_SendEvent $event
55
     */
56
    public function sendPerformed(Swift_Events_SendEvent $event)
57
    {
58
        $message = $event->getMessage();
59
        $message->setFrom($this->originalAddresses);
60
    }
61
}
62