Test Failed
Push — 1.0.0 ( d3c3e6...4505d9 )
by Zaahid
04:05
created

SimpleDi::getHeaderPartFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 2
rs 9.4285
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;
8
9
use ZBateson\MailMimeParser\Message\MessageParser;
10
use ZBateson\MailMimeParser\Message\Part\PartBuilderFactory;
11
use ZBateson\MailMimeParser\Message\Part\PartFactoryService;
12
use ZBateson\MailMimeParser\Header\Consumer\ConsumerService;
13
use ZBateson\MailMimeParser\Header\HeaderFactory;
14
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
15
use ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory;
16
use ZBateson\MailMimeParser\Stream\PartStream;
17
use ZBateson\MailMimeParser\Util\CharsetConverter;
18
use ZBateson\MailMimeParser\Message\Part\PartStreamFilterManagerFactory;
19
use ZBateson\MailMimeParser\Stream\StreamDecoderFactory;
20
21
/**
22
 * Dependency injection container for use by ZBateson\MailMimeParser - because a
23
 * more complex one seems like overkill.
24
 * 
25
 * Constructs objects and whatever dependencies they require.
26
 *
27
 * @author Zaahid Bateson
28
 */
29
class SimpleDi
30
{
31
    /**
32
     * @var type 
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
     */
34
    protected $partBuilderFactory;
35
    
36
    /**
37
     * @var type 
38
     */
39
    protected $partFactoryService;
40
    
41
    /**
42
     * @var type 
43
     */
44
    protected $partFilterFactory;
45
    
46
    /**
47
     * @var type 
48
     */
49
    protected $partStreamFilterManagerFactory;
50
    
51
    /**
52
     * @var \ZBateson\MailMimeParser\Stream\PartStreamRegistry singleton
53
     * 'service' instance
54
     */
55
    protected $partStreamRegistry;
56
    
57
    /**
58
     * @var \ZBateson\MailMimeParser\Header\HeaderFactory singleton 'service'
59
     * instance
60
     */
61
    protected $headerFactory;
62
    
63
    /**
64
     * @var \ZBateson\MailMimeParser\Header\Part\HeaderPartFactory singleton
65
     * 'service' instance
66
     */
67
    protected $headerPartFactory;
68
    
69
    /**
70
     * @var \ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory
71
     * singleton 'service' instance
72
     */
73
    protected $mimeLiteralPartFactory;
74
    
75
    /**
76
     * @var \ZBateson\MailMimeParser\Header\Consumer\ConsumerService singleton
77
     * 'service' instance
78
     */
79
    protected $consumerService;
80
    
81
    /**
82
     * @var \ZBateson\MailMimeParser\Message\Writer\MessageWriterService 
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\...er\MessageWriterService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
83
     * singleton 'service' instance for getting MimePartWriter and MessageWriter
84
     * instances
85
     */
86
    protected $messageWriterService;
87
    
88
    /**
89
     * Constructs a SimpleDi - call singleton() to invoke
90
     */
91
    private function __construct()
92
    {
93
    }
94 1
    
95
    /**
96 1
     * Returns the singleton instance.
97
     * 
98
     * @return \ZBateson\MailMimeParser\SimpleDi
99
     */
100
    public static function singleton()
101
    {
102
        static $singleton = null;
103 8
        if ($singleton === null) {
104
            $singleton = new SimpleDi();
105 8
        }
106 8
        return $singleton;
107 1
    }
108 1
    
109 8
    /**
110
     * Returns a singleton 'service' instance for the given service named $var
111
     * with a class type of $class.
112
     * 
113
     * @param string $var the name of the service
114
     * @param string $class the name of the class
115
     * @return mixed the service object
116
     */
117
    protected function getInstance($var, $class)
118
    {
119
        if ($this->$var === null) {
120 2
            $this->$var = new $class();
121
        }
122 2
        return $this->$var;
123 1
    }
124 1
    
125 2
    /**
126
     * Constructs and returns a new MessageParser object.
127
     * 
128
     * @return \ZBateson\MailMimeParser\Message\MessageParser
129
     */
130
    public function newMessageParser()
131
    {
132
        return new MessageParser(
133 1
            $this->getPartFactoryService(),
134
            $this->getPartBuilderFactory()
135 1
        );
136 1
    }
137 1
    
138 1
    /**
139 1
     * Returns a MessageWriterService instance.
140
     * 
141
     * @return MessageWriterService
142
     */
143
    public function getMessageWriterService()
144
    {
145
        if ($this->messageWriterService === null) {
146
            $this->messageWriterService = new MessageWriterService();
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\MessageWriterService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
147
        }
148
        return $this->messageWriterService;
149
    }
150
    
151
    /**
152
     * Constructs and returns a new CharsetConverter object.
153
     * 
154
     * @return \ZBateson\MailMimeParser\Util\CharsetConverter
155
     */
156
    public function newCharsetConverter()
157
    {
158
        return new CharsetConverter();
159
    }
160 1
    
161
    
162 1
    public function getPartFilterFactory()
163
    {
164
        return $this->getInstance(
165
            'partFilterFactory',
166 1
            __NAMESPACE__ . '\Message\PartFilterFactory'
167
        );
168 1
    }
169 1
    
170
    /**
171 1
     * 
172
     * @return type
173
     */
174
    public function getPartFactoryService()
175
    {
176
        if ($this->partFactoryService === null) {
177
            $this->partFactoryService = new PartFactoryService(
0 ignored issues
show
Documentation Bug introduced by
It seems like new ZBateson\MailMimePar...FilterManagerFactory()) of type ZBateson\MailMimeParser\...Part\PartFactoryService is incompatible with the declared type ZBateson\MailMimeParser\type of property $partFactoryService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
178 1
                $this->getHeaderFactory(),
179
                $this->getPartFilterFactory(),
180 1
                $this->getPartStreamFilterManagerFactory()
181 1
            );
182 1
        }
183 1
        return $this->partFactoryService;
184 1
    }
