Test Failed
Push — master ( 66d82e...4ebaf8 )
by Zaahid
03:17
created

ConsumerService::getParameterConsumer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
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\Header\Consumer;
8
9
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
10
use ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory;
11
use ZBateson\MailMimeParser\Header\Consumer\Received\DomainConsumer;
12
use ZBateson\MailMimeParser\Header\Consumer\Received\GenericReceivedConsumer;
13
use ZBateson\MailMimeParser\Header\Consumer\Received\ReceivedDateConsumer;
14
15
/**
16
 * Simple service provider for consumer singletons.
17
 *
18
 * @author Zaahid Bateson
19
 */
20
class ConsumerService
21
{
22
    /**
23
     * @var \ZBateson\MailMimeParser\Header\Part\HeaderPartFactory the
24
     * HeaderPartFactory instance used to create HeaderParts.
25
     */
26
    protected $partFactory;
27
    
28
    /**
29
     * @var \ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory used for
30
     * GenericConsumer instances.
31
     */
32
    protected $mimeLiteralPartFactory;
33
34
    /**
35
     * @var Received\DomainConsumer[]|
36
     *      Received\GenericReceivedConsumer[]|
37 8
     *      Received\ReceivedDateConsumer[] an array of sub-received header
38
     *      consumer instances.
39 8
     */
40 8
    protected $receivedConsumers = [
41 8
        'from' => null,
42
        'by' => null,
43
        'via' => null,
44
        'with' => null,
45
        'id' => null,
46
        'for' => null,
47
        'date' => null
48 1
    ];
49
    
50 1
    /**
51
     * Sets up the HeaderPartFactory member variable.
52
     * 
53
     * @param HeaderPartFactory $partFactory
54
     * @param MimeLiteralPartFactory $mimeLiteralPartFactory
55
     */
56
    public function __construct(HeaderPartFactory $partFactory, MimeLiteralPartFactory $mimeLiteralPartFactory)
57
    {
58 1
        $this->partFactory = $partFactory;
59
        $this->mimeLiteralPartFactory = $mimeLiteralPartFactory;
60 1
    }
61
    
62
    /**
63
     * Returns the AddressBaseConsumer singleton instance.
64
     * 
65
     * @return \ZBateson\MailMimeParser\Header\Consumer\AddressBaseConsumer
66
     */
67
    public function getAddressBaseConsumer()
68 1
    {
69
        return AddressBaseConsumer::getInstance($this, $this->partFactory);
70 1
    }
71
    
72
    /**
73
     * Returns the AddressConsumer singleton instance.
74
     * 
75
     * @return \ZBateson\MailMimeParser\Header\Consumer\AddressConsumer
76
     */
77
    public function getAddressConsumer()
78 1
    {
79
        return AddressConsumer::getInstance($this, $this->partFactory);
80 1
    }
81
    
82
    /**
83
     * Returns the AddressGroupConsumer singleton instance.
84
     * 
85
     * @return \ZBateson\MailMimeParser\Header\Consumer\AddressGroupConsumer
86
     */
87
    public function getAddressGroupConsumer()
88 1
    {
89
        return AddressGroupConsumer::getInstance($this, $this->partFactory);
90 1
    }
91
    
92
    /**
93
     * Returns the CommentConsumer singleton instance.
94
     * 
95
     * @return \ZBateson\MailMimeParser\Header\Consumer\CommentConsumer
96
     */
97
    public function getCommentConsumer()
98
    {
99
        return CommentConsumer::getInstance($this, $this->partFactory);
100
    }
101
    
102
    /**
103
     * Returns the GenericConsumer singleton instance.
104
     * 
105
     * @return \ZBateson\MailMimeParser\Header\Consumer\GenericConsumer
106
     */
107
    public function getGenericConsumer()
108 1
    {
109
        return GenericConsumer::getInstance($this, $this->mimeLiteralPartFactory);
110 1
    }
111
112
    /**
113
     * Returns the SubjectConsumer singleton instance.
114
     * 
115
     * @return \ZBateson\MailMimeParser\Header\Consumer\SubjectConsumer
116
     */
117
    public function getSubjectConsumer()
118 1
    {
119
        return SubjectConsumer::getInstance($this, $this->mimeLiteralPartFactory);
120 1
    }
121
    
122
    /**
123
     * Returns the QuotedStringConsumer singleton instance.
124
     * 
125
     * @return \ZBateson\MailMimeParser\Header\Consumer\QuotedStringConsumer
126
     */
127
    public function getQuotedStringConsumer()
128 1
    {
129
        return QuotedStringConsumer::getInstance($this, $this->partFactory);
130 1
    }
131
    
132
    /**
133
     * Returns the DateConsumer singleton instance.
134
     * 
135
     * @return \ZBateson\MailMimeParser\Header\Consumer\DateConsumer
136
     */
137
    public function getDateConsumer()
138
    {
139
        return DateConsumer::getInstance($this, $this->partFactory);
140
    }
141
    
142
    /**
143
     * Returns the ParameterConsumer singleton instance.
144
     * 
145
     * @return \ZBateson\MailMimeParser\Header\Consumer\ParameterConsumer
146
     */
147
    public function getParameterConsumer()
148
    {
149
        return ParameterConsumer::getInstance($this, $this->partFactory);
150
    }
151
152
    /**
153
     * Returns the consumer instance corresponding to the passed part name of a
154
     * Received header.
155
     *
156
     * @param string $partName
157
     * @return \ZBateson\MailMimeParser\Header\Consumer\Received\FromConsumer
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\...r\Received\FromConsumer 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...
158
     */
159
    public function getSubReceivedConsumer($partName)
160
    {
161
        if (empty($this->receivedConsumers[$partName])) {
162
            $consumer = null;
163
            if ($partName === 'from' || $partName === 'by') {
164
                $consumer = new DomainConsumer($this, $this->partFactory, $partName);
165
            } else if ($partName === 'date') {
166
                $consumer = new ReceivedDateConsumer($this, $this->partFactory);
167
            } else {
168
                $consumer = new GenericReceivedConsumer($this, $this->partFactory, $partName);
169
            }
170
            $this->receivedConsumers[$partName] = $consumer;
171
        }
172
        return $this->receivedConsumers[$partName];
173
    }
174
175
    /**
176
     * Returns the ReceivedConsumer singleton instance.
177
     *
178
     * @return \ZBateson\MailMimeParser\Header\Consumer\ReceivedConsumer
179
     */
180
    public function getReceivedConsumer()
181
    {
182
        return ReceivedConsumer::getInstance($this, $this->partFactory);
183
    }
184
}
185