Passed
Pull Request — master (#4360)
by Owen
12:29
created

ApostropheTest::testApostropheInSheetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 44
c 2
b 0
f 0
dl 0
loc 53
rs 9.216
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
6
7
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
8
use PhpOffice\PhpSpreadsheet\NamedRange;
9
use PhpOffice\PhpSpreadsheet\Spreadsheet;
10
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
11
12
class ApostropheTest extends AbstractFunctional
13
{
14
    public function testApostropheInSheetName(): void
15
    {
16
        $spreadsheet = new Spreadsheet();
17
        Calculation::getInstance($spreadsheet)
18
            ->setInstanceArrayReturnType(
19
                Calculation::RETURN_ARRAY_AS_ARRAY
20
            );
21
        $sheet = $spreadsheet->getActiveSheet();
22
        $sheet->setTitle('sheet1');
23
        $sheet->getCell('A1')->setValue(1);
24
        $sheet->getCell('A2')->setValue(2);
25
        $sheet->getCell('A3')->setValue(3);
26
        $sheet->getCell('A4')->setValue(4);
27
        $spreadsheet->addNamedRange(new NamedRange('sheet14cells', $sheet, '$A$1:$A$4'));
28
        $sheet->getCell('C1')
29
            ->setValue('=sheet14cells*sheet14cells');
30
        $sheet->getCell('E1')->setValue('=ANCHORARRAY(sheet1!C1)');
31
        $sheet->getCell('G1')->setValue('=SINGLE(sheet1!C1:C4)');
32
33
        $sheet1 = $spreadsheet->createSheet();
34
        $sheet1->setTitle("Apo'strophe");
35
        $sheet1->getCell('A1')->setValue(2);
36
        $sheet1->getCell('A2')->setValue(3);
37
        $sheet1->getCell('A3')->setValue(4);
38
        $sheet1->getCell('A4')->setValue(5);
39
        $spreadsheet->addNamedRange(new NamedRange('sheet24cells', $sheet1, '$A$1:$A$4'));
40
        $sheet1->getCell('C1')
41
            ->setValue('=sheet24cells*sheet24cells');
42
        $sheet1->getCell('E1')->setValue("=ANCHORARRAY('Apo''strophe'!C1)");
43
        $sheet1->getCell('G1')->setValue("=SINGLE('Apo''strophe'!C1:C4)");
44
45
        $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
46
        $spreadsheet->disconnectWorksheets();
47
        Calculation::getInstance($reloadedSpreadsheet)
48
            ->setInstanceArrayReturnType(
49
                Calculation::RETURN_ARRAY_AS_ARRAY
50
            );
51
        $rsheet = $reloadedSpreadsheet->getSheet(0);
52
        // make sure results aren't from cache
53
        $rsheet->getCell('E1')->setCalculatedValue(-1);
54
        $rsheet->getCell('G1')->setCalculatedValue(-1);
55
        self::assertSame([[1], [4], [9], [16]], $rsheet->getCell('C1')->getCalculatedValue());
56
        self::assertSame([[1], [4], [9], [16]], $rsheet->getCell('E1')->getCalculatedValue());
57
        self::assertSame(1, $rsheet->getCell('G1')->getCalculatedValue());
58
59
        $rsheet1 = $reloadedSpreadsheet->getSheet(1);
60
        // make sure results aren't from cache
61
        $rsheet1->getCell('E1')->setCalculatedValue(-1);
62
        $rsheet1->getCell('G1')->setCalculatedValue(-1);
63
        self::assertSame([[4], [9], [16], [25]], $rsheet1->getCell('C1')->getCalculatedValue());
64
        self::assertSame([[4], [9], [16], [25]], $rsheet1->getCell('E1')->getCalculatedValue());
65
        self::assertSame(4, $rsheet1->getCell('G1')->getCalculatedValue());
66
        $reloadedSpreadsheet->disconnectWorksheets();
67
    }
68
}
69