Add typing to jsonSerialize

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2022-02-24 16:43:37 +01:00
parent 9fa12f44ea
commit 46f2d448ab
8 changed files with 15 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ jobs:
strategy: strategy:
matrix: matrix:
php-versions: ['7.4', '8.0', "8.1"] php-versions: ['7.4', '8.0', '8.1']
name: php${{ matrix.php-versions }} lint name: php${{ matrix.php-versions }} lint
steps: steps:

View File

@@ -18,7 +18,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php-versions: ['7.4', '8.0', "8.1"] php-versions: ['7.4', '8.0', '8.1']
databases: ['sqlite', 'mysql', 'pgsql'] databases: ['sqlite', 'mysql', 'pgsql']
server-versions: ['master'] server-versions: ['master']

View File

@@ -69,15 +69,7 @@ class ChangeSet implements \JsonSerializable {
return $this->after; return $this->after;
} }
/** public function jsonSerialize(): array {
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize() {
return [ return [
'before' => $this->getBefore(), 'before' => $this->getBefore(),
'after' => $this->getAfter(), 'after' => $this->getAfter(),

View File

@@ -58,7 +58,7 @@ class Board extends RelationalEntity {
$this->shared = -1; $this->shared = -1;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
$json = parent::jsonSerialize(); $json = parent::jsonSerialize();
if ($this->shared === -1) { if ($this->shared === -1) {
unset($json['shared']); unset($json['shared']);

View File

@@ -50,7 +50,7 @@ class Card extends RelationalEntity {
protected $deletedAt = 0; protected $deletedAt = 0;
protected $commentsUnread = 0; protected $commentsUnread = 0;
protected $commentsCount = 0; protected $commentsCount = 0;
protected $relatedStack = null; protected $relatedStack = null;
protected $relatedBoard = null; protected $relatedBoard = null;
@@ -78,7 +78,7 @@ class Card extends RelationalEntity {
$this->addRelation('commentsUnread'); $this->addRelation('commentsUnread');
$this->addRelation('commentsCount'); $this->addRelation('commentsCount');
$this->addResolvable('owner'); $this->addResolvable('owner');
$this->addRelation('relatedStack'); $this->addRelation('relatedStack');
$this->addRelation('relatedBoard'); $this->addRelation('relatedBoard');
} }
@@ -98,7 +98,7 @@ class Card extends RelationalEntity {
return $dt->format('c'); return $dt->format('c');
} }
public function jsonSerialize() { public function jsonSerialize(): array {
$json = parent::jsonSerialize(); $json = parent::jsonSerialize();
$json['overdue'] = self::DUEDATE_FUTURE; $json['overdue'] = self::DUEDATE_FUTURE;
$due = strtotime($this->duedate); $due = strtotime($this->duedate);

View File

@@ -63,7 +63,7 @@ class RelationalEntity extends Entity implements \JsonSerializable {
* @return array serialized data * @return array serialized data
* @throws \ReflectionException * @throws \ReflectionException
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
$properties = get_object_vars($this); $properties = get_object_vars($this);
$reflection = new \ReflectionClass($this); $reflection = new \ReflectionClass($this);
$json = []; $json = [];

View File

@@ -23,7 +23,9 @@
namespace OCA\Deck\Db; namespace OCA\Deck\Db;
class RelationalObject implements \JsonSerializable { use JsonSerializable;
class RelationalObject implements JsonSerializable {
protected $primaryKey; protected $primaryKey;
protected $object; protected $object;
@@ -38,7 +40,7 @@ class RelationalObject implements \JsonSerializable {
$this->object = $object; $this->object = $object;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return array_merge( return array_merge(
['primaryKey' => $this->primaryKey], ['primaryKey' => $this->primaryKey],
$this->getObjectSerialization() $this->getObjectSerialization()
@@ -51,8 +53,8 @@ class RelationalObject implements \JsonSerializable {
* @throws \Exception * @throws \Exception
*/ */
public function getObjectSerialization() { public function getObjectSerialization() {
if ($this->object instanceof \JsonSerializable) { if ($this->object instanceof JsonSerializable) {
$this->object->jsonSerialize(); return $this->object->jsonSerialize();
} else { } else {
throw new \Exception('jsonSerialize is not implemented on ' . get_class($this)); throw new \Exception('jsonSerialize is not implemented on ' . get_class($this));
} }

View File

@@ -45,7 +45,7 @@ class Stack extends RelationalEntity {
$this->cards = $cards; $this->cards = $cards;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
$json = parent::jsonSerialize(); $json = parent::jsonSerialize();
if (empty($this->cards)) { if (empty($this->cards)) {
unset($json['cards']); unset($json['cards']);