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

MessagePartFactory::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 3
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\PartFilterFactory;
11
12
/**
13
 * Abstract factory for subclasses of MessagePart.
14
 *
15
 * @author Zaahid Bateson
16
 */
17
abstract class MessagePartFactory
18
{
19
    /**
20
     * @var PartStreamFilterManagerFactory responsible for creating
21
     *      PartStreamFilterManager instances
22
     */
23
    protected $partStreamFilterManagerFactory;
24
    
25
    /**
26
     * Initializes class dependencies.
27
     * 
28
     * @param PartStreamFilterManagerFactory $psf
29
     */
30
    public function __construct(PartStreamFilterManagerFactory $psf)
31
    {
32
        $this->partStreamFilterManagerFactory = $psf;
33
    }
34
    
35
    /**
36
     * Returns the singleton instance for the class.
37
     * 
38
     * @param PartStreamFilterManagerFactory $psf
39
     * @param HeaderFactory $hf
40
     * @param PartFilterFactory $pf
41
     * @return MessagePartFactory
42
     */
43 View Code Duplication
    public static function getInstance(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
        PartStreamFilterManagerFactory $psf,
45
        HeaderFactory $hf = null,
46
        PartFilterFactory $pf = null
47
    ) {
48
        static $instances = [];
49
        $class = get_called_class();
50
        if (!isset($instances[$class])) {
51
            $instances[$class] = new static($psf);
52
        }
53
        return $instances[$class];
54
    }
55
    
56
    /**
57
     * Constructs a new MessagePart object and returns it
58
     * 
59
     * @param string $messageObjectId
60
     * @param PartBuilder $partBuilder
61
     * @return \ZBateson\MailMimeParser\Message\Part\MessagePart
62
     */
63
    public abstract function newInstance($messageObjectId, PartBuilder $partBuilder);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
64
}
65