Test Failed
Branch 1.0.0 (84f469)
by Zaahid
05:36
created

PartFactoryService::getMimePartFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 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\Part;
8
9
use ZBateson\MailMimeParser\Header\HeaderFactory;
10
use ZBateson\MailMimeParser\Message\MessageFactory;
11
use ZBateson\MailMimeParser\Message\PartFilterFactory;
12
13
/**
14
 * Responsible for creating singleton instances of MessagePartFactory and its
15
 * subclasses.
16
 *
17
 * @author Zaahid Bateson
18
 */
19
class PartFactoryService
20
{
21
    /**
22
     * @var \ZBateson\MailMimeParser\Header\HeaderFactory the HeaderFactory
23
     *      object used for created headers
24
     */
25
    protected $headerFactory;
26
    
27
    /**
28
     * @var \ZBateson\MailMimeParser\Header\HeaderFactory the PartFilterFactory
29
     *      instance
30
     */
31
    protected $partFilterFactory;
32
    
33
    /**
34
     * @var PartStreamFilterManagerFactory the PartStreamFilterManagerFactory
35
     *      instance
36
     */
37
    protected $partStreamFilterManagerFactory;
38
    
39
    /**
40
     * Sets up dependencies.
41
     * 
42
     * @param HeaderFactory $headerFactory
43
     * @param PartFilterFactory $partFilterFactory
44
     * @param PartStreamFilterManagerFactory $partStreamFilterManagerFactory
45
     */
46
    public function __construct(
47
        HeaderFactory $headerFactory,
48
        PartFilterFactory $partFilterFactory,
49
        PartStreamFilterManagerFactory $partStreamFilterManagerFactory
50
    ) {
51
        $this->headerFactory = $headerFactory;
52
        $this->partFilterFactory = $partFilterFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $partFilterFactory of type object<ZBateson\MailMime...sage\PartFilterFactory> is incompatible with the declared type object<ZBateson\MailMime...r\Header\HeaderFactory> of property $partFilterFactory.

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...
53
        $this->partStreamFilterManagerFactory = $partStreamFilterManagerFactory;
54
    }
55
56
    /**
57
     * Returns the MessageFactory singleton instance.
58
     * 
59
     * @return MessageFactory
60
     */
61
    public function getMessageFactory()
62
    {
63
        return MessageFactory::getInstance(
64
            $this->partStreamFilterManagerFactory,
65
            $this->headerFactory,
66
            $this->partFilterFactory
0 ignored issues
show
Documentation introduced by
$this->partFilterFactory is of type object<ZBateson\MailMime...r\Header\HeaderFactory>, but the function expects a null|object<ZBateson\Mai...sage\PartFilterFactory>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        );
68
    }
69
    
70
    /**
71
     * Returns the MimePartFactory singleton instance.
72
     * 
73
     * @return MimePartFactory
74
     */
75
    public function getMimePartFactory()
76
    {
77
        return MimePartFactory::getInstance(
78
            $this->partStreamFilterManagerFactory,
79
            $this->headerFactory,
80
            $this->partFilterFactory
0 ignored issues
show
Documentation introduced by
$this->partFilterFactory is of type object<ZBateson\MailMime...r\Header\HeaderFactory>, but the function expects a null|object<ZBateson\Mai...sage\PartFilterFactory>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
        );
82
    }
83
    
84
    /**
85
     * Returns the NonMimePartFactory singleton instance.
86
     * 
87
     * @return NonMimePartFactory
88
     */
89
    public function getNonMimePartFactory()
90
    {
91
        return NonMimePartFactory::getInstance($this->partStreamFilterManagerFactory);
92
    }
93
    
94
    /**
95
     * Returns the UUEncodedPartFactory singleton instance.
96
     * 
97
     * @return UUEncodedPartFactory
98
     */
99
    public function getUUEncodedPartFactory()
100
    {
101
        return UUEncodedPartFactory::getInstance($this->partStreamFilterManagerFactory);
102
    }
103
}
104