From 441abf05d5c340466ce9e39eb061c950c4a79c95 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:51:02 -0800 Subject: [PATCH] DataValidation Doesn't Need __construct nor __clone Constructor does nothing. Class doesn't require deep clone since all properties are bool or string. --- src/PhpSpreadsheet/Cell/DataValidation.php | 22 ------------------- .../Cell/DataValidatorTest.php | 21 ++++++++++++++++++ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/DataValidation.php b/src/PhpSpreadsheet/Cell/DataValidation.php index 9a5f44e346..a21c30c803 100644 --- a/src/PhpSpreadsheet/Cell/DataValidation.php +++ b/src/PhpSpreadsheet/Cell/DataValidation.php @@ -95,13 +95,6 @@ class DataValidation */ private string $prompt = ''; - /** - * Create a new DataValidation. - */ - public function __construct() - { - } - /** * Get Formula 1. */ @@ -390,21 +383,6 @@ public function getHashCode(): string ); } - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() - { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value)) { - $this->$key = clone $value; - } else { - $this->$key = $value; - } - } - } - private ?string $sqref = null; public function getSqref(): ?string diff --git a/tests/PhpSpreadsheetTests/Cell/DataValidatorTest.php b/tests/PhpSpreadsheetTests/Cell/DataValidatorTest.php index 6792197101..680ce8e5e5 100644 --- a/tests/PhpSpreadsheetTests/Cell/DataValidatorTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DataValidatorTest.php @@ -17,6 +17,7 @@ public function testNoValidation(): void $testCell = $sheet->getCell('A1'); self::assertTrue($testCell->hasValidValue(), 'a cell without any validation data is always valid'); + $spreadsheet->disconnectWorksheets(); } public function testUnsupportedType(): void @@ -30,6 +31,7 @@ public function testUnsupportedType(): void $validation->setAllowBlank(true); self::assertFalse($testCell->hasValidValue(), 'cannot assert that value is valid when the validation type is not supported'); + $spreadsheet->disconnectWorksheets(); } public function testList(): void @@ -71,5 +73,24 @@ public function testList(): void $validation->setFormula1('broken : cell : coordinates'); self::assertFalse($testCell->hasValidValue(), 'invalid formula should not throw exceptions'); + $spreadsheet->disconnectWorksheets(); + } + + public function testInvalidNumeric(): void + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + $validation = $sheet->getCell('A1')->getDataValidation(); + $validation->setType(DataValidation::TYPE_WHOLE) + ->setOperator(DataValidation::OPERATOR_EQUAL) + ->setFormula1('broken : cell : coordinates'); + $sheet->getCell('A1')->setValue(0); + self::assertFalse($sheet->getCell('A1')->hasValidValue(), 'invalid formula should return false'); + $validation->setOperator('invalid operator') + ->setFormula1('0'); + self::assertFalse($sheet->getCell('A1')->hasValidValue(), 'invalid operator should return false'); + + $spreadsheet->disconnectWorksheets(); } }