CssInlinerPlugin   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A beforeSendPerformed() 0 14 4
A sendPerformed() 0 4 1
1
<?php
2
3
namespace Openbuildings\Swiftmailer;
4
5
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
6
use Swift_Events_SendListener;
7
use Swift_Events_SendEvent;
8
9
class CssInlinerPlugin implements Swift_Events_SendListener
10
{
11
    /**
12
     * @var CssToInlineStyles
13
     */
14
    private $converter;
15
16
    /**
17
     * @param CssToInlineStyles $converter
18
     */
19 1
    public function __construct(CssToInlineStyles $converter = null)
20
    {
21 1
        if ($converter) {
22 1
            $this->converter = $converter;
23
        } else {
24 1
            $this->converter = new CssToInlineStyles();
25
        }
26 1
    }
27
28
    /**
29
     * @param Swift_Events_SendEvent $event
30
     */
31 3
    public function beforeSendPerformed(Swift_Events_SendEvent $event)
32
    {
33 3
        $message = $event->getMessage();
34
35 3
        if ($message->getContentType() === 'text/html') {
36 2
            $message->setBody($this->converter->convert($message->getBody()));
37
        }
38
39 3
        foreach ($message->getChildren() as $part) {
40 1
            if (strpos($part->getContentType(), 'text/html') === 0) {
41 1
                $part->setBody($this->converter->convert($part->getBody()));
42
            }
43
        }
44 3
    }
45
46
    /**
47
     * @param Swift_Events_SendEvent $event
48
     */
49 1
    public function sendPerformed(Swift_Events_SendEvent $event)
50
    {
51
        // Do nothing after sending the message
52 1
    }
53
}
54