Completed
Pull Request — master (#65)
by Frederik
01:35
created

MessageStream::detach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
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
     * @param MessageInterface $message
20
     */
21
    public function __construct(MessageInterface $message)
22
    {
23 57
        $this->decoratedStream = new LazyStream(function () use ($message) {
24 57
            $headerString = \implode(
25 57
                "\r\n",
26 57
                \array_values(
27 57
                    \array_filter(
28 57
                        \array_map(
29 57
                            function (array $headers) {
30 57
                                return \implode(
31 57
                                    "\r\n",
32 57
                                    \array_map(
33 57
                                        function (HeaderInterface $header) {
34 57
                                            return (string) (new HeaderLine($header));
35 57
                                        },
36 57
                                        $headers
37
                                    )
38
                                );
39 57
                            },
40 57
                            $message->getHeaders()
41
                        )
42
                    )
43
                )
44
            );
45
46 57
            return new ConcatenatedStream(
47 57
                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...
48 57
                    new StringStream($headerString),
49 57
                    new StringStream("\r\n\r\n"),
50 57
                    $message->getBody()
51
                ])
52
            );
53 57
        });
54 57
    }
55
56
    /**
57
     * @return string
58
     */
59 56
    public function __toString(): string
60
    {
61 56
        return $this->decoratedStream->__toString();
62
    }
63
    
64
    public function close(): void
65
    {
66
        $this->decoratedStream->close();
67
    }
68
69
    /**
70
     * @return mixed
71
     */
72
    public function detach()
73
    {
74
        return $this->decoratedStream->detach();
75
    }
76
77
    /**
78
     * @return int|null
79
     */
80
    public function getSize(): ?int
81
    {
82
        return $this->decoratedStream->getSize();
83
    }
84
85
    /**
86
     * @return int
87
     * @throws \RuntimeException
88
     */
89
    public function tell(): int
90
    {
91
        return $this->decoratedStream->tell();
92
    }
93
94
    /**
95
     * @return bool
96
     */
97 2
    public function eof(): bool
98
    {
99 2
        return $this->decoratedStream->eof();
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    public function isSeekable(): bool
106
    {
107
        return $this->decoratedStream->isSeekable();
108
    }
109
110
    /**
111
     * @param int $offset
112
     * @param int $whence
113
     * @return int
114
     */
115
    public function seek(int $offset, int $whence = SEEK_SET): int
116
    {
117
        return $this->decoratedStream->seek($offset, $whence);
118
    }
119
120
    /**
121
     * @return bool
122
     */
123 2
    public function rewind(): bool
124
    {
125 2
        return $this->decoratedStream->rewind();
126
    }
127
128
    /**
129
     * @return bool
130
     */
131
    public function isWritable(): bool
132
    {
133
        return false;
134
    }
135
136
    /**
137
     * @param string $string
138
     * @return int
139
     */
140
    public function write($string): int
141
    {
142
        throw new \RuntimeException('Cannot write to stream');
143
    }
144
145
    /**
146
     * @return bool
147
     */
148
    public function isReadable(): bool
149
    {
150
        return true;
151
    }
152
153
    /**
154
     * @param int $length
155
     * @return string
156
     */
157 2
    public function read(int $length): string
158
    {
159 2
        return $this->decoratedStream->read($length);
160
    }
161
162
    /**
163
     * @return string
164
     */
165
    public function getContents(): string
166
    {
167
        return $this->decoratedStream->getContents();
168
    }
169
170
    /**
171
     * @param array $keys
172
     * @return array
173
     */
174
    public function getMetadata(array $keys = []): array
175
    {
176
        return $this->decoratedStream->getMetadata();
177
    }
178
}
179