Skip to content

Commit

Permalink
Add return types to jsonSerialize to suppress deprecation message. (#507
Browse files Browse the repository at this point in the history
)

* Add return types to jsonSerialize to surpress deprecation message.   Fixes issue #506.

* Fix pre-existing style issue, rewrite if block with empty body.  Fixes issue #506.

---------

Co-authored-by: Marc Runkel <[email protected]>
  • Loading branch information
mrunkel and mrunkel authored Apr 16, 2023
1 parent db4ef1f commit 5fe666f
Show file tree
Hide file tree
Showing 42 changed files with 51 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/Auth/AuthSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AuthSession implements \JsonSerializable
public $loginInfo;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CurrentUser implements \JsonSerializable
public $loginInfo;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/LoginInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LoginInfo implements \JsonSerializable
public $previousLoginTime;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/SessionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SessionInfo implements \JsonSerializable
public $value;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Board/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getLocation()
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
Expand Down
2 changes: 1 addition & 1 deletion src/Board/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getName()
* {@inheritdoc}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
Expand Down
6 changes: 2 additions & 4 deletions src/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ public function setProject(string $project): static
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
$vars = array_filter(get_object_vars($this), function ($var) {
return array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
});

return $vars;
}
}
2 changes: 1 addition & 1 deletion src/Field/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setSearcherKey(string $searcherKey)
public $schema;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Group implements \JsonSerializable
public $expand;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Group/GroupSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GroupSearchResult implements \JsonSerializable
public $values;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Attachment implements \JsonSerializable
public $thumbnail;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/ChangeLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ChangeLog implements \JsonSerializable
public $histories;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setBody($body)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Comments implements \JsonSerializable
public $comments;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct($name = null)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/ContentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/CustomFieldUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct()
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class History implements \JsonSerializable
public $items;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Issue implements \JsonSerializable
public ?ChangeLog $changelog;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
12 changes: 5 additions & 7 deletions src/Issue/IssueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function __construct($updateIssue = false)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): mixed
{
$vars = array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
Expand All @@ -120,12 +120,10 @@ public function jsonSerialize()
// if assignee property has empty value then remove it.
// @see https:/lesstif/php-jira-rest-client/issues/126
// @see https:/lesstif/php-jira-rest-client/issues/177
if (!empty($this->assignee)) {
// do nothing
if ($this->assignee->isWantUnassigned() === true) {
} elseif ($this->assignee->isEmpty()) {
unset($vars['assignee']);
}
if (!empty($this->assignee) &&
$this->assignee->isWantUnassigned() !== true &&
$this->assignee->isEmpty()) {
unset($vars['assignee']);
}

// clear undefined json property
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/IssueStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IssueStatus implements \JsonSerializable
public $statuscategory;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/IssueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IssueType implements \JsonSerializable
public int $hierarchyLevel;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function setRestrictPermission($id, $key)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Priority implements \JsonSerializable
public $description;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/RemoteIssueLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RemoteIssueLink implements \JsonSerializable
public $object;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Issue/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Reporter implements \JsonSerializable
public string $accountType;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): ?array
{
$vars = (get_object_vars($this));
$vars = get_object_vars($this);

foreach ($vars as $key => $value) {
if ($key === 'name' && ($this->isWantUnassigned() === true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/SecurityScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SecurityScheme implements \JsonSerializable
public $levels;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Issue/TimeTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ public function setTimeSpentSeconds($timeSpentSeconds)
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*
* @return mixed data which can be serialized by <b>json_encode</b>,
* @return array data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Transition.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function setCommentBody($commentBody)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct($name = null)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/VersionIssueCounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/VersionUnresolvedCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class VersionUnresolvedCount implements \JsonSerializable
public $issuesUnresolvedCount;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getValue(): string
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Worklog.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Worklog
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
6 changes: 2 additions & 4 deletions src/IssueLink/IssueLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ class IssueLink implements \JsonSerializable
public $comment;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
$vars = array_filter(get_object_vars($this));

return $vars;
return array_filter(get_object_vars($this));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/IssueLink/IssueLinkType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class IssueLinkType implements \JsonSerializable
public $self;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
$vars = array_filter(get_object_vars($this));

return $vars;
return array_filter(get_object_vars($this));
}
}
2 changes: 1 addition & 1 deletion src/JsonSerializableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
trait JsonSerializableTrait
{
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Project implements \JsonSerializable
public bool $archived;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): mixed
{
$params = array_filter(get_object_vars($this), function ($var) {
return !is_null($var);
Expand Down
2 changes: 1 addition & 1 deletion src/Request/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Author implements \JsonSerializable
public $timeZone;

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Request/RequestComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setIsPublic(bool $public)
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_filter(get_object_vars($this), function ($var) {
return $var !== null;
Expand Down
Loading

0 comments on commit 5fe666f

Please sign in to comment.