Test Failed
Push — 2.0 ( 9e8731...0b4092 )
by Zaahid
03:06
created

ParserPartProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
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
namespace ZBateson\MailMimeParser\Parser\Proxy;
8
9
use ZBateson\MailMimeParser\Message\IMessagePart;
10
use ZBateson\MailMimeParser\Parser\IParser;
11
use ZBateson\MailMimeParser\Parser\PartBuilder;
12
use ZBateson\MailMimeParser\Parser\Part\ParserPartStreamContainer;
13
14
/**
15
 * Base bi-directional proxy between a parser and a MessagePart.
16
 *
17
 * @author Zaahid Bateson
18
 */
19
class ParserPartProxy
20
{
21
    /**
22
     * @var IMessagePart The part.
23
     */
24
    protected $part;
25
    
26
    /**
27
     * @var IParser|null The parser.
28
     */
29
    protected $childParser;
30
31
    /**
32
     * @var PartBuilder The part's PartBuilder.
33
     */
34
    protected $partBuilder;
35
36
    /**
37
     * @var ParserPartProxy The parent parser proxy for this part.
38
     */
39
    protected $parent;
40
41
    public function __construct(
42
        PartBuilder $partBuilder,
43
        IParser $childParser = null,
44
        ParserMimePartProxy $parent = null
45
    ) {
46
        $this->partBuilder = $partBuilder;
47
        $this->childParser = $childParser;
48
        $this->parent = $parent;
49
    }
50
51
    /**
52
     * Sets the associated part.
53
     *
54
     * @param IMessagePart $part The part
55
     */
56
    public function setPart(IMessagePart $part)
57
    {
58
        $this->part = $part;
59
    }
60
61
    /**
62
     * Returns the IMessagePart associated with this proxy.
63
     *
64
     * @return IMessagePart the part.
65
     */
66
    public function getPart()
67
    {
68
        return $this->part;
69
    }
70
71
    /**
72
     * Parses this part's content (if not already parsed).
73
     *
74
     * If the part has a parent, parseContent() will use
75
     * $this->parent->childParser, which is the matching type of parser for the
76
     * given part.  Otherwise, if it's the top-level part (Message), then
77
     * $this->childParser is used.
78
     */
79
    public function parseContent()
80
    {
81
        if (!$this->partBuilder->isContentParsed()) {
82
            $parser = ($this->parent === null) ? $this->childParser : $this->parent->childParser;
83
            $parser->parseContent($this);
0 ignored issues
show
Bug introduced by
The method parseContent() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
            $parser->/** @scrutinizer ignore-call */ 
84
                     parseContent($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
        }
85
    }
86
87
    /**
88
     * Parses the associated part's content and children.
89
     */
90
    public function parseAll()
91
    {
92
        $this->parseContent();
93
    }
94
95
    /**
96
     * Returns the PartBuilder for this part.
97
     *
98
     * @return PartBuilder the associated PartBuilder.
99
     */
100
    public function getPartBuilder()
101
    {
102
        return $this->partBuilder;
103
    }
104
}
105