From fb5f8d4763962f1c464b44b2788871903edc43ed Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sat, 23 Dec 2017 21:50:07 +0900 Subject: [PATCH] Support DateTimeImmutable as cell value --- src/PhpSpreadsheet/Cell/DefaultValueBinder.php | 6 +++--- src/PhpSpreadsheet/Cell/IValueBinder.php | 2 +- tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php index 208025b5..0e35ae2f 100644 --- a/src/PhpSpreadsheet/Cell/DefaultValueBinder.php +++ b/src/PhpSpreadsheet/Cell/DefaultValueBinder.php @@ -2,7 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Cell; -use DateTime; +use DateTimeInterface; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; @@ -16,14 +16,14 @@ class DefaultValueBinder implements IValueBinder * * @return bool */ - public function bindValue(Cell $cell, $value = null) + public function bindValue(Cell $cell, $value) { // sanitize UTF-8 strings if (is_string($value)) { $value = StringHelper::sanitizeUTF8($value); } elseif (is_object($value)) { // Handle any objects that might be injected - if ($value instanceof DateTime) { + if ($value instanceof DateTimeInterface) { $value = $value->format('Y-m-d H:i:s'); } elseif (!($value instanceof RichText)) { $value = (string) $value; diff --git a/src/PhpSpreadsheet/Cell/IValueBinder.php b/src/PhpSpreadsheet/Cell/IValueBinder.php index 5db3530e..5af9f5f6 100644 --- a/src/PhpSpreadsheet/Cell/IValueBinder.php +++ b/src/PhpSpreadsheet/Cell/IValueBinder.php @@ -12,5 +12,5 @@ interface IValueBinder * * @return bool */ - public function bindValue(Cell $cell, $value = null); + public function bindValue(Cell $cell, $value); } diff --git a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php index 0bc16e86..356a7212 100644 --- a/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php @@ -3,6 +3,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; use DateTime; +use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; @@ -11,9 +12,9 @@ use PHPUnit\Framework\TestCase; class DefaultValueBinderTest extends TestCase { - protected $cellStub; + private $cellStub; - protected function createCellStub() + private function createCellStub() { // Create a stub for the Cell class. $this->cellStub = $this->getMockBuilder(Cell::class) @@ -53,6 +54,7 @@ class DefaultValueBinderTest extends TestCase ['-123.456'], ['#REF!'], [new DateTime()], + [new DateTimeImmutable()], ]; }