Skip to content

Commit

Permalink
Support DateTimeImmutable as cell value
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Dec 23, 2017
1 parent 6f76306 commit fb5f8d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpOffice\PhpSpreadsheet\Cell;

use DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Cell/IValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface IValueBinder
*
* @return bool
*/
public function bindValue(Cell $cell, $value = null);
public function bindValue(Cell $cell, $value);
}
6 changes: 4 additions & 2 deletions tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,9 +12,9 @@

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)
Expand Down Expand Up @@ -53,6 +54,7 @@ public function binderProvider()
['-123.456'],
['#REF!'],
[new DateTime()],
[new DateTimeImmutable()],
];
}

Expand Down

0 comments on commit fb5f8d4

Please sign in to comment.