From db097e243902a83598c79d94fe0b1906306e2542 Mon Sep 17 00:00:00 2001 From: Rikudou_Sage Date: Tue, 26 Nov 2024 13:47:55 +0100 Subject: [PATCH] Chore: Explicitly mark parameters as nullable (#231) --- .php-cs-fixer.dist.php | 1 + src/Metrics/DefaultMetricsHandler.php | 2 +- src/Metrics/MetricsHandler.php | 2 +- tests/AbstractHttpClientTestCase.php | 2 +- tests/ClientSpecificationTest.php | 2 +- tests/Configuration/UnleashContextTest.php | 2 +- .../Operator/AbstractOperatorValidatorTest.php | 2 +- .../DependencyContainer/CacheAwareMetricsHandler.php | 2 +- .../ConfigurationAwareMetricsHandler.php | 2 +- .../MetricsSenderAwareMetricsHandler.php | 2 +- .../RequestFactoryAwareEventDispatcher.php | 6 +++--- tests/UnleashBuilderTest.php | 2 +- 12 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e20b711e..ff3433c8 100755 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -66,6 +66,7 @@ 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'normalize_index_brace' => true, + 'nullable_type_declaration_for_default_null_value' => true, 'object_operator_without_whitespace' => true, 'ordered_class_elements' => true, 'ordered_imports' => true, diff --git a/src/Metrics/DefaultMetricsHandler.php b/src/Metrics/DefaultMetricsHandler.php index a672d015..2dcbb63a 100755 --- a/src/Metrics/DefaultMetricsHandler.php +++ b/src/Metrics/DefaultMetricsHandler.php @@ -18,7 +18,7 @@ public function __construct( } #[Override] - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { if (!$this->configuration->isMetricsEnabled()) { return; diff --git a/src/Metrics/MetricsHandler.php b/src/Metrics/MetricsHandler.php index a6a4bd4c..e8b83683 100755 --- a/src/Metrics/MetricsHandler.php +++ b/src/Metrics/MetricsHandler.php @@ -7,5 +7,5 @@ interface MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void; + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void; } diff --git a/tests/AbstractHttpClientTestCase.php b/tests/AbstractHttpClientTestCase.php index 93af411b..c68db652 100755 --- a/tests/AbstractHttpClientTestCase.php +++ b/tests/AbstractHttpClientTestCase.php @@ -92,7 +92,7 @@ protected function setUp(): void ); $this->metricsHandler = new class implements MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } }; diff --git a/tests/ClientSpecificationTest.php b/tests/ClientSpecificationTest.php index efd391bd..f19d16bf 100755 --- a/tests/ClientSpecificationTest.php +++ b/tests/ClientSpecificationTest.php @@ -53,7 +53,7 @@ public function testClientSpecifications() $this->registrationService, $configuration, new class implements MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } }, diff --git a/tests/Configuration/UnleashContextTest.php b/tests/Configuration/UnleashContextTest.php index 09b2f4bb..85055ddb 100755 --- a/tests/Configuration/UnleashContextTest.php +++ b/tests/Configuration/UnleashContextTest.php @@ -185,7 +185,7 @@ public function testCurrentTimeE2E() ->setAutoRegistrationEnabled(false) ->setCache($this->getCache()), new class implements MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } }, diff --git a/tests/ConstraintValidator/Operator/AbstractOperatorValidatorTest.php b/tests/ConstraintValidator/Operator/AbstractOperatorValidatorTest.php index bd14f064..af3db43c 100644 --- a/tests/ConstraintValidator/Operator/AbstractOperatorValidatorTest.php +++ b/tests/ConstraintValidator/Operator/AbstractOperatorValidatorTest.php @@ -53,7 +53,7 @@ public function testMissingValues() ->setMetricsEnabled(false) ->setAutoRegistrationEnabled(false), new class implements MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } }, diff --git a/tests/TestHelpers/DependencyContainer/CacheAwareMetricsHandler.php b/tests/TestHelpers/DependencyContainer/CacheAwareMetricsHandler.php index 74a5ce7a..e7968d09 100644 --- a/tests/TestHelpers/DependencyContainer/CacheAwareMetricsHandler.php +++ b/tests/TestHelpers/DependencyContainer/CacheAwareMetricsHandler.php @@ -20,7 +20,7 @@ public function setCache(CacheInterface $cache): void $this->cache = $cache; } - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } } diff --git a/tests/TestHelpers/DependencyContainer/ConfigurationAwareMetricsHandler.php b/tests/TestHelpers/DependencyContainer/ConfigurationAwareMetricsHandler.php index 1d4c7436..b80d8d2b 100644 --- a/tests/TestHelpers/DependencyContainer/ConfigurationAwareMetricsHandler.php +++ b/tests/TestHelpers/DependencyContainer/ConfigurationAwareMetricsHandler.php @@ -20,7 +20,7 @@ public function setConfiguration(UnleashConfiguration $configuration): void $this->configuration = $configuration; } - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } } diff --git a/tests/TestHelpers/DependencyContainer/MetricsSenderAwareMetricsHandler.php b/tests/TestHelpers/DependencyContainer/MetricsSenderAwareMetricsHandler.php index d22adf5c..e5ba4f00 100644 --- a/tests/TestHelpers/DependencyContainer/MetricsSenderAwareMetricsHandler.php +++ b/tests/TestHelpers/DependencyContainer/MetricsSenderAwareMetricsHandler.php @@ -15,7 +15,7 @@ final class MetricsSenderAwareMetricsHandler implements MetricsHandler, MetricsS */ public $metricsSender = null; - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } diff --git a/tests/TestHelpers/DependencyContainer/RequestFactoryAwareEventDispatcher.php b/tests/TestHelpers/DependencyContainer/RequestFactoryAwareEventDispatcher.php index 68eb06a1..27f84d5e 100644 --- a/tests/TestHelpers/DependencyContainer/RequestFactoryAwareEventDispatcher.php +++ b/tests/TestHelpers/DependencyContainer/RequestFactoryAwareEventDispatcher.php @@ -15,7 +15,7 @@ final class RequestFactoryAwareEventDispatcher implements EventDispatcherInterfa */ public $requestFactory = null; - public function dispatch(object $event, string $eventName = null): object + public function dispatch(object $event, ?string $eventName = null): object { return new stdClass(); } @@ -41,7 +41,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber): void { } - public function getListeners(string $eventName = null): array + public function getListeners(?string $eventName = null): array { return []; } @@ -51,7 +51,7 @@ public function getListenerPriority(string $eventName, callable $listener): ?int return null; } - public function hasListeners(string $eventName = null): bool + public function hasListeners(?string $eventName = null): bool { return false; } diff --git a/tests/UnleashBuilderTest.php b/tests/UnleashBuilderTest.php index 03927c65..61be333e 100755 --- a/tests/UnleashBuilderTest.php +++ b/tests/UnleashBuilderTest.php @@ -769,7 +769,7 @@ public function testWithMetricsCacheHandler() public function testWithMetricsHandler() { $metricsHandler = new class implements MetricsHandler { - public function handleMetrics(Feature $feature, bool $successful, Variant $variant = null): void + public function handleMetrics(Feature $feature, bool $successful, ?Variant $variant = null): void { } };