Passed
Push — 2.0 ( 00e111...1e45aa )
by Zaahid
03:30
created

ParserUUEncodedPartProxyFactory::newInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.9
cc 1
nc 1
nop 2
crap 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
namespace ZBateson\MailMimeParser\Parser\Proxy;
8
9
use ZBateson\MailMimeParser\Message\UUEncodedPart;
10
use ZBateson\MailMimeParser\Parser\IParser;
11
use ZBateson\MailMimeParser\Parser\PartBuilder;
12
use ZBateson\MailMimeParser\Parser\Part\ParserPartStreamContainerFactory;
13
use ZBateson\MailMimeParser\Stream\StreamFactory;
14
15
/**
16
 * Responsible for creating proxied IUUEncodedPart instances wrapped in a
17
 * ParserUUEncodedPartProxy and used by NonMimeParser.
18
 *
19
 * @author Zaahid Bateson
20
 */
21
class ParserUUEncodedPartProxyFactory extends ParserPartProxyFactory
22
{
23
    /**
24
     * @var StreamFactory the StreamFactory instance
25
     */
26
    protected $streamFactory;
27
28
    /**
29
     * @var ParserPartStreamContainerFactory
30
     */
31
    protected $parserPartStreamContainerFactory;
32
33 2
    public function __construct(
34
        StreamFactory $sdf,
35
        ParserPartStreamContainerFactory $parserPartStreamContainerFactory
36
    ) {
37 2
        $this->streamFactory = $sdf;
38 2
        $this->parserPartStreamContainerFactory = $parserPartStreamContainerFactory;
39 2
    }
40
41
    /**
42
     * Constructs a new ParserUUEncodedPartProxy wrapping an IUUEncoded object.
43
     * 
44
     * @param PartBuilder $partBuilder
45
     * @return ParserPartProxy
46
     */
47 4
    public function newInstance(PartBuilder $partBuilder, IParser $parser)
48
    {
49 4
        $parserProxy = new ParserUUEncodedPartProxy($partBuilder, $parser);
50 4
        $streamContainer = $this->parserPartStreamContainerFactory->newInstance($parserProxy);
51
52 4
        $part = new UUEncodedPart(
53 4
            $parserProxy->getUnixFileMode(),
54 4
            $parserProxy->getFileName(),
55 4
            $partBuilder->getParent()->getPart(),
56 4
            $streamContainer
57
        );
58 4
        $parserProxy->setPart($part);
59
60 4
        $streamContainer->setStream($this->streamFactory->newMessagePartStream($part));
61 4
        $part->attach($streamContainer);
62 4
        return $parserProxy;
63
    }
64
}
65