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

MessagePartFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 12
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 12 12 2
newInstance() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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