From 998e5c0ed262bc7bc192fbcf0c48fee2928597f6 Mon Sep 17 00:00:00 2001 From: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:59:59 +0100 Subject: [PATCH] feat: Add PHP 8.4 support (#415) Signed-off-by: Joas Schilling Co-authored-by: Konstantin Babushkin --- .github/workflows/unit_tests.yml | 2 +- src/Common/Auth/AuthHandler.php | 2 +- src/Common/Error/Builder.php | 4 +- src/Common/HydratorStrategyTrait.php | 2 +- src/Common/JsonSchema/Schema.php | 2 +- src/Common/Resource/Alias.php | 2 +- src/Common/Resource/Listable.php | 8 ++-- src/Common/Resource/OperatorResource.php | 4 +- src/Common/Service/Builder.php | 2 +- src/Common/Transport/HandlerStack.php | 2 +- src/Common/Transport/HandlerStackFactory.php | 2 +- src/Common/Transport/Middleware.php | 4 +- src/Common/Transport/RequestSerializer.php | 2 +- src/Common/Transport/Utils.php | 2 +- src/Compute/v2/Service.php | 40 ++++++++++---------- src/Images/v2/Models/Schema.php | 2 +- src/ObjectStore/v1/Models/Container.php | 2 +- src/ObjectStore/v1/Service.php | 6 +-- src/OpenStack.php | 2 +- 19 files changed, 46 insertions(+), 46 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 22972dd7a..6b6ac130d 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 ] + php: [ 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 ] composer: - name: lowest arg: "--prefer-lowest --prefer-stable" diff --git a/src/Common/Auth/AuthHandler.php b/src/Common/Auth/AuthHandler.php index 71a58721c..4abf2b83e 100644 --- a/src/Common/Auth/AuthHandler.php +++ b/src/Common/Auth/AuthHandler.php @@ -25,7 +25,7 @@ class AuthHandler /** @var Token */ private $token; - public function __construct(callable $nextHandler, callable $tokenGenerator, Token $token = null) + public function __construct(callable $nextHandler, callable $tokenGenerator, ?Token $token = null) { $this->nextHandler = $nextHandler; $this->tokenGenerator = $tokenGenerator; diff --git a/src/Common/Error/Builder.php b/src/Common/Error/Builder.php index f2717aa1a..a9830309f 100644 --- a/src/Common/Error/Builder.php +++ b/src/Common/Error/Builder.php @@ -35,7 +35,7 @@ class Builder */ private $client; - public function __construct(ClientInterface $client = null) + public function __construct(?ClientInterface $client = null) { $this->client = $client ?: new Client(); } @@ -164,7 +164,7 @@ private function getStatusCodeMessage(int $statusCode): string * @param mixed $userValue The incorrect value the user actually provided * @param string|null $furtherLink a link to further information if necessary (optional) */ - public function userInputError(string $expectedType, $userValue, string $furtherLink = null): UserInputError + public function userInputError(string $expectedType, $userValue, ?string $furtherLink = null): UserInputError { $message = $this->header('User Input Error'); diff --git a/src/Common/HydratorStrategyTrait.php b/src/Common/HydratorStrategyTrait.php index 83d5719bc..43ddd946d 100644 --- a/src/Common/HydratorStrategyTrait.php +++ b/src/Common/HydratorStrategyTrait.php @@ -25,7 +25,7 @@ public function hydrate(array $data, array $aliases = []) } } - public function set(string $key, $property, array $data, callable $fn = null) + public function set(string $key, $property, array $data, ?callable $fn = null) { if (isset($data[$key]) && property_exists($this, $property)) { $value = $fn ? call_user_func($fn, $data[$key]) : $data[$key]; diff --git a/src/Common/JsonSchema/Schema.php b/src/Common/JsonSchema/Schema.php index 36396d5ee..d2ac5cdd7 100644 --- a/src/Common/JsonSchema/Schema.php +++ b/src/Common/JsonSchema/Schema.php @@ -14,7 +14,7 @@ class Schema /** @var Validator */ private $validator; - public function __construct($body, Validator $validator = null) + public function __construct($body, ?Validator $validator = null) { $this->body = (object) $body; $this->validator = $validator ?: new Validator(); diff --git a/src/Common/Resource/Alias.php b/src/Common/Resource/Alias.php index ebd7a6bfd..53944bab1 100644 --- a/src/Common/Resource/Alias.php +++ b/src/Common/Resource/Alias.php @@ -26,7 +26,7 @@ class Alias * @param string|null $className A class name for the property value * @param bool $list Whether value of the property should be treated as a list or not */ - public function __construct(string $propertyName, string $className = null, bool $list = false) + public function __construct(string $propertyName, ?string $className = null, bool $list = false) { $this->isList = $list; $this->propertyName = $propertyName; diff --git a/src/Common/Resource/Listable.php b/src/Common/Resource/Listable.php index a19499e3d..899e80fc2 100644 --- a/src/Common/Resource/Listable.php +++ b/src/Common/Resource/Listable.php @@ -18,11 +18,11 @@ interface Listable * of the marker will depend on the last element returned in the previous response. If a limit is * provided, the loop will continue up until that point. * - * @param array $def The operation definition - * @param array $userVals The user values - * @param callable $mapFn an optional callback that will be executed on every resource iteration + * @param array $def The operation definition + * @param array $userVals The user values + * @param callable|null $mapFn an optional callback that will be executed on every resource iteration * * @returns \Generator */ - public function enumerate(array $def, array $userVals = [], callable $mapFn = null); + public function enumerate(array $def, array $userVals = [], ?callable $mapFn = null); } diff --git a/src/Common/Resource/OperatorResource.php b/src/Common/Resource/OperatorResource.php index 894925986..ac940c762 100644 --- a/src/Common/Resource/OperatorResource.php +++ b/src/Common/Resource/OperatorResource.php @@ -69,7 +69,7 @@ private function getResourcesKey(): string * * @returns \Generator */ - public function enumerate(array $def, array $userVals = [], callable $mapFn = null): \Generator + public function enumerate(array $def, array $userVals = [], ?callable $mapFn = null): \Generator { $operation = $this->getOperation($def); @@ -105,7 +105,7 @@ public function enumerate(array $def, array $userVals = [], callable $mapFn = nu * * @return array */ - public function extractMultipleInstances(ResponseInterface $response, string $key = null): array + public function extractMultipleInstances(ResponseInterface $response, ?string $key = null): array { $key = $key ?: $this->getResourcesKey(); $resourcesData = Utils::jsonDecode($response)[$key]; diff --git a/src/Common/Service/Builder.php b/src/Common/Service/Builder.php index f63eefc18..a5dca9974 100644 --- a/src/Common/Service/Builder.php +++ b/src/Common/Service/Builder.php @@ -109,7 +109,7 @@ private function stockAuthHandler(array &$options): void } } - private function httpClient(string $baseUrl, HandlerStack $stack, string $serviceType = null, string $microVersion = null): ClientInterface + private function httpClient(string $baseUrl, HandlerStack $stack, ?string $serviceType = null, ?string $microVersion = null): ClientInterface { $clientOptions = [ 'base_uri' => Utils::normalizeUrl($baseUrl), diff --git a/src/Common/Transport/HandlerStack.php b/src/Common/Transport/HandlerStack.php index fd500be50..158b57b3c 100644 --- a/src/Common/Transport/HandlerStack.php +++ b/src/Common/Transport/HandlerStack.php @@ -10,7 +10,7 @@ class HandlerStack /** * @deprecated use \OpenStack\Common\Transport\HandlerStackFactory::createWithOptions instead */ - public static function create(callable $handler = null): \GuzzleHttp\HandlerStack + public static function create(?callable $handler = null): \GuzzleHttp\HandlerStack { return HandlerStackFactory::create($handler); } diff --git a/src/Common/Transport/HandlerStackFactory.php b/src/Common/Transport/HandlerStackFactory.php index a2324d581..7afa03735 100644 --- a/src/Common/Transport/HandlerStackFactory.php +++ b/src/Common/Transport/HandlerStackFactory.php @@ -13,7 +13,7 @@ class HandlerStackFactory /** * @deprecated use \OpenStack\Common\Transport\HandlerStackFactory::createWithOptions instead */ - public static function create(callable $handler = null): HandlerStack + public static function create(?callable $handler = null): HandlerStack { $stack = new HandlerStack($handler ?: Utils::chooseHandler()); $stack->push(Middleware::httpErrors(), 'http_errors'); diff --git a/src/Common/Transport/Middleware.php b/src/Common/Transport/Middleware.php index d11667ef4..c7eaed348 100644 --- a/src/Common/Transport/Middleware.php +++ b/src/Common/Transport/Middleware.php @@ -31,7 +31,7 @@ function (ResponseInterface $response) use ($request, $verbosity) { }; } - public static function authHandler(callable $tokenGenerator, Token $token = null): callable + public static function authHandler(callable $tokenGenerator, ?Token $token = null): callable { return function (callable $handler) use ($tokenGenerator, $token) { return new AuthHandler($handler, $tokenGenerator, $token); @@ -49,7 +49,7 @@ public static function history(array &$container): callable /** * @codeCoverageIgnore */ - public static function retry(callable $decider, callable $delay = null): callable + public static function retry(callable $decider, ?callable $delay = null): callable { return GuzzleMiddleware::retry($decider, $delay); } diff --git a/src/Common/Transport/RequestSerializer.php b/src/Common/Transport/RequestSerializer.php index 533a11c5c..20d29e668 100644 --- a/src/Common/Transport/RequestSerializer.php +++ b/src/Common/Transport/RequestSerializer.php @@ -11,7 +11,7 @@ class RequestSerializer { private $jsonSerializer; - public function __construct(JsonSerializer $jsonSerializer = null) + public function __construct(?JsonSerializer $jsonSerializer = null) { $this->jsonSerializer = $jsonSerializer ?: new JsonSerializer(); } diff --git a/src/Common/Transport/Utils.php b/src/Common/Transport/Utils.php index 6a52a81a2..52a4f3c91 100644 --- a/src/Common/Transport/Utils.php +++ b/src/Common/Transport/Utils.php @@ -45,7 +45,7 @@ public static function jsonDecode(ResponseInterface $response, bool $assoc = tru * * @return array */ - public static function flattenJson($data, string $key = null) + public static function flattenJson($data, ?string $key = null) { return (!empty($data) && $key && isset($data[$key])) ? $data[$key] : $data; } diff --git a/src/Compute/v2/Service.php b/src/Compute/v2/Service.php index 3dc1fd4c8..968b22ebc 100644 --- a/src/Compute/v2/Service.php +++ b/src/Compute/v2/Service.php @@ -44,7 +44,7 @@ public function createServer(array $options): Server * * @return \Generator */ - public function listServers(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator + public function listServers(bool $detailed = false, array $options = [], ?callable $mapFn = null): \Generator { $def = (true === $detailed) ? $this->api->getServersDetail() : $this->api->getServers(); @@ -72,13 +72,13 @@ public function getServer(array $options = []): Server /** * List flavors. * - * @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors} - * @param callable $mapFn a callable function that will be invoked on every iteration of the list - * @param bool $detailed set to true to fetch flavors' details + * @param array $options {@see \OpenStack\Compute\v2\Api::getFlavors} + * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list + * @param bool $detailed set to true to fetch flavors' details * * @return \Generator */ - public function listFlavors(array $options = [], callable $mapFn = null, bool $detailed = false): \Generator + public function listFlavors(array $options = [], ?callable $mapFn = null, bool $detailed = false): \Generator { $def = true === $detailed ? $this->api->getFlavorsDetail() : $this->api->getFlavors(); @@ -119,7 +119,7 @@ public function createFlavor(array $options = []): Flavor * * @return \Generator */ - public function listImages(array $options = [], callable $mapFn = null): \Generator + public function listImages(array $options = [], ?callable $mapFn = null): \Generator { return $this->model(Image::class)->enumerate($this->api->getImages(), $options, $mapFn); } @@ -143,12 +143,12 @@ public function getImage(array $options = []): Image /** * List key pairs. * - * @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs} - * @param callable $mapFn a callable function that will be invoked on every iteration of the list + * @param array $options {@see \OpenStack\Compute\v2\Api::getKeyPairs} + * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list * * @return \Generator */ - public function listKeypairs(array $options = [], callable $mapFn = null): \Generator + public function listKeypairs(array $options = [], ?callable $mapFn = null): \Generator { return $this->model(Keypair::class)->enumerate($this->api->getKeypairs(), $options, $mapFn); } @@ -197,14 +197,14 @@ public function getHypervisorStatistics(): HypervisorStatistic /** * List hypervisors. * - * @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only - * the ID, name and links attributes are returned, saving bandwidth. - * @param array $options {@see \OpenStack\Compute\v2\Api::getHypervisors} - * @param callable $mapFn a callable function that will be invoked on every iteration of the list + * @param bool $detailed Determines whether detailed information will be returned. If FALSE is specified, only + * the ID, name and links attributes are returned, saving bandwidth. + * @param array $options {@see \OpenStack\Compute\v2\Api::getHypervisors} + * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list * * @return \Generator */ - public function listHypervisors(bool $detailed = false, array $options = [], callable $mapFn = null): \Generator + public function listHypervisors(bool $detailed = false, array $options = [], ?callable $mapFn = null): \Generator { $def = (true === $detailed) ? $this->api->getHypervisorsDetail() : $this->api->getHypervisors(); @@ -224,12 +224,12 @@ public function getHypervisor(array $options = []): Hypervisor /** * List hosts. * - * @param array $options {@see \OpenStack\Compute\v2\Api::getHosts} - * @param callable $mapFn a callable function that will be invoked on every iteration of the list + * @param array $options {@see \OpenStack\Compute\v2\Api::getHosts} + * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list * * @return \Generator */ - public function listHosts(array $options = [], callable $mapFn = null): \Generator + public function listHosts(array $options = [], ?callable $mapFn = null): \Generator { return $this->model(Host::class)->enumerate($this->api->getHosts(), $options, $mapFn); } @@ -255,12 +255,12 @@ public function getHost(array $options = []): Host /** * List AZs. * - * @param array $options {@see \OpenStack\Compute\v2\Api::getAvailabilityZones} - * @param callable $mapFn a callable function that will be invoked on every iteration of the list + * @param array $options {@see \OpenStack\Compute\v2\Api::getAvailabilityZones} + * @param callable|null $mapFn a callable function that will be invoked on every iteration of the list * * @return \Generator */ - public function listAvailabilityZones(array $options = [], callable $mapFn = null): \Generator + public function listAvailabilityZones(array $options = [], ?callable $mapFn = null): \Generator { return $this->model(AvailabilityZone::class)->enumerate($this->api->getAvailabilityZones(), $options, $mapFn); } diff --git a/src/Images/v2/Models/Schema.php b/src/Images/v2/Models/Schema.php index 44532fab2..10373e6fa 100644 --- a/src/Images/v2/Models/Schema.php +++ b/src/Images/v2/Models/Schema.php @@ -8,7 +8,7 @@ class Schema extends \OpenStack\Common\JsonSchema\Schema { - public function __construct($data, Validator $validator = null) + public function __construct($data, ?Validator $validator = null) { if (!isset($data->type)) { $data->type = 'object'; diff --git a/src/ObjectStore/v1/Models/Container.php b/src/ObjectStore/v1/Models/Container.php index fa9350268..74f2e4662 100644 --- a/src/ObjectStore/v1/Models/Container.php +++ b/src/ObjectStore/v1/Models/Container.php @@ -57,7 +57,7 @@ public function populateFromResponse(ResponseInterface $response): self * * @return \Generator */ - public function listObjects(array $options = [], callable $mapFn = null): \Generator + public function listObjects(array $options = [], ?callable $mapFn = null): \Generator { $options = array_merge($options, ['name' => $this->name, 'format' => 'json']); diff --git a/src/ObjectStore/v1/Service.php b/src/ObjectStore/v1/Service.php index d4bdbae78..e4686c3b6 100644 --- a/src/ObjectStore/v1/Service.php +++ b/src/ObjectStore/v1/Service.php @@ -30,7 +30,7 @@ public function getAccount(): Account * * @return \Generator */ - public function listContainers(array $options = [], callable $mapFn = null): \Generator + public function listContainers(array $options = [], ?callable $mapFn = null): \Generator { $options = array_merge($options, ['format' => 'json']); @@ -41,9 +41,9 @@ public function listContainers(array $options = [], callable $mapFn = null): \Ge * Retrieves a Container object and populates its name according to the value provided. Please note that the * remote API is not contacted. * - * @param string $name The unique name of the container + * @param string|null $name The unique name of the container */ - public function getContainer(string $name = null): Container + public function getContainer(?string $name = null): Container { return $this->model(Container::class, ['name' => $name]); } diff --git a/src/OpenStack.php b/src/OpenStack.php index 4eecd642a..254e66df3 100644 --- a/src/OpenStack.php +++ b/src/OpenStack.php @@ -33,7 +33,7 @@ class OpenStack * ['requestOptions'] = (array) Guzzle Http request options [OPTIONAL] * ['cachedToken'] = (array) Cached token credential [OPTIONAL] */ - public function __construct(array $options = [], Builder $builder = null) + public function __construct(array $options = [], ?Builder $builder = null) { $defaults = ['errorVerbosity' => 2]; $options = array_merge($defaults, $options);