Passed
Push — 1.0.0 ( 1b586d...185e59 )
by Zaahid
03:51
created

MimePartFactory::newChildInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 2
rs 10
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\Factory;
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
use ZBateson\MailMimeParser\Message\Part\MimePart;
14
use ZBateson\MailMimeParser\Message\Part\PartBuilder;
15
use ZBateson\MailMimeParser\Message\Writer\MessageWriterService;
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\...er\MessageWriterService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * Responsible for creating MimePart instances.
19
 *
20
 * @author Zaahid Bateson
21
 */
22
class MimePartFactory extends MessagePartFactory
23
{
24
    /**
25
     * @var HeaderFactory an instance used for creating MimePart objects 
26
     */
27
    protected $headerFactory;
28
29
    /**
30
     * @var PartFilterFactory an instance used for creating MimePart objects
31
     */
32
    protected $partFilterFactory;
33
34
    /**
35
     * Initializes dependencies.
36
     *
37
     * @param StreamDecoratorFactory $sdf
38
     * @param PartStreamFilterManagerFactory $psf
39
     * @param HeaderFactory $hf
40
     * @param PartFilterFactory $pf
41
     */
42 1
    public function __construct(
43
        StreamDecoratorFactory $sdf,
44
        PartStreamFilterManagerFactory $psf,
45
        HeaderFactory $hf,
46
        PartFilterFactory $pf
47
    ) {
48 1
        parent::__construct($sdf, $psf);
49 1
        $this->headerFactory = $hf;
50 1
        $this->partFilterFactory = $pf;
51 1
    }
52
53
    /**
54
     * Returns the singleton instance for the class.
55
     *
56
     * @param StreamDecoratorFactory $sdf
57
     * @param PartStreamFilterManagerFactory $psf
58
     * @param HeaderFactory $hf
59
     * @param PartFilterFactory $pf
60
     * @param MessageWriterService $ws
61
     * @return MessagePartFactory
62
     */
63
    public static function getInstance(
64
        StreamDecoratorFactory $sdf,
65
        PartStreamFilterManagerFactory $psf,
66
        HeaderFactory $hf = null,
67
        PartFilterFactory $pf = null,
68
        MessageWriterService $ws = null,
0 ignored issues
show
Unused Code introduced by
The parameter $ws is not used and could be removed. ( Ignorable by Annotation )

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

68
        /** @scrutinizer ignore-unused */ MessageWriterService $ws = null,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
        MimePartFactory $mpf = null
0 ignored issues
show
Unused Code introduced by
The parameter $mpf is not used and could be removed. ( Ignorable by Annotation )

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

69
        /** @scrutinizer ignore-unused */ MimePartFactory $mpf = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    ) {
71
        $instance = static::getCachedInstance();
72
        if ($instance === null) {
73
            $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

73
            $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

73
            $instance = new static($sdf, $psf, $hf, /** @scrutinizer ignore-type */ $pf);
Loading history...
74
            static::setCachedInstance($instance);
75
        }
76
        return $instance;
77
    }
78
79
    /**
80
     * Constructs a new MimePart object and returns it
81
     * 
82
     * @param StreamInterface $messageStream
83
     * @param PartBuilder $partBuilder
84
     * @return \ZBateson\MailMimeParser\Message\Part\MimePart
85
     */
86 1
    public function newInstance(StreamInterface $messageStream, PartBuilder $partBuilder)
87
    {
88 1
        return new MimePart(
89 1
            $this->headerFactory,
90 1
            $this->partFilterFactory,
91 1
            $partBuilder,
92 1
            $this->partStreamFilterManagerFactory->newInstance(),
93 1
            $this->streamDecoratorFactory->getLimitedPartStream($messageStream, $partBuilder),
94 1
            $this->streamDecoratorFactory->getLimitedContentStream($messageStream, $partBuilder)
95
        );
96
    }
97
98
    /**
99
     *
100
     * @return MimePart
101
     */
102
    public function newChildInstance()
103
    {
104
        return new MimePart(
0 ignored issues
show
Bug introduced by
The call to ZBateson\MailMimeParser\...MimePart::__construct() has too few arguments starting with stream. ( Ignorable by Annotation )

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

104
        return /** @scrutinizer ignore-call */ new MimePart(

This check compares calls to functions or methods with their respective definitions. If the call has less 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. Please note the @ignore annotation hint above.

Loading history...
105
            $this->headerFactory,
106
            $this->partFilterFactory,
107
            null,
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type ZBateson\MailMimeParser\Message\Part\PartBuilder expected by parameter $partBuilder of ZBateson\MailMimeParser\...MimePart::__construct(). ( Ignorable by Annotation )

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

107
            /** @scrutinizer ignore-type */ null,
Loading history...
108
            $this->partStreamFilterManagerFactory->newInstance()
109
        );
110
    }
111
}
112