Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Passed to AutoFilter SetRange #2454

Merged
merged 3 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6065,16 +6065,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php

-
message: "#^Parameter \\#1 \\$range of class PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter constructor expects string, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php

-
message: "#^Parameter \\#1 \\$range of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\:\\:setRange\\(\\) expects string, null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php

-
message: "#^Parameter \\#1 \\$range of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:rangeDimension\\(\\) expects string, string\\|false given\\.$#"
count: 1
Expand Down
12 changes: 3 additions & 9 deletions src/PhpSpreadsheet/Worksheet/AutoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public function setEvaluated(bool $value): void

/**
* Create a new AutoFilter.
*
* @param string $range Cell range (i.e. A1:E10)
*/
public function __construct($range = '', ?Worksheet $worksheet = null)
public function __construct(string $range = '', ?Worksheet $worksheet = null)
{
$this->range = $range;
$this->workSheet = $worksheet;
Expand Down Expand Up @@ -93,13 +91,9 @@ public function getRange()
}

/**
* Set AutoFilter Range.
*
* @param string $range Cell range (i.e. A1:E10)
*
* @return $this
* Set AutoFilter Cell Range.
*/
public function setRange($range)
public function setRange(string $range): self
{
$this->evaluated = false;
// extract coordinate
Expand Down
8 changes: 3 additions & 5 deletions src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public function __construct(?Spreadsheet $parent = null, $title = 'Worksheet')
$this->defaultRowDimension = new RowDimension(null);
// Default column dimension
$this->defaultColumnDimension = new ColumnDimension(null);
$this->autoFilter = new AutoFilter(null, $this);
$this->autoFilter = new AutoFilter('', $this);
}

/**
Expand Down Expand Up @@ -1914,12 +1914,10 @@ public function setAutoFilterByColumnAndRow($columnIndex1, $row1, $columnIndex2,

/**
* Remove autofilter.
*
* @return $this
*/
public function removeAutoFilter()
public function removeAutoFilter(): self
{
$this->autoFilter->setRange(null);
$this->autoFilter->setRange('');

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter;

class DeleteAutoFilterTest extends SetupTeardown
{
public function testDelete(): void
{
// Issue 2281 - deprecation in PHP81 when deleting filter
$sheet = $this->getSheet();
$autoFilter = $sheet->getAutoFilter();
$autoFilter->setRange('H2:O256');
$sheet->removeAutoFilter();
self::assertSame('', $sheet->getAutoFilter()->getRange());
}
}