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

ParserUUEncodedPartFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 43
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A newInstance() 0 16 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\PartBuilder;
11
use ZBateson\MailMimeParser\Parser\Part\ParserPartStreamContainerFactory;
12
use ZBateson\MailMimeParser\Stream\StreamFactory;
13
14
/**
15
 * Responsible for creating proxied IUUEncodedPart instances.
16
 *
17
 * @author Zaahid Bateson
18
 */
19
class ParserUUEncodedPartFactory
20
{
21
    /**
22
     * @var StreamFactory the StreamFactory instance
23
     */
24
    protected $streamFactory;
25
26
    /**
27
     * @var ParserPartStreamContainerFactory
28
     */
29
    protected $parserPartStreamContainerFactory;
30
31
    public function __construct(
32
        StreamFactory $sdf,
33
        ParserPartStreamContainerFactory $parserPartStreamContainerFactory
34
    ) {
35
        $this->streamFactory = $sdf;
36
        $this->parserPartStreamContainerFactory = $parserPartStreamContainerFactory;
37
    }
38
39
    /**
40
     * Constructs a new IUUEncodedPart object attached to a parser proxy, and
41
     * returns it
42
     * 
43
     * @param PartBuilder $partBuilder
44
     * @return ParserPartProxy
45
     */
46
    public function newInstance(PartBuilder $partBuilder, $mode, $filename, ParserMimePartProxy $parent)
47
    {
48
        $parserProxy = new ParserPartProxy($partBuilder, null, $parent);
49
        $streamContainer = $this->parserPartStreamContainerFactory->newInstance($parserProxy);
50
51
        $part = new UUEncodedPart(
52
            $mode,
53
            $filename,
54
            $parent->getPart(),
55
            $streamContainer
56
        );
57
        $parserProxy->setPart($part);
58
59
        $streamContainer->setStream($this->streamFactory->newMessagePartStream($part));
60
        $part->attach($streamContainer);
61
        return $parserProxy;
62
    }
63
}
64