Passed
Pull Request — master (#171)
by Zaahid
03:23
created

ParserPartChildrenContainer::offsetExists()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.9666
cc 4
nc 3
nop 1
crap 4
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\Part;
8
9
use ZBateson\MailMimeParser\Message\PartChildrenContainer;
10
use ZBateson\MailMimeParser\Parser\Proxy\ParserMimePartProxy;
11
12
/**
13
 * A child container that proxies calls to a parser when attempting to access
14
 * child parts.
15
 *
16
 * @author Zaahid Bateson
17
 */
18
class ParserPartChildrenContainer extends PartChildrenContainer
19
{
20
    /**
21
     * @var ParserMimePartProxy The parser to proxy requests to when trying to
22
     *      get child parts.
23
     */
24
    protected $parserProxy;
25
26
    /**
27
     * @var bool Set to true once all parts have been parsed, and requests to
28
     *      the proxy won't result in any more child parts.
29
     */
30
    private $allParsed = false;
31
32 106
    public function __construct(ParserMimePartProxy $parserProxy)
33
    {
34 106
        parent::__construct([]);
35 106
        $this->parserProxy = $parserProxy;
36 106
    }
37
38 103
    public function offsetExists($offset)
39
    {
40 103
        $exists = parent::offsetExists($offset);
41 103
        while (!$exists && !$this->allParsed) {
42 103
            $child = $this->parserProxy->popNextChild();
43 103
            if ($child === null) {
44 98
                $this->allParsed = true;
45
            } else {
46 74
                $this->add($child);
47
            }
48 103
            $exists = parent::offsetExists($offset);
49
        }
50 103
        return $exists;
51
    }
52
}
53