Completed
Pull Request — master (#32)
by Gawain
01:49
created

MessageStream::detach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Genkgo\Mail\Stream;
5
6
use Genkgo\Mail\Header\HeaderLine;
7
use Genkgo\Mail\HeaderInterface;
8
use Genkgo\Mail\MessageInterface;
9
use Genkgo\Mail\StreamInterface;
10
11
final class MessageStream implements StreamInterface
12
{
13
    /**
14
     * @var StreamInterface
15
     */
16
    private $decoratedStream;
17
18
    /**
19
     * MessageStream constructor.
20
     * @param MessageInterface $message
21
     */
22 35
    public function __construct(MessageInterface $message)
23
    {
24
        $this->decoratedStream = new LazyStream(function () use ($message) {
25 35
            $headerString = implode(
26 35
                "\r\n",
27 35
                array_values(
28 35
                    array_filter(
29 35
                        array_map(
30
                            function (array $headers) {
31 35
                                return implode(
32 35
                                    "\r\n",
33 35
                                    array_map(
34 35
                                        function (HeaderInterface $header) {
35 35
                                            return (string) (new HeaderLine($header));
36 35
                                        },
37 35
                                        $headers
38
                                    )
39
                                );
40 35
                            },
41 35
                            $message->getHeaders()
42
                        )
43
                    )
44
                )
45
            );
46
47 35
            return new ConcatenatedStream(
48 35
                new \ArrayObject([
0 ignored issues
show
Documentation introduced by
new \ArrayObject(array(n..., $message->getBody())) is of type object<ArrayObject>, but the function expects a object<Genkgo\Mail\Stream\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49 35
                    new StringStream($headerString),
50 35
                    new StringStream("\r\n\r\n"),
51 35
                    $message->getBody()
52
                ])
53
            );
54 35
        });
55 35
    }
56
57
    /**
58
     * @return string
59
     */
60 34
    public function __toString(): string
61
    {
62 34
        return $this->decoratedStream->__toString();
63
    }
64
65
    /**
66
     *
67
     */
68
    public function close(): void
69
    {
70
        $this->decoratedStream->close();
71
    }
72
73
    /**
74
     * @return mixed
75
     */
76
    public function detach()
77
    {
78
        return $this->decoratedStream->detach();
79
    }
80
81
    /**
82
     * @return int|null
83
     */
84
    public function getSize(): ?int
85
    {
86
        return $this->decoratedStream->getSize();
87
    }
88
89
    /**
90
     * @return int
91
     * @throws \RuntimeException
92
     */
93
    public function tell(): int
94
    {
95
        return $this->decoratedStream->tell();
96
    }
97
98
    /**
99
     * @return bool
100
     */
101 1
    public function eof(): bool
102
    {
103 1
        return $this->decoratedStream->eof();
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isSeekable(): bool
110
    {
111
        return $this->decoratedStream->isSeekable();
112
    }
113
114
    /**
115
     * @param int $offset
116
     * @param int $whence
117
     * @return int
118
     */
119
    public function seek(int $offset, int $whence = SEEK_SET): int
120
    {
121
        return $this->decoratedStream->seek($offset, $whence);
122
    }
123
124
    /**
125
     * @return bool
126
     */
127 1
    public function rewind(): bool
128
    {
129 1
        return $this->decoratedStream->rewind();
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function isWritable(): bool
136
    {
137
        return false;
138
    }
139
140
    /**
141
     * @param $string
142
     * @return int
143
     */
144
    public function write($string): int
145
    {
146
        throw new \RuntimeException('Cannot write to stream');
147
    }
148
149
    /**
150
     * @return bool
151
     */
152
    public function isReadable(): bool
153
    {
154
        return true;
155
    }
156
157
    /**
158
     * @param int $length
159
     * @return string
160
     */
161 1
    public function read(int $length): string
162
    {
163 1
        return $this->decoratedStream->read($length);
164
    }
165
166
    /**
167
     * @return string
168
     */
169
    public function getContents(): string
170
    {
171
        return $this->decoratedStream->getContents();
172
    }
173
174
    /**
175
     * @param array $keys
176
     * @return array
177
     */
178
    public function getMetadata(array $keys = []): array
179
    {
180
        return $this->decoratedStream->getMetadata();
181
    }
182
}