Test Failed
Push — 1.0.0 ( dd1332...30b11b )
by Zaahid
02:32
created

HeaderStream   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPartHeadersArray() 0 12 4
A writePartHeadersTo() 0 7 2
A __construct() 0 3 1
A createStream() 0 6 1
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\Stream;
8
9
use ZBateson\MailMimeParser\Message\Part\ParentHeaderPart;
10
use ZBateson\MailMimeParser\Message\Part\MessagePart;
11
use Psr\Http\Message\StreamInterface;
12
use GuzzleHttp\Psr7\StreamDecoratorTrait;
13
use GuzzleHttp\Psr7;
14
15
/**
16
 * 
17
 *
18
 * @author Zaahid Bateson
19
 */
20
class HeaderStream implements StreamInterface
21
{
22
    use StreamDecoratorTrait;
23
24
    protected $part;
25
26
    public function __construct(MessagePart $part)
27
    {
28
        $this->part = $part;
29
    }
30
31
    private function getPartHeadersArray()
32
    {
33
        if ($this->part instanceof ParentHeaderPart) {
34
            return $this->part->getRawHeaders();
35
        } elseif ($this->part->getParent() !== null && $this->part->getParent()->isMime()) {
36
            return [
37
                'Content-Type' => $this->part->getContentType(),
38
                'Content-Disposition' => $this->part->getContentDisposition(),
39
                'Content-Transfer-Encoding' => $this->part->getContentTransferEncoding()
40
            ];
41
        }
42
        return [];
43
    }
44
45
    /**
46
     * Writes out the headers of the passed part and follows them with an
47
     * empty line.
48
     *
49
     * @param MimePart $part
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\Stream\MimePart 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...
50
     * @param StreamInterface $stream
51
     */
52
    public function writePartHeadersTo(StreamInterface $stream)
53
    {
54
        $headers = $this->getPartHeadersArray($this->part);
0 ignored issues
show
Unused Code introduced by
The call to ZBateson\MailMimeParser\...::getPartHeadersArray() has too many arguments starting with $this->part. ( Ignorable by Annotation )

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

54
        /** @scrutinizer ignore-call */ 
55
        $headers = $this->getPartHeadersArray($this->part);

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. Please note the @ignore annotation hint above.

Loading history...
55
        foreach ($headers as $header) {
56
            $stream->write("${header[0]}: ${header[1]}\r\n");
57
        }
58
        $stream->write("\r\n");
59
    }
60
61
    /**
62
     * Creates the underlying stream lazily when required.
63
     *
64
     * @return StreamInterface
65
     */
66
    protected function createStream()
67
    {
68
        $stream = Psr7\stream_for('php://temp');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

68
        $stream = /** @scrutinizer ignore-call */ Psr7\stream_for('php://temp');
Loading history...
69
        $this->writePartHeadersTo($stream);
70
        $stream->rewind();
71
        return $stream;
72
    }
73
}
74