Completed
Push — 5.x ( 4bb56c...2a7c65 )
by Lars
06:29
created

__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 55
    public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset)
43
    {
44 55
        $this->safeEncoder = $safeEncoder;
45 55
        $this->nativeEncoder = $nativeEncoder;
46 55
        $this->charset = $charset;
47 55
    }
48
49
    /**
50
     * Make a deep copy of object.
51
     */
52 3
    public function __clone()
53
    {
54 3
        $this->safeEncoder = clone $this->safeEncoder;
55 3
        $this->nativeEncoder = clone $this->nativeEncoder;
56 3
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 27
    public function charsetChanged($charset)
62
    {
63 27
        $this->charset = $charset;
64 27
        $this->safeEncoder->charsetChanged($charset);
65 27
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
71
    {
72
        $this->getEncoder()->encodeByteStream($os, $is, $firstLineOffset, $maxLineLength);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 55
    public function getName()
79
    {
80 55
        return 'quoted-printable';
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 22
    public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
87
    {
88 22
        return $this->getEncoder()->encodeString($string, $firstLineOffset, $maxLineLength);
89
    }
90
91
    /**
92
     * @return Swift_Mime_ContentEncoder
93
     */
94 22
    private function getEncoder()
95
    {
96 22
        return 'utf-8' === $this->charset ? $this->nativeEncoder : $this->safeEncoder;
97
    }
98
}
99