Early bail out if resource cannot be opened

This commit is contained in:
Adrien Crivelli 2020-05-16 18:08:10 +09:00
parent b60b1d25c0
commit 9cdbddf3bf
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 13 additions and 7 deletions

View File

@ -33,7 +33,7 @@ class Ods extends BaseWriter
private $spreadSheet; private $spreadSheet;
/** /**
* @var bool|resource * @var resource
*/ */
private $fileHandle; private $fileHandle;
@ -105,7 +105,12 @@ class Ods extends BaseWriter
} }
} }
$this->fileHandle = fopen($pFilename, 'wb+'); $fileHandle = fopen($pFilename, 'wb+');
if ($fileHandle === false) {
throw new WriterException('Could not open file ' . $pFilename . ' for writing.');
}
$this->fileHandle = $fileHandle;
} }
$zip = $this->createZip(); $zip = $this->createZip();

View File

@ -108,7 +108,7 @@ class Xlsx extends BaseWriter
private $drawingHashTable; private $drawingHashTable;
/** /**
* @var bool|resource * @var resource
*/ */
private $fileHandle; private $fileHandle;
@ -196,11 +196,12 @@ class Xlsx extends BaseWriter
} }
} }
$this->fileHandle = fopen($pFilename, 'wb+'); $fileHandle = fopen($pFilename, 'wb+');
} if ($fileHandle === false) {
throw new WriterException('Could not open file ' . $pFilename . ' for writing.');
}
if (!is_resource($this->fileHandle)) { $this->fileHandle = $fileHandle;
throw new WriterException('Could not open resource for writing.');
} }
$saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); $saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog();