Failed Conditions
Push — develop ( eb5856...11b055 )
by Adrien
31:22
created

XlsxTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 65.71 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 35
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadXlsxWithoutCellReference() 0 5 1
A testFreezePane() 23 23 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx;
6
use PhpOffice\PhpSpreadsheet\Shared\File;
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as WriterXlsx;
9
use PHPUnit\Framework\TestCase;
10
11
class XlsxTest extends TestCase
12
{
13
    /**
14
     * Test load Xlsx file without cell reference.
15
     */
16
    public function testLoadXlsxWithoutCellReference()
17
    {
18
        $filename = './data/Reader/XLSX/without_cell_reference.xlsx';
19
        $reader = new ReaderXlsx();
20
        $reader->load($filename);
21
    }
22
23 View Code Duplication
    public function testFreezePane()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet');
26
27
        $cellSplit = 'B2';
28
        $topLeftCell = 'E5';
29
30
        $spreadsheet = new Spreadsheet();
31
        $active = $spreadsheet->getActiveSheet();
32
        $active->freezePane($cellSplit, $topLeftCell);
33
34
        $writer = new WriterXlsx($spreadsheet);
35
        $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\Xlsx::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

35
        $writer->save(/** @scrutinizer ignore-type */ $filename);
Loading history...
36
37
        // Read written file
38
        $reader = new ReaderXlsx();
39
        $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\Xlsx::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

39
        $reloadedSpreadsheet = $reader->load(/** @scrutinizer ignore-type */ $filename);
Loading history...
40
        $reloadedActive = $reloadedSpreadsheet->getActiveSheet();
41
        $actualCellSplit = $reloadedActive->getFreezePane();
42
        $actualTopLeftCell = $reloadedActive->getTopLeftCell();
43
44
        self::assertSame($cellSplit, $actualCellSplit, 'should be able to set freeze pane');
45
        self::assertSame($topLeftCell, $actualTopLeftCell, 'should be able to set the top left cell');
46
    }
47
}
48