Skip to content

Commit

Permalink
Merge pull request #188 from odan/master
Browse files Browse the repository at this point in the history
Fix Error: debugInfo must return an array #164
  • Loading branch information
markstory authored Feb 11, 2019
2 parents 3951101 + 71d3a29 commit 8ee5ec5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
18 changes: 13 additions & 5 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
* @property-read bool $dst daylight savings time indicator, true if DST, false otherwise
* @property-read bool $local checks if the timezone is local, true if local, false otherwise
* @property-read bool $utc checks if the timezone is UTC, true if UTC, false otherwise
* @property-read string $timezoneName
* @property-read string $tzName
* @property-read string $timezoneName
* @property-read string $tzName
*/
class Chronos extends DateTimeImmutable implements ChronosInterface
{
Expand Down Expand Up @@ -190,12 +190,20 @@ public static function hasTestNow()
*/
public function __debugInfo()
{
$vars = get_object_vars($this);

$properties = [
'time' => $this->format('Y-m-d H:i:s.u'),
'timezone' => $this->getTimezone()->getName(),
'hasFixedNow' => self::hasTestNow()
'hasFixedNow' => static::hasTestNow(),
];

if (isset($vars['date'])) {
$properties['time'] = $this->format('Y-m-d H:i:s.u');
}

if (isset($vars['timezone'])) {
$properties['timezone'] = $this->getTimezone()->getName();
}

return $properties;
}
}
12 changes: 9 additions & 3 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

namespace Cake\Chronos;

use DateTimeImmutable;
Expand Down Expand Up @@ -44,8 +45,8 @@
* @property-read bool $dst daylight savings time indicator, true if DST, false otherwise
* @property-read bool $local checks if the timezone is local, true if local, false otherwise
* @property-read bool $utc checks if the timezone is UTC, true if UTC, false otherwise
* @property-read string $timezoneName
* @property-read string $tzName
* @property-read string $timezoneName
* @property-read string $tzName
*/
class Date extends DateTimeImmutable implements ChronosInterface
{
Expand Down Expand Up @@ -132,11 +133,16 @@ public function toMutable()
*/
public function __debugInfo()
{
$vars = get_object_vars($this);

$properties = [
'date' => $this->format('Y-m-d'),
'hasFixedNow' => static::hasTestNow(),
];

if (isset($vars['date'])) {
$properties['date'] = $this->format('Y-m-d');
}

return $properties;
}
}
13 changes: 9 additions & 4 deletions src/MutableDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
* @property-read bool $dst daylight savings time indicator, true if DST, false otherwise
* @property-read bool $local checks if the timezone is local, true if local, false otherwise
* @property-read bool $utc checks if the timezone is UTC, true if UTC, false otherwise
* @property-read string $timezoneName
* @property-read string $tzName
* @property-read string $timezoneName
* @property-read string $tzName
*/
class MutableDate extends DateTime implements ChronosInterface
{
Expand Down Expand Up @@ -132,11 +132,16 @@ public function toImmutable()
*/
public function __debugInfo()
{
$vars = get_object_vars($this);

$properties = [
'date' => $this->format('Y-m-d'),
'hasFixedNow' => static::hasTestNow()
'hasFixedNow' => static::hasTestNow(),
];

if (isset($vars['date'])) {
$properties['date'] = $this->format('Y-m-d');
}

return $properties;
}
}
16 changes: 12 additions & 4 deletions src/MutableDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
* @property-read bool $dst daylight savings time indicator, true if DST, false otherwise
* @property-read bool $local checks if the timezone is local, true if local, false otherwise
* @property-read bool $utc checks if the timezone is UTC, true if UTC, false otherwise
* @property-read string $timezoneName
* @property-read string $tzName
* @property-read string $timezoneName
* @property-read string $tzName
*/
class MutableDateTime extends DateTime implements ChronosInterface
{
Expand Down Expand Up @@ -175,12 +175,20 @@ public function __set($name, $value)
*/
public function __debugInfo()
{
$vars = get_object_vars($this);

$properties = [
'time' => $this->format('Y-m-d H:i:s.u'),
'timezone' => $this->getTimezone()->getName(),
'hasFixedNow' => static::hasTestNow(),
];

if (isset($vars['date'])) {
$properties['time'] = $this->format('Y-m-d H:i:s.u');
}

if (isset($vars['timezone'])) {
$properties['timezone'] = $this->getTimezone()->getName();
}

return $properties;
}
}

0 comments on commit 8ee5ec5

Please sign in to comment.