Skip to content

Commit 9366da9

Browse files
committed
File content extracted to a separate var. Type hinting, strict comparison
1 parent 4989d8b commit 9366da9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/internal/Magento/Framework/App/Response/Http/FileFactory.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function create(
5959
$dir = $this->_filesystem->getDirectoryWrite($baseDir);
6060
$isFile = false;
6161
$file = null;
62+
$fileContent = $this->getFileContent($content);
6263
if (is_array($content)) {
6364
if (!isset($content['type']) || !isset($content['value'])) {
6465
throw new \InvalidArgumentException("Invalid arguments. Keys 'type' and 'value' are required.");
@@ -76,11 +77,7 @@ public function create(
7677
->setHeader('Pragma', 'public', true)
7778
->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
7879
->setHeader('Content-type', $contentType, true)
79-
->setHeader(
80-
'Content-Length',
81-
$contentLength === null ? strlen($this->getFileContent($content)) : $contentLength,
82-
true
83-
)
80+
->setHeader('Content-Length', $contentLength === null ? strlen($fileContent) : $contentLength, true)
8481
->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)
8582
->setHeader('Last-Modified', date('r'), true);
8683

@@ -92,7 +89,7 @@ public function create(
9289
echo $stream->read(1024);
9390
}
9491
} else {
95-
$dir->writeFile($fileName, $this->getFileContent($content));
92+
$dir->writeFile($fileName, $fileContent);
9693
$file = $fileName;
9794
$stream = $dir->openFile($fileName, 'r');
9895
while (!$stream->eof()) {
@@ -114,9 +111,9 @@ public function create(
114111
* @param string|array $content
115112
* @return string
116113
*/
117-
private function getFileContent($content)
114+
private function getFileContent($content): string
118115
{
119-
if (isset($content['type']) && $content['type'] == 'string') {
116+
if (isset($content['type']) && $content['type'] === 'string') {
120117
return $content['value'];
121118
}
122119

0 commit comments

Comments
 (0)