Completed
Push — 5.x ( 831ff0...27843f )
by Lars
15:22 queued 08:41
created

charsetChanged()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2004-2009 Chris Corbyn
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * Proxy for quoted-printable content encoders.
13
 *
14
 * Switches on the best QP encoder implementation for current charset.
15
 *
16
 * @author Jean-François Simon <[email protected]>
17
 */
18
class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_ContentEncoder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
19
{
20
    /**
21
     * @var Swift_Mime_ContentEncoder_QpContentEncoder
22
     */
23
    private $safeEncoder;
24
25
    /**
26
     * @var Swift_Mime_ContentEncoder_NativeQpContentEncoder
27
     */
28
    private $nativeEncoder;
29
30
    /**
31
     * @var null|string
32
     */
33
    private $charset;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param Swift_Mime_ContentEncoder_QpContentEncoder       $safeEncoder
39
     * @param Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder
40
     * @param string|null                                      $charset
41
     */
42 1
    public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset)
43
    {
44 1
        $this->safeEncoder = $safeEncoder;
45 1
        $this->nativeEncoder = $nativeEncoder;
46 1
        $this->charset = $charset;
47 1
    }
48
49
    /**
50
     * Make a deep copy of object.
51
     */
52
    public function __clone()
53
    {
54
        if (true === Swift::$useMemorySpool) {
55
            $this->safeEncoder = clone $this->safeEncoder;
56
            $this->nativeEncoder = clone $this->nativeEncoder;
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function charsetChanged($charset)
64
    {
65
        $this->charset = $charset;
66
        $this->safeEncoder->charsetChanged($charset);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
73
    {
74
        $this->getEncoder()->encodeByteStream($os, $is, $firstLineOffset, $maxLineLength);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getName()
81
    {
82
        return 'quoted-printable';
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
89
    {
90
        return $this->getEncoder()->encodeString($string, $firstLineOffset, $maxLineLength);
91
    }
92
93
    /**
94
     * @return Swift_Mime_ContentEncoder
95
     */
96
    private function getEncoder()
97
    {
98
        return 'utf-8' === $this->charset ? $this->nativeEncoder : $this->safeEncoder;
99
    }
100
}
101