ParserMessageProxyFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 21
c 1
b 0
f 0
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A newInstance() 0 21 1
1
<?php
2
3
/**
4
 * This file is part of the ZBateson\MailMimeParser project.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 */
8
9
namespace ZBateson\MailMimeParser\Parser\Proxy;
10
11
use Psr\Log\LoggerInterface;
12
use ZBateson\MailMimeParser\Message;
13
use ZBateson\MailMimeParser\Message\Factory\PartHeaderContainerFactory;
14
use ZBateson\MailMimeParser\Message\Helper\MultipartHelper;
15
use ZBateson\MailMimeParser\Message\Helper\PrivacyHelper;
16
use ZBateson\MailMimeParser\Parser\IParserService;
17
use ZBateson\MailMimeParser\Parser\Part\ParserPartChildrenContainerFactory;
18
use ZBateson\MailMimeParser\Parser\Part\ParserPartStreamContainerFactory;
19
use ZBateson\MailMimeParser\Parser\PartBuilder;
20
use ZBateson\MailMimeParser\Stream\StreamFactory;
21
22
/**
23
 * Responsible for creating proxied IMessage instances wrapped in a
24
 * ParserMessageProxy.
25
 *
26
 * @author Zaahid Bateson
27
 */
28
class ParserMessageProxyFactory extends ParserMimePartProxyFactory
29
{
30
    protected MultipartHelper $multipartHelper;
31
32
    protected PrivacyHelper $privacyHelper;
33
34 3
    public function __construct(
35
        LoggerInterface $logger,
36
        StreamFactory $sdf,
37
        PartHeaderContainerFactory $phcf,
38
        ParserPartStreamContainerFactory $pscf,
39
        ParserPartChildrenContainerFactory $ppccf,
40
        MultipartHelper $multipartHelper,
41
        PrivacyHelper $privacyHelper
42
    ) {
43 3
        parent::__construct($logger, $sdf, $phcf, $pscf, $ppccf);
44 3
        $this->multipartHelper = $multipartHelper;
45 3
        $this->privacyHelper = $privacyHelper;
46
    }
47
48
    /**
49
     * Constructs a new ParserMessageProxy wrapping an IMessage object that will
50
     * dynamically parse a message's content and parts as they're requested.
51
     */
52 105
    public function newInstance(PartBuilder $partBuilder, IParserService $parser) : ParserMessageProxy
53
    {
54 105
        $parserProxy = new ParserMessageProxy($partBuilder, $parser);
55
56 105
        $streamContainer = $this->parserPartStreamContainerFactory->newInstance($parserProxy);
57 105
        $headerContainer = $this->partHeaderContainerFactory->newInstance($parserProxy->getHeaderContainer());
58 105
        $childrenContainer = $this->parserPartChildrenContainerFactory->newInstance($parserProxy);
59
60 105
        $message = new Message(
61 105
            $this->logger,
62 105
            $streamContainer,
63 105
            $headerContainer,
64 105
            $childrenContainer,
65 105
            $this->multipartHelper,
66 105
            $this->privacyHelper
67 105
        );
68 105
        $parserProxy->setPart($message);
69
70 105
        $streamContainer->setStream($this->streamFactory->newMessagePartStream($message));
71 105
        $message->attach($streamContainer);
72 105
        return $parserProxy;
73
    }
74
}
75