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

ParserPartChildrenContainer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
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\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
    public function __construct(ParserMimePartProxy $parserProxy)
33
    {
34
        parent::__construct([]);
35
        $this->parserProxy = $parserProxy;
36
    }
37
38
    public function offsetExists($offset)
39
    {
40
        $exists = parent::offsetExists($offset);
41
        while (!$exists && !$this->allParsed) {
42
            $child = $this->parserProxy->popNextChild();
43
            if ($child === null) {
44
                $this->allParsed = true;
45
            } else {
46
                $this->add($child);
47
            }
48
            $exists = parent::offsetExists($offset);
49
        }
50
        return $exists;
51
    }
52
}
53