From 46f2d448abcd8dc2e914bcca638dfe4332087e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 24 Feb 2022 16:43:37 +0100 Subject: [PATCH] Add typing to jsonSerialize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .github/workflows/lint.yml | 2 +- .github/workflows/phpunit.yml | 2 +- lib/Activity/ChangeSet.php | 10 +--------- lib/Db/Board.php | 2 +- lib/Db/Card.php | 6 +++--- lib/Db/RelationalEntity.php | 2 +- lib/Db/RelationalObject.php | 10 ++++++---- lib/Db/Stack.php | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f7cb8bfad..62ca06748 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php-versions: ['7.4', '8.0', "8.1"] + php-versions: ['7.4', '8.0', '8.1'] name: php${{ matrix.php-versions }} lint steps: diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bedac65bf..402263327 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', "8.1"] + php-versions: ['7.4', '8.0', '8.1'] databases: ['sqlite', 'mysql', 'pgsql'] server-versions: ['master'] diff --git a/lib/Activity/ChangeSet.php b/lib/Activity/ChangeSet.php index c4519c375..f491ecd1f 100644 --- a/lib/Activity/ChangeSet.php +++ b/lib/Activity/ChangeSet.php @@ -69,15 +69,7 @@ class ChangeSet implements \JsonSerializable { return $this->after; } - /** - * 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 json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'before' => $this->getBefore(), 'after' => $this->getAfter(), diff --git a/lib/Db/Board.php b/lib/Db/Board.php index 6cf3c3206..3b5bea9fe 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -58,7 +58,7 @@ class Board extends RelationalEntity { $this->shared = -1; } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); if ($this->shared === -1) { unset($json['shared']); diff --git a/lib/Db/Card.php b/lib/Db/Card.php index af2c665c5..caf97aae9 100644 --- a/lib/Db/Card.php +++ b/lib/Db/Card.php @@ -50,7 +50,7 @@ class Card extends RelationalEntity { protected $deletedAt = 0; protected $commentsUnread = 0; protected $commentsCount = 0; - + protected $relatedStack = null; protected $relatedBoard = null; @@ -78,7 +78,7 @@ class Card extends RelationalEntity { $this->addRelation('commentsUnread'); $this->addRelation('commentsCount'); $this->addResolvable('owner'); - + $this->addRelation('relatedStack'); $this->addRelation('relatedBoard'); } @@ -98,7 +98,7 @@ class Card extends RelationalEntity { return $dt->format('c'); } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); $json['overdue'] = self::DUEDATE_FUTURE; $due = strtotime($this->duedate); diff --git a/lib/Db/RelationalEntity.php b/lib/Db/RelationalEntity.php index c0b180c62..6e2a19ef5 100644 --- a/lib/Db/RelationalEntity.php +++ b/lib/Db/RelationalEntity.php @@ -63,7 +63,7 @@ class RelationalEntity extends Entity implements \JsonSerializable { * @return array serialized data * @throws \ReflectionException */ - public function jsonSerialize() { + public function jsonSerialize(): array { $properties = get_object_vars($this); $reflection = new \ReflectionClass($this); $json = []; diff --git a/lib/Db/RelationalObject.php b/lib/Db/RelationalObject.php index e9f0ed667..bd176e1b8 100644 --- a/lib/Db/RelationalObject.php +++ b/lib/Db/RelationalObject.php @@ -23,7 +23,9 @@ namespace OCA\Deck\Db; -class RelationalObject implements \JsonSerializable { +use JsonSerializable; + +class RelationalObject implements JsonSerializable { protected $primaryKey; protected $object; @@ -38,7 +40,7 @@ class RelationalObject implements \JsonSerializable { $this->object = $object; } - public function jsonSerialize() { + public function jsonSerialize(): array { return array_merge( ['primaryKey' => $this->primaryKey], $this->getObjectSerialization() @@ -51,8 +53,8 @@ class RelationalObject implements \JsonSerializable { * @throws \Exception */ public function getObjectSerialization() { - if ($this->object instanceof \JsonSerializable) { - $this->object->jsonSerialize(); + if ($this->object instanceof JsonSerializable) { + return $this->object->jsonSerialize(); } else { throw new \Exception('jsonSerialize is not implemented on ' . get_class($this)); } diff --git a/lib/Db/Stack.php b/lib/Db/Stack.php index c414f52a8..63e85ca03 100644 --- a/lib/Db/Stack.php +++ b/lib/Db/Stack.php @@ -45,7 +45,7 @@ class Stack extends RelationalEntity { $this->cards = $cards; } - public function jsonSerialize() { + public function jsonSerialize(): array { $json = parent::jsonSerialize(); if (empty($this->cards)) { unset($json['cards']);