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
|
|
|
use ReflectionClass; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Abstract factory for subclasses of MessagePart. |
15
|
|
|
* |
16
|
|
|
* @author Zaahid Bateson |
17
|
|
|
*/ |
18
|
|
|
abstract class MessagePartFactory |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var PartStreamFilterManagerFactory responsible for creating |
22
|
|
|
* PartStreamFilterManager instances |
23
|
|
|
*/ |
24
|
|
|
protected $partStreamFilterManagerFactory; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Initializes class dependencies. |
28
|
|
|
* |
29
|
|
|
* @param PartStreamFilterManagerFactory $psf |
30
|
|
|
*/ |
31
|
3 |
|
public function __construct(PartStreamFilterManagerFactory $psf) |
32
|
|
|
{ |
33
|
3 |
|
$this->partStreamFilterManagerFactory = $psf; |
34
|
3 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns the singleton instance for the class. |
38
|
|
|
* |
39
|
|
|
* @param PartStreamFilterManagerFactory $psf |
40
|
|
|
* @param HeaderFactory $hf |
41
|
|
|
* @param PartFilterFactory $pf |
42
|
|
|
* @return MessagePartFactory |
43
|
|
|
*/ |
44
|
|
|
public static function getInstance( |
45
|
|
|
PartStreamFilterManagerFactory $psf, |
46
|
|
|
HeaderFactory $hf = null, |
47
|
|
|
PartFilterFactory $pf = null |
48
|
|
|
) { |
49
|
|
|
static $instances = []; |
50
|
|
|
$class = get_called_class(); |
51
|
|
|
if (!isset($instances[$class])) { |
52
|
|
|
$rf = new ReflectionClass($class); |
53
|
|
|
$constr = $rf->getConstructor(); |
54
|
|
|
if ($constr->getNumberOfParameters() === 3) { |
55
|
|
|
$instances[$class] = new static($psf, $hf, $pf); |
|
|
|
|
56
|
|
|
} else { |
57
|
|
|
$instances[$class] = new static($psf); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
return $instances[$class]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Constructs a new MessagePart object and returns it |
65
|
|
|
* |
66
|
|
|
* @param string $messageObjectId |
67
|
|
|
* @param PartBuilder $partBuilder |
68
|
|
|
* @return \ZBateson\MailMimeParser\Message\Part\MessagePart |
69
|
|
|
*/ |
70
|
|
|
public abstract function newInstance($messageObjectId, PartBuilder $partBuilder); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.