Skip to content

Commit

Permalink
Test to see if scrutinizer expectations match my own
Browse files Browse the repository at this point in the history
  • Loading branch information
basbl committed Apr 2, 2020
1 parent e44c9f2 commit 52025c5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/PhpSpreadsheet/Writer/Ods.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function save($pFilename)
$originalFilename = $pFilename;
if (is_resource($pFilename)) {
$this->fileHandle = $pFilename;
} elseif (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
} elseif (is_string($pFilename) && in_array(strtolower($pFilename), ['php://output', 'php://stdout'], true)) {
// If $pFilename is php://output or php://stdout, make it a temporary file...
$pFilename = @tempnam(File::sysGetTempDir(), 'phpxltmp');
if ($pFilename == '') {
Expand All @@ -108,6 +108,10 @@ public function save($pFilename)
$this->fileHandle = fopen($pFilename, 'wb+');
}

if (!is_resource($this->fileHandle)) {
throw new WriterException('Could not open resource for writing.');
}

$zip = $this->createZip();

$zip->addFile('META-INF/manifest.xml', $this->getWriterPart('meta_inf')->writeManifest());
Expand All @@ -132,7 +136,9 @@ public function save($pFilename)
if (stream_copy_to_stream($this->fileHandle, fopen($originalFilename, 'wb+')) === false) {
throw new WriterException("Could not copy temporary zip file $pFilename to $originalFilename.");
}
@unlink($pFilename);
if (is_string($pFilename)) {
@unlink($pFilename);
}
}
}

Expand All @@ -146,7 +152,7 @@ public function save($pFilename)
private function createZip()
{
// Try opening the ZIP file
if ($this->fileHandle === false) {
if (!is_resource($this->fileHandle)) {
throw new WriterException('Could not open resource for writing.');
}

Expand Down

0 comments on commit 52025c5

Please sign in to comment.