Passed
Push — 1.0.0 ( 4505d9...06b3ad )
by Zaahid
04:10
created

MimePartFactory::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 6
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\Message\Part;
8
9
use Psr\Http\Message\StreamInterface;
10
use ZBateson\MailMimeParser\Stream\StreamDecoratorFactory;
11
use ZBateson\MailMimeParser\Header\HeaderFactory;
12
use ZBateson\MailMimeParser\Message\PartFilterFactory;
13
14
/**
15
 * Responsible for creating MimePart instances.
16
 *
17
 * @author Zaahid Bateson
18
 */
19
class MimePartFactory extends MessagePartFactory
20
{
21
    /**
22
     * Creates a MimePartFactory instance with its dependencies.
23
     *
24
     * @param StreamDecoratorFactory $sdf
25
     * @param PartStreamFilterManagerFactory $psf
26
     * @param HeaderFactory $hf
27
     * @param PartFilterFactory $pf
28
     */
29 1
    public function __construct(
30
        StreamDecoratorFactory $sdf,
31
        PartStreamFilterManagerFactory $psf,
32
        HeaderFactory $hf,
33
        PartFilterFactory $pf
34
    ) {
35 1
        parent::__construct($sdf, $psf);
36 1
        $this->headerFactory = $hf;
0 ignored issues
show
Bug Best Practice introduced by
The property headerFactory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37 1
        $this->partFilterFactory = $pf;
0 ignored issues
show
Bug Best Practice introduced by
The property partFilterFactory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38 1
    }
39
40
    /**
41
     * Returns the singleton instance for the class.
42
     *
43
     * @param StreamDecoratorFactory $sdf
44
     * @param PartStreamFilterManagerFactory $psf
45
     * @param HeaderFactory $hf
46
     * @param PartFilterFactory $pf
47
     * @return MessagePartFactory
48
     */
49
    public static function getInstance(
50
        StreamDecoratorFactory $sdf,
51
        PartStreamFilterManagerFactory $psf,
52
        HeaderFactory $hf = null,
53
        PartFilterFactory $pf = null
54
    ) {
55
        $instance = static::getCachedInstance();
56
        if ($instance === null) {
57
            $instance = new static($sdf, $psf, $hf, $pf);
0 ignored issues
show
Bug introduced by
It seems like $hf can also be of type null; however, parameter $hf of ZBateson\MailMimeParser\...tFactory::__construct() does only seem to accept ZBateson\MailMimeParser\Header\HeaderFactory, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            $instance = new static($sdf, $psf, /** @scrutinizer ignore-type */ $hf, $pf);
Loading history...
Bug introduced by
It seems like $pf can also be of type null; however, parameter $pf of ZBateson\MailMimeParser\...tFactory::__construct() does only seem to accept ZBateson\MailMimeParser\Message\PartFilterFactory, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            $instance = new static($sdf, $psf, $hf, /** @scrutinizer ignore-type */ $pf);
Loading history...
58
            static::setCachedInstance($instance);
59
        }
60
        return $instance;
61
    }
62
63
    /**
64
     * Constructs a new MimePart object and returns it
65
     * 
66
     * @param StreamInterface $messageStream
67
     * @param PartBuilder $partBuilder
68
     * @return \ZBateson\MailMimeParser\Message\Part\MimePart
69
     */
70 1
    public function newInstance(StreamInterface $messageStream, PartBuilder $partBuilder)
71
    {
72 1
        return new MimePart(
73 1
            $this->headerFactory,
74 1
            $this->partFilterFactory,
75 1
            $partBuilder,
76 1
            $this->partStreamFilterManagerFactory->newInstance(),
77 1
            $this->streamDecoratorFactory->getLimitedPartStream($messageStream, $partBuilder),
78 1
            $this->streamDecoratorFactory->getLimitedContentStream($messageStream, $partBuilder)
79
        );
80
    }
81
}
82