Passed
Push — master ( 37aad3...325143 )
by Zaahid
03:26
created

MessageHelperService::getPrivacyHelper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 2
rs 10
c 0
b 0
f 0
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\Message\Helper;
8
9
use ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory;
10
use ZBateson\MailMimeParser\Message\Part\Factory\PartFactoryService;
11
12
/**
13
 * Responsible for creating helper singletons.
14
 *
15
 * @author Zaahid Bateson
16
 */
17
class MessageHelperService
18
{
19
    /**
20
     * @var PartBuilderFactory
21
     */
22
    private $partBuilderFactory;
23
24
    /**
25
     * @var GenericHelper the GenericHelper singleton
26
     */
27
    private $genericHelper;
28
29
    /**
30
     * @var MultipartHelper the MultipartHelper singleton
31
     */
32
    private $multipartHelper;
33
34
    /**
35
     * @var PrivacyHelper the PrivacyHelper singleton
36
     */
37
    private $privacyHelper;
38
39
    /**
40
     * @var PartFactoryService the PartFactoryService
41
     */
42
    private $partFactoryService;
43
44
    /**
45
     * @param PartBuilderFactory $partBuilderFactory
46
     */
47
    public function __construct(PartBuilderFactory $partBuilderFactory)
48
    {
49
        $this->partBuilderFactory = $partBuilderFactory;
50
    }
51
52
    /**
53
     * Set separately to avoid circular dependencies (PartFactoryService needs a
54
     * MessageHelperService).
55
     *
56
     * @param PartFactoryService $partFactoryService
57
     */
58
    public function setPartFactoryService(PartFactoryService $partFactoryService)
59
    {
60
        $this->partFactoryService = $partFactoryService;
61
    }
62
63
    /**
64
     * Returns the GenericHelper singleton
65
     * 
66
     * @return GenericHelper
67
     */
68 1
    public function getGenericHelper()
69
    {
70 1
        if ($this->genericHelper === null) {
71 1
            $this->genericHelper = new GenericHelper(
72 1
                $this->partFactoryService->getMimePartFactory(),
73 1
                $this->partFactoryService->getUUEncodedPartFactory(),
74 1
                $this->partBuilderFactory
75
            );
76
        }
77 1
        return $this->genericHelper;
78
    }
79
80
    /**
81
     * Returns the MultipartHelper singleton
82
     *
83
     * @return MultipartHelper
84
     */
85 1
    public function getMultipartHelper()
86
    {
87 1
        if ($this->multipartHelper === null) {
88 1
            $this->multipartHelper = new MultipartHelper(
89 1
                $this->partFactoryService->getMimePartFactory(),
90 1
                $this->partFactoryService->getUUEncodedPartFactory(),
91 1
                $this->partBuilderFactory,
92 1
                $this->getGenericHelper()
93
            );
94
        }
95 1
        return $this->multipartHelper;
96
    }
97
98
    /**
99
     * Returns the PrivacyHelper singleton
100
     *
101
     * @return PrivacyHelper
102
     */
103 1
    public function getPrivacyHelper()
104
    {
105 1
        if ($this->privacyHelper === null) {
106 1
            $this->privacyHelper = new PrivacyHelper(
107 1
                $this->partFactoryService->getMimePartFactory(),
108 1
                $this->partFactoryService->getUUEncodedPartFactory(),
109 1
                $this->partBuilderFactory,
110 1
                $this->getGenericHelper(),
111 1
                $this->getMultipartHelper()
112
            );
113
        }
114 1
        return $this->privacyHelper;
115
    }
116
}
117