MessageEncoding   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 4
dl 0
loc 52
ccs 8
cts 11
cp 0.7272
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setMessageEncoding() 0 4 1
A attach() 0 4 1
A setEncoding() 0 6 1
A getEncoding() 0 4 1
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