From a7616cf62737873cc7c41d8652a537c4b055329b Mon Sep 17 00:00:00 2001 From: Tomasz Durda Date: Mon, 28 Nov 2022 18:03:10 +0100 Subject: [PATCH] PHP 8.1 compatibility --- composer.json | 2 +- src/PrintNode/Entity.php | 2 +- src/PrintNode/EntityDynamic.php | 42 ++++++++++++++++----------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index b5784b8..4a56257 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "printnode/printnode-php", "description": "Connect any printer to your application with PrintNode Client and easy to use JSON API", "require": { - "php": ">=5.3.2", + "php": ">=7.0", "ext-curl": "*" }, "keywords": [ diff --git a/src/PrintNode/Entity.php b/src/PrintNode/Entity.php index 1a71c51..8782bea 100755 --- a/src/PrintNode/Entity.php +++ b/src/PrintNode/Entity.php @@ -102,7 +102,7 @@ public function mapValuesFromJson($json) * * @return string */ - public function jsonSerialize() + public function jsonSerialize(): mixed { $json = array(); diff --git a/src/PrintNode/EntityDynamic.php b/src/PrintNode/EntityDynamic.php index af474eb..7820c0d 100644 --- a/src/PrintNode/EntityDynamic.php +++ b/src/PrintNode/EntityDynamic.php @@ -4,7 +4,7 @@ abstract class EntityDynamic extends Entity { - + /** * Reference to the client * @var Client @@ -12,7 +12,7 @@ abstract class EntityDynamic extends Entity protected static $protectedProperties = array( 'client', ); - + /** * Set property on entity * @param mixed $propertyName @@ -21,15 +21,15 @@ abstract class EntityDynamic extends Entity */ public function __set($propertyName, $value) { - + if (\in_array($propertyName, self::$protectedProperties)) { throw new \PrintNode\Exception\InvalidArgumentException($propertyName . ' is a protected property.'); } - + $this->$propertyName = $value; - + } - + /** * Maps a json object to this entity * @@ -38,41 +38,41 @@ public function __set($propertyName, $value) */ public function mapValuesFromJson($json) { - + foreach ($json as $key => $value) { $this->$key = $value; } - + return true; - + } - + /** * Implements the jsonSerialize method * * @return string */ - public function jsonSerialize() + public function jsonSerialize(): mixed { - + $refClass = new \ReflectionClass($this); - + $properties = get_object_vars($this); - + $json = array(); - + foreach ($properties as $property => $value) { - + if (in_array($property, self::$protectedProperties)) { continue; } - + $json[$property] = $value; - + } - + return $json; - + } - + } \ No newline at end of file