From f9fabe838a4bc1001c4ff8e9ebe75af7b7873837 Mon Sep 17 00:00:00 2001 From: Lukas Rosenstock Date: Fri, 19 Jun 2026 08:28:06 +0000 Subject: [PATCH] Use ? to mark parameters as nullable to prevent PHP 8.4 deprecation warning --- .../SDK/AccountGateway/AccountContext.php | 2 +- CloudObjects/SDK/CloudObject.php | 12 +++---- CloudObjects/SDK/Common/CryptoHelper.php | 2 +- CloudObjects/SDK/NodeReader.php | 36 +++++++++---------- CloudObjects/SDK/WebAPI/APIClientFactory.php | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CloudObjects/SDK/AccountGateway/AccountContext.php b/CloudObjects/SDK/AccountGateway/AccountContext.php index ffcca72..10cc5fd 100644 --- a/CloudObjects/SDK/AccountGateway/AccountContext.php +++ b/CloudObjects/SDK/AccountGateway/AccountContext.php @@ -40,7 +40,7 @@ class AccountContext { /** * Create a new context using an AAUID and an OAuth 2.0 bearer access token. */ - public function __construct(IRI $aauid, $accessToken, DataLoader $dataLoader = null) { + public function __construct(IRI $aauid, $accessToken, ?DataLoader $dataLoader = null) { if (AAUIDParser::getType($aauid) != AAUIDParser::AAUID_ACCOUNT) throw new \Exception("Not a valid AAUID"); diff --git a/CloudObjects/SDK/CloudObject.php b/CloudObjects/SDK/CloudObject.php index a9f25d0..1725b16 100644 --- a/CloudObjects/SDK/CloudObject.php +++ b/CloudObjects/SDK/CloudObject.php @@ -85,7 +85,7 @@ class CloudObject { * Get the value of a property as a string. * If the property has multiple values, only the first is returned. */ - public function getString($property, string $default = null) : ?string { + public function getString($property, ?string $default = null) : ?string { return $this->getReader()->getFirstValueString($this->node, $property, $default); } @@ -93,7 +93,7 @@ class CloudObject { * Get the value of a property as an integer. * If the property has multiple values, only the first is returned. */ - public function getInt($property, int $default = null) : ?int { + public function getInt($property, ?int $default = null) : ?int { return $this->getReader()->getFirstValueInt($this->node, $property, $default); } @@ -101,7 +101,7 @@ class CloudObject { * Get the value of a property as a float. * If the property has multiple values, only the first is returned. */ - public function getFloat($property, float $default = null) : ?float { + public function getFloat($property, ?float $default = null) : ?float { return $this->getReader()->getFirstValueFloat($this->node, $property, $default); } @@ -109,7 +109,7 @@ class CloudObject { * Get the value of a property as a boolean. * If the property has multiple values, only the first is returned. */ - public function getBool($property, bool $default = null) : ?bool { + public function getBool($property, ?bool $default = null) : ?bool { return $this->getReader()->getFirstValueBool($this->node, $property, $default); } @@ -117,7 +117,7 @@ class CloudObject { * Get the value of a property as an IRI. * If the property has multiple values, only the first is returned. */ - public function getIRI($property, IRI $default = null) : ?IRI { + public function getIRI($property, ?IRI $default = null) : ?IRI { return $this->getReader()->getFirstValueIRI($this->node, $property, $default); } @@ -125,7 +125,7 @@ class CloudObject { * Get the value of a property as a Node. * If the property has multiple values, only the first is returned. */ - public function getNode($property, Node $default = null) : ?Node { + public function getNode($property, ?Node $default = null) : ?Node { return $this->getReader()->getFirstValueNode($this->node, $property, $default); } diff --git a/CloudObjects/SDK/Common/CryptoHelper.php b/CloudObjects/SDK/Common/CryptoHelper.php index 32bcdaf..49af6e6 100644 --- a/CloudObjects/SDK/Common/CryptoHelper.php +++ b/CloudObjects/SDK/Common/CryptoHelper.php @@ -53,7 +53,7 @@ class CryptoHelper { * @param ObjectRetriever $objectRetriever An initialized and authenticated object retriever. * @param IRI|null $namespaceCoid The namespace used to retrieve keys. If this parameter is not provided, the namespace provided with the "auth_ns" configuration option from the object retriever is used. */ - public function __construct(ObjectRetriever $objectRetriever, IRI $namespaceCoid = null) { + public function __construct(ObjectRetriever $objectRetriever, ?IRI $namespaceCoid = null) { if (!class_exists('Defuse\Crypto\Crypto')) throw new Exception("Run composer require defuse/php-encryption before using CryptoHelper."); diff --git a/CloudObjects/SDK/NodeReader.php b/CloudObjects/SDK/NodeReader.php index f4393b9..a5201f2 100644 --- a/CloudObjects/SDK/NodeReader.php +++ b/CloudObjects/SDK/NodeReader.php @@ -38,7 +38,7 @@ class NodeReader { * @param string|object $type The type to check for. * @return boolean */ - public function hasType(Node $node = null, $type) { + public function hasType(?Node $node = null, $type) { if (!isset($node)) return false; $type = $this->expand($type); @@ -60,7 +60,7 @@ class NodeReader { return false; } - private function getFirstValue(Node $node = null, $property, $default = null) { + private function getFirstValue(?Node $node = null, $property, $default = null) { if (!isset($node)) return $default; $valueFromNode = $node->getProperty($this->expand($property)); @@ -82,7 +82,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return string|null */ - public function getFirstValueString(Node $node = null, $property, $default = null) { + public function getFirstValueString(?Node $node = null, $property, $default = null) { $valueFromNode = $this->getFirstValue($node, $property, $default); if ($valueFromNode == $default) return $default; @@ -103,7 +103,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return bool|null */ - public function getFirstValueBool(Node $node = null, $property, $default = null) { + public function getFirstValueBool(?Node $node = null, $property, $default = null) { return (in_array( $this->getFirstValueString($node, $property, $default), [ '1', 'true' ] @@ -120,7 +120,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return int|null */ - public function getFirstValueInt(Node $node = null, $property, $default = null) { + public function getFirstValueInt(?Node $node = null, $property, $default = null) { $value = $this->getFirstValueString($node, $property); if (is_numeric($value)) return (int)($value); @@ -138,7 +138,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return float|null */ - public function getFirstValueFloat(Node $node = null, $property, $default = null) { + public function getFirstValueFloat(?Node $node = null, $property, $default = null) { $value = $this->getFirstValueString($node, $property); if (is_numeric($value)) return (float)($value); @@ -156,7 +156,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return string|null */ - public function getFirstValueIRI(Node $node = null, $property, IRI $default = null) { + public function getFirstValueIRI(?Node $node = null, $property, ?IRI $default = null) { $valueFromNode = $this->getFirstValue($node, $property, $default); if ($valueFromNode == $default) return $default; @@ -177,7 +177,7 @@ class NodeReader { * @param $default The default that is returned if no value for the property exists on the node. * @return string|null */ - public function getFirstValueNode(Node $node = null, $property, Node $default = null) { + public function getFirstValueNode(?Node $node = null, $property, ?Node $default = null) { $valueFromNode = $this->getFirstValue($node, $property, $default); if ($valueFromNode == $default) return $default; @@ -196,7 +196,7 @@ class NodeReader { * @param string|object $value The expected value. * @return boolean */ - public function hasPropertyValue(Node $node = null, $property, $value) { + public function hasPropertyValue(?Node $node = null, $property, $value) { if (!isset($node)) return false; $valuesFromNode = $node->getProperty($this->expand($property)); @@ -225,14 +225,14 @@ class NodeReader { * @param string|object $property The property to read. * @return boolean */ - public function hasProperty(Node $node = null, $property) { + public function hasProperty(?Node $node = null, $property) { if (!isset($node)) return false; return ($node->getProperty($this->expand($property)) != null); } - private function getAllValues(Node $node = null, $property) { + private function getAllValues(?Node $node = null, $property) { if (!isset($node)) return []; @@ -248,7 +248,7 @@ class NodeReader { * Get the language-tagged-string for the property in the specified language. * If no value is found for the specified language, the default is returned. */ - public function getLocalizedString(Node $node = null, $property, $language, $default = null) { + public function getLocalizedString(?Node $node = null, $property, $language, $default = null) { $values = $this->getAllValues($node, $property); foreach ($values as $v) { if (is_a($v, 'ML\JsonLD\LanguageTaggedString') && $v->getLanguage() == $language) @@ -265,7 +265,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesString(Node $node = null, $property) { + public function getAllValuesString(?Node $node = null, $property) { $allValues = $this->getAllValues($node, $property); $output = []; foreach ($allValues as $a) @@ -284,7 +284,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesBool(Node $node = null, $property) { + public function getAllValuesBool(?Node $node = null, $property) { $allValues = $this->getAllValuesString($node, $property); $output = []; foreach ($allValues as $a) @@ -300,7 +300,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesInt(Node $node = null, $property) { + public function getAllValuesInt(?Node $node = null, $property) { $allValues = $this->getAllValuesString($node, $property); $output = []; foreach ($allValues as $a) @@ -316,7 +316,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesFloat(Node $node = null, $property) { + public function getAllValuesFloat(?Node $node = null, $property) { $allValues = $this->getAllValuesString($node, $property); $output = []; foreach ($allValues as $a) @@ -333,7 +333,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesIRI(Node $node = null, $property) { + public function getAllValuesIRI(?Node $node = null, $property) { $allValues = $this->getAllValues($node, $property); $output = []; foreach ($allValues as $a) @@ -351,7 +351,7 @@ class NodeReader { * @param string|object $property The property to read. * @return array */ - public function getAllValuesNode(Node $node = null, $property) { + public function getAllValuesNode(?Node $node = null, $property) { $allValues = $this->getAllValues($node, $property); $output = []; foreach ($allValues as $a) diff --git a/CloudObjects/SDK/WebAPI/APIClientFactory.php b/CloudObjects/SDK/WebAPI/APIClientFactory.php index 58a82c0..67e09f4 100644 --- a/CloudObjects/SDK/WebAPI/APIClientFactory.php +++ b/CloudObjects/SDK/WebAPI/APIClientFactory.php @@ -217,7 +217,7 @@ class APIClientFactory { * @param ObjectRetriever $objectRetriever An initialized and authenticated object retriever. * @param IRI|null $namespaceCoid The namespace of the API client. Used to retrieve credentials. If this parameter is not provided, the namespace provided with the "auth_ns" configuration option from the object retriever is used. */ - public function __construct(ObjectRetriever $objectRetriever, IRI $namespaceCoid = null) { + public function __construct(ObjectRetriever $objectRetriever, ?IRI $namespaceCoid = null) { $this->objectRetriever = $objectRetriever; $this->namespace = isset($namespaceCoid) ? $objectRetriever->getObjectNode($namespaceCoid)