185 1
186 1
    public function getPartBuilderFactory()
187 1
    {
188
        if ($this->partBuilderFactory === null) {
189
            $this->partBuilderFactory = new PartBuilderFactory(
0 ignored issues
show
Documentation Bug introduced by
It seems like new ZBateson\MailMimePar...is->getHeaderFactory()) of type ZBateson\MailMimeParser\...Part\PartBuilderFactory is incompatible with the declared type ZBateson\MailMimeParser\type of property $partBuilderFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
190 1
                $this->getHeaderFactory()
191
            );
192 1
        }
193 1
        return $this->partBuilderFactory;
194 1
    }
195
    
196 1
    /**
197 1
     * Returns the header factory service instance.
198 1
     * 
199
     * @return \ZBateson\MailMimeParser\Header\HeaderFactory
200
     */
201
    public function getHeaderFactory()
202
    {
203
        if ($this->headerFactory === null) {
204
            $this->headerFactory = new HeaderFactory($this->getConsumerService());
205
        }
206 2
        return $this->headerFactory;
207
    }
208 2
    
209 1
    public function getPartStreamFilterManagerFactory()
210 1
    {
211 2
        if ($this->partStreamFilterManagerFactory === null) {
212
            $this->partStreamFilterManagerFactory = new PartStreamFilterManagerFactory(
0 ignored issues
show
Documentation Bug introduced by
It seems like new ZBateson\MailMimePar...StreamDecoderFactory()) of type ZBateson\MailMimeParser\...eamFilterManagerFactory is incompatible with the declared type ZBateson\MailMimeParser\type of property $partStreamFilterManagerFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
213
                new StreamDecoderFactory()
214 1
            );
215
        }
216 1
        return $this->getInstance(
217 1
            'partStreamFilterManagerFactory',
218 1
            __NAMESPACE__ . '\Message\Part\PartStreamFilterManagerFactory'
219 1
        );
220 1
    }
221
    
222 1
    public function getCharsetConverter()
223 1
    {
224 1
        return new CharsetConverter();
225 1
    }
226
    
227 1
    /**
228
     * Returns the part factory service
229
     * 
230
     * @return \ZBateson\MailMimeParser\Header\Part\HeaderPartFactory
231
     */
232
    public function getHeaderPartFactory()
233
    {
234
        if ($this->headerPartFactory === null) {
235
            $this->headerPartFactory = new HeaderPartFactory($this->getCharsetConverter());
236 2
        }
237
        return $this->headerPartFactory;
238 2
    }
239 1
    
240 1
    /**
241 2
     * Returns the MimeLiteralPartFactory service
242
     * 
243
     * @return \ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory
244 1
     */
245
    public function getMimeLiteralPartFactory()
246 1
    {
247
        if ($this->mimeLiteralPartFactory === null) {
248
            $this->mimeLiteralPartFactory = new MimeLiteralPartFactory($this->getCharsetConverter());
249
        }
250
        return $this->mimeLiteralPartFactory;
251
    }
252
    
253
    /**
254 2
     * Returns the header consumer service
255
     * 
256 2
     * @return \ZBateson\MailMimeParser\Header\Consumer\ConsumerService
257 1
     */
258 1
    public function getConsumerService()
259 2
    {
260
        if ($this->consumerService === null) {
261
            $this->consumerService = new ConsumerService(
262
                $this->getHeaderPartFactory(),
263
                $this->getMimeLiteralPartFactory()
264
            );
265
        }
266
        return $this->consumerService;
267 2
    }
268
    
269
}
270