Passed
Push — master ( 181d77...7fe46a )
by Zaahid
06:13 queued 12s
created

ParserPartProxy   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Test Coverage

Coverage 93.88%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 21
eloc 33
c 2
b 0
f 0
dl 0
loc 165
ccs 46
cts 49
cp 0.9388
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
A getPart() 0 3 1
A __construct() 0 4 1
A setStreamContentStartPos() 0 4 1
A parseContent() 0 6 2
A isMime() 0 3 1
A setPart() 0 4 1
A getStreamPartStartPos() 0 3 1
A setStreamPartStartPos() 0 4 1
A getStreamPartLength() 0 3 1
A setStreamPartAndContentEndPos() 0 4 1
A getMessageResourceHandlePos() 0 3 1
A getParent() 0 3 1
A getStreamContentLength() 0 3 1
A setStreamPartEndPos() 0 4 1
A getMessageResourceHandle() 0 3 1
A getHeaderContainer() 0 3 1
A getStream() 0 3 1
A parseAll() 0 4 1
A isContentParsed() 0 3 1
A getStreamContentStartPos() 0 3 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
8
namespace ZBateson\MailMimeParser\Parser\Proxy;
9
10
use ZBateson\MailMimeParser\Message\IMessagePart;
11
use ZBateson\MailMimeParser\Parser\IParser;
12
use ZBateson\MailMimeParser\Parser\PartBuilder;
13
14
/**
15
 * Proxy between a MessagePart and a Parser.
16
 *
17
 * ParserPartProxy objects are responsible for ferrying requests from message
18
 * parts to a proxy as they're requested, and for maintaining state information
19
 * for a parser as necessary.
20
 *
21
 * @author Zaahid Bateson
22
 */
23
abstract class ParserPartProxy extends PartBuilder
24
{
25
    /**
26
     * @var IParser The parser.
27
     */
28
    protected $parser;
29
30
    /**
31
     * @var PartBuilder The part's PartBuilder.
32
     */
33
    protected $partBuilder;
34
35
    /**
36
     * @var IMessagePart The part.
37
     */
38
    private $part;
39
40 132
    public function __construct(PartBuilder $partBuilder, IParser $parser)
41
    {
42 132
        $this->partBuilder = $partBuilder;
43 132
        $this->parser = $parser;
44
    }
45
46
    /**
47
     * Sets the associated part.
48
     *
49
     * @param IMessagePart $part The part
50
     */
51 105
    public function setPart(IMessagePart $part) : self
52
    {
53 105
        $this->part = $part;
54 105
        return $this;
55
    }
56
57
    /**
58
     * Returns the IMessagePart associated with this proxy.
59
     *
60
     * @return IMessagePart the part.
61
     */
62 105
    public function getPart()
63
    {
64 105
        return $this->part;
65
    }
66
67
    /**
68
     * Requests the parser to parse this part's content, and call
69
     * setStreamContentStartPos/EndPos to setup this part's boundaries within
70
     * the main message's raw stream.
71
     *
72
     * The method first checks to see if the content has already been parsed,
73
     * and is safe to call multiple times.
74
     *
75
     * @return static
76
     */
77 109
    public function parseContent()
78
    {
79 109
        if (!$this->isContentParsed()) {
80 109
            $this->parser->parseContent($this);
81
        }
82 109
        return $this;
83
    }
84
85
    /**
86
     * Parses everything under this part.
87
     *
88
     * For ParserPartProxy, this is just content, but sub-classes may override
89
     * this to parse all children as well for example.
90
     *
91
     * @return static
92
     */
93 3
    public function parseAll()
94
    {
95 3
        $this->parseContent();
96 3
        return $this;
97
    }
98
99 112
    public function getParent()
100
    {
101 112
        return $this->partBuilder->getParent();
102
    }
103
104 112
    public function getHeaderContainer()
105
    {
106 112
        return $this->partBuilder->getHeaderContainer();
107
    }
108
109 102
    public function getStream()
110
    {
111 102
        return $this->partBuilder->getStream();
112
    }
113
114 103
    public function getMessageResourceHandle()
115
    {
116 103
        return $this->partBuilder->getMessageResourceHandle();
117
    }
118
119 101
    public function getMessageResourceHandlePos() : int
120
    {
121 101
        return $this->partBuilder->getMessageResourceHandlePos();
122
    }
123
124 98
    public function getStreamPartStartPos() : int
125
    {
126 98
        return $this->partBuilder->getStreamPartStartPos();
127
    }
128
129 98
    public function getStreamPartLength() : int
130
    {
131 98
        return $this->partBuilder->getStreamPartLength();
132
    }
133
134 102
    public function getStreamContentStartPos() : ?int
135
    {
136 102
        return $this->partBuilder->getStreamContentStartPos();
137
    }
138
139 102
    public function getStreamContentLength() : int
140
    {
141 102
        return $this->partBuilder->getStreamContentLength();
142
    }
143
144
    /**
145
     * @return static
146
     */
147
    public function setStreamPartStartPos(int $streamPartStartPos)
148
    {
149
        $this->partBuilder->setStreamPartStartPos($streamPartStartPos);
150
        return $this;
151
    }
152
153
    /**
154
     * @return static
155
     */
156 73
    public function setStreamPartEndPos(int $streamPartEndPos)
157
    {
158 73
        $this->partBuilder->setStreamPartEndPos($streamPartEndPos);
159 73
        return $this;
160
    }
161
162
    /**
163
     * @return static
164
     */
165 103
    public function setStreamContentStartPos(int $streamContentStartPos)
166
    {
167 103
        $this->partBuilder->setStreamContentStartPos($streamContentStartPos);
168 103
        return $this;
169
    }
170
171
    /**
172
     * @return static
173
     */
174 103
    public function setStreamPartAndContentEndPos(int $streamContentEndPos)
175
    {
176 103
        $this->partBuilder->setStreamPartAndContentEndPos($streamContentEndPos);
177 103
        return $this;
178
    }
179
180 109
    public function isContentParsed() : ?bool
181
    {
182 109
        return $this->partBuilder->isContentParsed();
183
    }
184
185 73
    public function isMime() : bool
186
    {
187 73
        return $this->partBuilder->isMime();
188
    }
189
}
190