MessageEncoding::attach()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * MtMail - e-mail module for Zend Framework
4
 *
5
 * @link      http://github.com/mtymek/MtMail
6
 * @copyright Copyright (c) 2013-2017 Mateusz Tymek
7
 * @license   BSD 2-Clause
8
 */
9
10
namespace MtMail\ComposerPlugin;
11
12
use MtMail\Event\ComposerEvent;
13
use Zend\EventManager\EventManagerInterface;
14
use Zend\EventManager\AbstractListenerAggregate;
15
16
class MessageEncoding extends AbstractListenerAggregate implements PluginInterface
17
{
18
19
    /**
20
     * @var string
21
     */
22
    protected $encoding;
23
24
    /**
25
     * Set encoding of message inside event
26
     *
27
     * @param ComposerEvent $event
28
     */
29 1
    public function setMessageEncoding(ComposerEvent $event)
30
    {
31 1
        $event->getMessage()->setEncoding($this->encoding);
32 1
    }
33
34
    /**
35
     * Attach one or more listeners
36
     *
37
     * Implementors may add an optional $priority argument; the EventManager
38
     * implementation will pass this to the aggregate.
39
     *
40
     * @param EventManagerInterface $events
41
     *
42
     * @return void
43
     */
44
    public function attach(EventManagerInterface $events, $priority = 1)
45
    {
46
        $this->listeners[] = $events->attach(ComposerEvent::EVENT_COMPOSE_PRE, [$this, 'setMessageEncoding']);
47
    }
48
49
    /**
50
     * @param  string $encoding
51
     * @return self
52
     */
53 2
    public function setEncoding($encoding)
54
    {
55 2
        $this->encoding = $encoding;
56
57 2
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 2
    public function getEncoding()
64
    {
65 2
        return $this->encoding;
66
    }
67
}
68