8000 [Mime] used yield-from when possible · symfony/symfony@df1b627 · GitHub
[go: up one dir, main page]

Skip to content

Commit df1b627

Browse files
committed
[Mime] used yield-from when possible
1 parent 5b38e17 commit df1b627

File tree

6 files changed

+7
-15
lines changed

6 files changed

+7
-15
lines changed

src/Symfony/Component/Mime/Message.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ public function toIterable(): iterable
122122
}
123123

124124
yield $this->getPreparedHeaders()->toString();
125-
foreach ($body->toIterable() as $chunk) {
126-
yield $chunk;
127-
}
125+
yield from $body->toIterable();
128126
}
129127

130128
private function generateMessageId(string $email): string

src/Symfony/Component/Mime/Part/AbstractMultipartPart.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ public function bodyToIterable(): iterable
8181

8282
foreach ($parts as $part) {
8383
yield '--'.$this->getBoundary()."\r\n";
84-
foreach ($part->toIterable() as $chunk) {
85-
yield $chunk;
86-
}
84+
yield from $part->toIterable();
8785
yield "\r\n";
8886
}
8987
yield '--'.$this->getBoundary()."--\r\n";

src/Symfony/Component/Mime/Part/AbstractPart.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public function toIterable(): iterable
4949
{
5050
yield $this->getPreparedHeaders()->toString();
5151
yield "\r\n";
52-
foreach ($this->bodyToIterable() as $chunk) {
53-
yield $chunk;
54-
}
52+
yield from $this->bodyToIterable();
5553
}
5654

5755
abstract public function bodyToString(): string;

src/Symfony/Component/Mime/Part/TextPart.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ public function bodyToIterable(): iterable
118118
if (stream_get_meta_data($this->body)['seekable'] ?? false) {
119119
rewind($this->body);
120120
}
121-
foreach ($this->getEncoder()->encodeByteStream($this->body) as $chunk) {
122-
yield $chunk;
123-
}
121+
yield from $this->getEncoder()->encodeByteStream($this->body);
124122
} else {
125123
yield $this->getEncoder()->encodeString($this->body);
126124
}

src/Symfony/Component/Mime/RawMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function toString(): string
3434
return $this->message;
3535
}
3636

37-
return $this->message = implode('', iterator_to_array($this->message));
37+
return $this->message = implode('', iterator_to_array($this->message, false));
3838
}
3939

4040
public function toIterable(): iterable

src/Symfony/Component/Mime/Tests/MessageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testToString()
131131
132132
EOF;
133133
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
134-
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable()))));
134+
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable(), false))));
135135

136136
$message = new Message(null, new TextPart('content'));
137137
$message->getHeaders()->addMailboxListHeader('From', ['fabien@symfony.com']);
@@ -146,6 +146,6 @@ public function testToString()
146146
content
147147
EOF;
148148
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
149-
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable()))));
149+
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable(), false))));
150150
}
151151
}

0 commit comments

Comments
 (0)
0