Skip to content

Commit 441abf0

Browse files
committed
DataValidation Doesn't Need __construct nor __clone
Constructor does nothing. Class doesn't require deep clone since all properties are bool or string.
1 parent 6632117 commit 441abf0

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

src/PhpSpreadsheet/Cell/DataValidation.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ class DataValidation
9595
*/
9696
private string $prompt = '';
9797

98-
/**
99-
* Create a new DataValidation.
100-
*/
101-
public function __construct()
102-
{
103-
}
104-
10598
/**
10699
* Get Formula 1.
107100
*/
@@ -390,21 +383,6 @@ public function getHashCode(): string
390383
);
391384
}
392385

393-
/**
394-
* Implement PHP __clone to create a deep clone, not just a shallow copy.
395-
*/
396-
public function __clone()
397-
{
398-
$vars = get_object_vars($this);
399-
foreach ($vars as $key => $value) {
400-
if (is_object($value)) {
401-
$this->$key = clone $value;
402-
} else {
403-
$this->$key = $value;
404-
}
405-
}
406-
}
407-
408386
private ?string $sqref = null;
409387

410388
public function getSqref(): ?string

tests/PhpSpreadsheetTests/Cell/DataValidatorTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function testNoValidation(): void
1717
$testCell = $sheet->getCell('A1');
1818

1919
self::assertTrue($testCell->hasValidValue(), 'a cell without any validation data is always valid');
20+
$spreadsheet->disconnectWorksheets();
2021
}
2122

2223
public function testUnsupportedType(): void
@@ -30,6 +31,7 @@ public function testUnsupportedType(): void
3031
$validation->setAllowBlank(true);
3132

3233
self::assertFalse($testCell->hasValidValue(), 'cannot assert that value is valid when the validation type is not supported');
34+
$spreadsheet->disconnectWorksheets();
3335
}
3436

3537
public function testList(): void
@@ -71,5 +73,24 @@ public function testList(): void
7173
$validation->setFormula1('broken : cell : coordinates');
7274

7375
self::assertFalse($testCell->hasValidValue(), 'invalid formula should not throw exceptions');
76+
$spreadsheet->disconnectWorksheets();
77+
}
78+
79+
public function testInvalidNumeric(): void
80+
{
81+
$spreadsheet = new Spreadsheet();
82+
$sheet = $spreadsheet->getActiveSheet();
83+
84+
$validation = $sheet->getCell('A1')->getDataValidation();
85+
$validation->setType(DataValidation::TYPE_WHOLE)
86+
->setOperator(DataValidation::OPERATOR_EQUAL)
87+
->setFormula1('broken : cell : coordinates');
88+
$sheet->getCell('A1')->setValue(0);
89+
self::assertFalse($sheet->getCell('A1')->hasValidValue(), 'invalid formula should return false');
90+
$validation->setOperator('invalid operator')
91+
->setFormula1('0');
92+
self::assertFalse($sheet->getCell('A1')->hasValidValue(), 'invalid operator should return false');
93+
94+
$spreadsheet->disconnectWorksheets();
7495
}
7596
}

0 commit comments

Comments
 (0)