Skip to content

Commit 17706a9

Browse files
authored
Merge pull request #4310 from oleibman/issue4309
getStyle Accept RowRange or ColumnRange Using Phpstan
2 parents c58a8e3 + 77f3f17 commit 17706a9

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

src/PhpSpreadsheet/Worksheet/AutoFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setEvaluated(bool $value): void
5050
/**
5151
* Create a new AutoFilter.
5252
*
53-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
53+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
5454
* A simple string containing a Cell range like 'A1:E10' is permitted
5555
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
5656
* or an AddressRange object.

src/PhpSpreadsheet/Worksheet/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Table implements Stringable
6464
/**
6565
* Create a new Table.
6666
*
67-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
67+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
6868
* A simple string containing a Cell range like 'A1:E10' is permitted
6969
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
7070
* or an AddressRange object.
@@ -268,7 +268,7 @@ public function getRange(): string
268268
/**
269269
* Set Table Cell Range.
270270
*
271-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
271+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range
272272
* A simple string containing a Cell range like 'A1:E10' is permitted
273273
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
274274
* or an AddressRange object.

src/PhpSpreadsheet/Worksheet/Validations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function validateCellAddress(null|CellAddress|string|array $cellAd
3636
/**
3737
* Validate a cell address or cell range.
3838
*
39-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12';
39+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12';
4040
* or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]),
4141
* or as a CellAddress or AddressRange object.
4242
*/
@@ -59,7 +59,7 @@ public static function validateCellOrCellRange(AddressRange|CellAddress|int|stri
5959
/**
6060
* Validate a cell range.
6161
*
62-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12';
62+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12';
6363
* or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]),
6464
* or as an AddressRange object.
6565
*/

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ public function getStyles(): array
13891389
/**
13901390
* Get style for cell.
13911391
*
1392-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellCoordinate
1392+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellCoordinate
13931393
* A simple string containing a cell address like 'A1' or a cell range like 'A1:E10'
13941394
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
13951395
* or a CellAddress or AddressRange object.
@@ -1693,7 +1693,7 @@ public function getColumnBreaks(): array
16931693
/**
16941694
* Set merge on a cell range.
16951695
*
1696-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10'
1696+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10'
16971697
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
16981698
* or an AddressRange.
16991699
* @param string $behaviour How the merged cells should behave.
@@ -1818,7 +1818,7 @@ public function mergeCellBehaviour(Cell $cell, string $upperLeft, string $behavi
18181818
/**
18191819
* Remove merge on a cell range.
18201820
*
1821-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10'
1821+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10'
18221822
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
18231823
* or an AddressRange.
18241824
*
@@ -1869,7 +1869,7 @@ public function setMergeCells(array $mergeCells): static
18691869
/**
18701870
* Set protection on a cell or cell range.
18711871
*
1872-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10'
1872+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10'
18731873
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
18741874
* or a CellAddress or AddressRange object.
18751875
* @param string $password Password to unlock the protection
@@ -1892,7 +1892,7 @@ public function protectCells(AddressRange|CellAddress|int|string|array $range, s
18921892
/**
18931893
* Remove protection on a cell or cell range.
18941894
*
1895-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10'
1895+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10'
18961896
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
18971897
* or a CellAddress or AddressRange object.
18981898
*
@@ -1950,7 +1950,7 @@ public function getAutoFilter(): AutoFilter
19501950
/**
19511951
* Set AutoFilter.
19521952
*
1953-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|AutoFilter|string $autoFilterOrRange
1953+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|AutoFilter|string $autoFilterOrRange
19541954
* A simple string containing a Cell range like 'A1:E10' is permitted for backward compatibility
19551955
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
19561956
* or an AddressRange.
@@ -2696,7 +2696,7 @@ public function setSelectedCell(string $coordinate): static
26962696
/**
26972697
* Select a range of cells.
26982698
*
2699-
* @param AddressRange<CellAddress>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $coordinate A simple string containing a Cell range like 'A1:E10'
2699+
* @param AddressRange<CellAddress>|AddressRange<int>|AddressRange<string>|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $coordinate A simple string containing a Cell range like 'A1:E10'
27002700
* or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]),
27012701
* or a CellAddress or AddressRange object.
27022702
*

tests/PhpSpreadsheetTests/Cell/ColumnRangeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testCreateColumnRangeWithWorksheet(): void
4343
self::assertSame('E', $columnRange->to());
4444
self::assertSame("'Mark''s Worksheet'!C:E", (string) $columnRange);
4545
self::assertSame("'Mark''s Worksheet'!C1:E1048576", (string) $columnRange->toCellRange());
46+
$spreadsheet->disconnectWorksheets();
4647
}
4748

4849
public function testCreateColumnRangeFromArray(): void
@@ -88,4 +89,23 @@ public function testColumnRangePrevious(): void
8889
// Check that original Column Range isn't changed
8990
self::assertSame('C:E', (string) $columnRange);
9091
}
92+
93+
public function testIssue4309(): void
94+
{
95+
$spreadsheet = new Spreadsheet();
96+
$sheet = $spreadsheet->getActiveSheet();
97+
$columnRange = new ColumnRange('A', 'A');
98+
$columnStyle = $sheet->getStyle($columnRange);
99+
$columnStyle->applyFromArray([
100+
'font' => ['bold' => true],
101+
]);
102+
$columnXf = $sheet->getColumnDimension('A')->getXfIndex();
103+
self::assertNotNull($columnXf);
104+
self::assertTrue(
105+
$spreadsheet->getCellXfByIndex($columnXf)
106+
->getFont()->getBold()
107+
);
108+
109+
$spreadsheet->disconnectWorksheets();
110+
}
91111
}

tests/PhpSpreadsheetTests/Cell/RowRangeTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testCreateRowRangeWithWorksheet(): void
3939
self::assertSame(3, $rowRange->from());
4040
self::assertSame(5, $rowRange->to());
4141
self::assertSame("'Mark''s Worksheet'!3:5", (string) $rowRange);
42+
$spreadsheet->disconnectWorksheets();
4243
}
4344

4445
public function testCreateRowRangeFromArray(): void
@@ -74,4 +75,20 @@ public function testRowRangePrevious(): void
7475
// Check that original Row Range isn't changed
7576
self::assertSame('3:5', (string) $rowRange);
7677
}
78+
79+
public function testIssue4309(): void
80+
{
81+
$spreadsheet = new Spreadsheet();
82+
$sheet = $spreadsheet->getActiveSheet();
83+
$rowRange = new RowRange(1, 1);
84+
$rowStyle = $sheet->getStyle($rowRange);
85+
$rowStyle->applyFromArray([
86+
'font' => ['name' => 'Arial'],
87+
]);
88+
$rowXf = $sheet->getRowDimension(1)->getXfIndex();
89+
self::assertNotNull($rowXf);
90+
self::assertSame('Arial', $spreadsheet->getCellXfByIndex($rowXf)->getFont()->getName());
91+
92+
$spreadsheet->disconnectWorksheets();
93+
}
7794
}

0 commit comments

Comments
 (0)