Failed Conditions
Push — develop ( 11b055...32a55a )
by Adrien
30:13
created

AbstractFunctional::writeAndReload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Functional;
4
5
use PhpOffice\PhpSpreadsheet\IOFactory;
6
use PhpOffice\PhpSpreadsheet\Shared\File;
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Base class for functional test to write and reload file on disk across different formats.
12
 */
13
abstract class AbstractFunctional extends TestCase
14
{
15
    /**
16
     * Write spreadsheet to disk, reload and return it.
17
     *
18
     * @param Spreadsheet $spreadsheet
19
     * @param string $format
20
     *
21
     * @return Spreadsheet
22
     */
23
    protected function writeAndReload(Spreadsheet $spreadsheet, $format)
24
    {
25
        $filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
26
        $writer = IOFactory::createWriter($spreadsheet, $format);
27
        $writer->save($filename);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $pFilename of PhpOffice\PhpSpreadsheet\Writer\IWriter::save() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $writer->save(/** @scrutinizer ignore-type */ $filename);
Loading history...
28
29
        $reader = IOFactory::createReader($format);
30
        $reloadedSpreadsheet = $reader->load($filename);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $pFilename of PhpOffice\PhpSpreadsheet\Reader\IReader::load() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        $reloadedSpreadsheet = $reader->load(/** @scrutinizer ignore-type */ $filename);
Loading history...
31
        unlink($filename);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $filename of unlink() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        unlink(/** @scrutinizer ignore-type */ $filename);
Loading history...
32
33
        return $reloadedSpreadsheet;
34
    }
35
}
36