From 2860d7d146176cabff609a30d0edf4b227ea4795 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Tue, 20 Feb 2024 14:56:18 -0500 Subject: [PATCH] Apply method_argument_space and nullable_type_declaration_for_default_null_value --- src/AuthenticatedClient.php | 4 ++-- src/Cache/Adapter/PHPArray/ArrayCachePool.php | 3 +-- src/DataService/CachingPhpDocExtractor.php | 2 +- src/DataService/DataObjectFactory.php | 6 +++--- src/DataService/DataServiceManager.php | 2 +- src/DataService/DateTime/ConcreteDateTime.php | 2 +- src/DataService/NotificationListener.php | 2 +- src/Exception/ClientException.php | 2 +- src/Exception/MpxExceptionFactory.php | 6 +++--- src/Exception/ServerException.php | 2 +- src/Exception/TokenNotFoundException.php | 2 +- src/Normalizer/UnixMillisecondNormalizer.php | 8 ++++---- src/Service/AccessManagement/ResolveBase.php | 2 +- src/Service/IdentityManagement/UserSession.php | 6 +++--- tests/src/Fixtures/Dummy.php | 2 +- tests/src/Unit/DataService/CachingPhpDocExtractorTest.php | 4 ++-- 16 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/AuthenticatedClient.php b/src/AuthenticatedClient.php index d188f21a..c2a78edd 100644 --- a/src/AuthenticatedClient.php +++ b/src/AuthenticatedClient.php @@ -54,7 +54,7 @@ class AuthenticatedClient implements ClientInterface * @param UserSession $userSession The user associated with this client. * @param IdInterface $account (optional) The account to use as the account context for requests. */ - public function __construct(Client $client, UserSession $userSession, IdInterface $account = null) + public function __construct(Client $client, UserSession $userSession, ?IdInterface $account = null) { $this->client = $client; $this->userSession = $userSession; @@ -94,7 +94,7 @@ public function getConfig($option = null) * * @param int|null $duration The duration in seconds, or null to not use a specific lifetime. */ - public function setTokenDuration(int $duration = null): void + public function setTokenDuration(?int $duration = null): void { $this->duration = $duration; } diff --git a/src/Cache/Adapter/PHPArray/ArrayCachePool.php b/src/Cache/Adapter/PHPArray/ArrayCachePool.php index 7cfa6bc0..42978094 100644 --- a/src/Cache/Adapter/PHPArray/ArrayCachePool.php +++ b/src/Cache/Adapter/PHPArray/ArrayCachePool.php @@ -51,8 +51,7 @@ function (string $key) use ($default) { $item = $this->cache->getItem($key); return $item->isHit() ? $item->get() : $default; - } - , $keys); + }, $keys); } public function setMultiple($values, $ttl = null): bool diff --git a/src/DataService/CachingPhpDocExtractor.php b/src/DataService/CachingPhpDocExtractor.php index e8a78d4f..293339e7 100644 --- a/src/DataService/CachingPhpDocExtractor.php +++ b/src/DataService/CachingPhpDocExtractor.php @@ -40,7 +40,7 @@ class CachingPhpDocExtractor implements PropertyDescriptionExtractorInterface, P * @param string[]|null $accessorPrefixes * @param string[]|null $arrayMutatorPrefixes */ - public function __construct(DocBlockFactoryInterface $docBlockFactory = null, array $mutatorPrefixes = null, array $accessorPrefixes = null, array $arrayMutatorPrefixes = null) + public function __construct(?DocBlockFactoryInterface $docBlockFactory = null, ?array $mutatorPrefixes = null, ?array $accessorPrefixes = null, ?array $arrayMutatorPrefixes = null) { if (!class_exists(DocBlockFactory::class)) { throw new \RuntimeException(sprintf('Unable to use the "%s" class as the "phpdocumentor/reflection-docblock" package is not installed.', self::class)); diff --git a/src/DataService/DataObjectFactory.php b/src/DataService/DataObjectFactory.php index 2d0d6382..87476531 100644 --- a/src/DataService/DataObjectFactory.php +++ b/src/DataService/DataObjectFactory.php @@ -65,7 +65,7 @@ class DataObjectFactory * @param \Lullabot\Mpx\AuthenticatedClient $authenticatedClient A client to make authenticated MPX calls. * @param CacheItemPoolInterface|null $cacheItemPool (optional) Cache to store API metadata. */ - public function __construct(DiscoveredDataService $dataService, AuthenticatedClient $authenticatedClient, CacheItemPoolInterface $cacheItemPool = null) + public function __construct(DiscoveredDataService $dataService, AuthenticatedClient $authenticatedClient, ?CacheItemPoolInterface $cacheItemPool = null) { $this->authenticatedClient = $authenticatedClient; $this->dataService = $dataService; @@ -201,7 +201,7 @@ public function load(UriInterface $uri, array $options = []): PromiseInterface * * @return ObjectListIterator An iterator over the full result set. */ - public function select(ObjectListQuery $objectListQuery = null, array $options = []): ObjectListIterator + public function select(?ObjectListQuery $objectListQuery = null, array $options = []): ObjectListIterator { return new ObjectListIterator($this->selectRequest($objectListQuery, $options)); } @@ -217,7 +217,7 @@ public function select(ObjectListQuery $objectListQuery = null, array $options = * * @return PromiseInterface A promise to return an ObjectList. */ - public function selectRequest(ObjectListQuery $objectListQuery = null, array $options = []): PromiseInterface + public function selectRequest(?ObjectListQuery $objectListQuery = null, array $options = []): PromiseInterface { if (!$objectListQuery) { $objectListQuery = new ObjectListQuery(); diff --git a/src/DataService/DataServiceManager.php b/src/DataService/DataServiceManager.php index 7815d48f..c4ace75b 100644 --- a/src/DataService/DataServiceManager.php +++ b/src/DataService/DataServiceManager.php @@ -18,7 +18,7 @@ public function __construct(private readonly DataServiceDiscovery $discovery) * * @return static */ - public static function basicDiscovery(CustomFieldManager $customFieldManager = null) + public static function basicDiscovery(?CustomFieldManager $customFieldManager = null) { if (!$customFieldManager) { $customFieldManager = CustomFieldManager::basicDiscovery(); diff --git a/src/DataService/DateTime/ConcreteDateTime.php b/src/DataService/DateTime/ConcreteDateTime.php index 135fb07f..386d883f 100644 --- a/src/DataService/DateTime/ConcreteDateTime.php +++ b/src/DataService/DateTime/ConcreteDateTime.php @@ -20,7 +20,7 @@ public function __construct(private readonly \DateTime $dateTime) * * @see http://php.net/manual/en/datetime.construct.php */ - public static function fromString($time = 'now', \DateTimeZone $timezone = null): self + public static function fromString($time = 'now', ?\DateTimeZone $timezone = null): self { return new static(new \DateTime($time, $timezone)); } diff --git a/src/DataService/NotificationListener.php b/src/DataService/NotificationListener.php index 11b0d3cb..ad02eeec 100644 --- a/src/DataService/NotificationListener.php +++ b/src/DataService/NotificationListener.php @@ -62,7 +62,7 @@ class NotificationListener * @param string $clientId A string to identify this client in debugging. * @param CacheItemPoolInterface|null $cacheItemPool (optional) The cache for API metadata. */ - public function __construct(AuthenticatedClient $session, DiscoveredDataService $service, private readonly string $clientId, CacheItemPoolInterface $cacheItemPool = null) + public function __construct(AuthenticatedClient $session, DiscoveredDataService $service, private readonly string $clientId, ?CacheItemPoolInterface $cacheItemPool = null) { $this->authenticatedClient = $session; $this->service = $service; diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index 20bd55e7..b0a515df 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -21,7 +21,7 @@ class ClientException extends GuzzleClientException implements MpxExceptionInter * @param \Exception|null $previous (optional) The previous exception. * @param array $handlerContext (optional) Custom HTTP handler context, if available. */ - public function __construct(RequestInterface $request, ResponseInterface $response, \Exception $previous = null, array $handlerContext = []) + public function __construct(RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null, array $handlerContext = []) { $message = $this->parseResponse($response); parent::__construct($message, $request, $response, $previous, $handlerContext); diff --git a/src/Exception/MpxExceptionFactory.php b/src/Exception/MpxExceptionFactory.php index 5d99d9ff..283a686e 100644 --- a/src/Exception/MpxExceptionFactory.php +++ b/src/Exception/MpxExceptionFactory.php @@ -16,7 +16,7 @@ class MpxExceptionFactory public static function create( RequestInterface $request, ResponseInterface $response, - \Exception $previous = null, + ?\Exception $previous = null, array $ctx = [] ): ClientException|ServerException { $data = \GuzzleHttp\Utils::jsonDecode($response->getBody(), true); @@ -30,7 +30,7 @@ public static function create( /** * Create a new MPX API exception from a notification. */ - public static function createFromNotificationException(RequestInterface $request, ResponseInterface $response, \Exception $previous = null, array $ctx = []): ClientException|ServerException + public static function createFromNotificationException(RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null, array $ctx = []): ClientException|ServerException { $data = \GuzzleHttp\Utils::jsonDecode($response->getBody(), true); ServerException::validateNotificationData($data); @@ -45,7 +45,7 @@ public static function createFromNotificationException(RequestInterface $request */ private static function createException(RequestInterface $request, ResponseInterface $altered, - \Exception $previous = null, + ?\Exception $previous = null, array $ctx = [] ): ClientException|ServerException { if ($altered->getStatusCode() >= 400 && $altered->getStatusCode() < 500) { diff --git a/src/Exception/ServerException.php b/src/Exception/ServerException.php index b4801248..e6271a25 100644 --- a/src/Exception/ServerException.php +++ b/src/Exception/ServerException.php @@ -18,7 +18,7 @@ class ServerException extends GuzzleServerException implements MpxExceptionInter * @param \Exception|null $previous (optional) The previous exception. * @param array $handlerContext (optional) Custom HTTP handler context, if available. */ - public function __construct(RequestInterface $request, ResponseInterface $response, \Exception $previous = null, array $handlerContext = []) + public function __construct(RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null, array $handlerContext = []) { $message = $this->parseResponse($response); parent::__construct($message, $request, $response, $previous, $handlerContext); diff --git a/src/Exception/TokenNotFoundException.php b/src/Exception/TokenNotFoundException.php index 0963974b..555570fd 100644 --- a/src/Exception/TokenNotFoundException.php +++ b/src/Exception/TokenNotFoundException.php @@ -16,7 +16,7 @@ class TokenNotFoundException extends \RuntimeException * @param int $code The exception code. * @param \Throwable|null $previous The previous exception, if available. */ - public function __construct(UserSession $userSession, int $code = 0, \Throwable $previous = null) + public function __construct(UserSession $userSession, int $code = 0, ?\Throwable $previous = null) { parent::__construct(sprintf('Token not found for %s.', $userSession->getUser()->getMpxUsername()), $code, $previous); } diff --git a/src/Normalizer/UnixMillisecondNormalizer.php b/src/Normalizer/UnixMillisecondNormalizer.php index a7bb7d86..19287e9e 100644 --- a/src/Normalizer/UnixMillisecondNormalizer.php +++ b/src/Normalizer/UnixMillisecondNormalizer.php @@ -53,17 +53,17 @@ public function getSupportedTypes(?string $format): array /** * @throws InvalidArgumentException */ - public function normalize(mixed $object, string $format = null, array $context = []): string + public function normalize(mixed $object, ?string $format = null, array $context = []): string { return $this->decorated->normalize($object, $format, $context); } - public function supportsNormalization(mixed $data, string $format = null): bool + public function supportsNormalization(mixed $data, ?string $format = null): bool { return $this->decorated->supportsNormalization($data, $format); } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): ConcreteDateTime + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): ConcreteDateTime { if (!\is_int($data)) { throw new NotNormalizableValueException('The data is not an integer, you should pass an integer representing the unix time in milliseconds.'); @@ -80,7 +80,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar return new ConcreteDateTime($date); } - public function supportsDenormalization(mixed $data, string $type, string $format = null): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null): bool { return isset(self::$supportedTypes[$type]); } diff --git a/src/Service/AccessManagement/ResolveBase.php b/src/Service/AccessManagement/ResolveBase.php index fd881e4c..fe3dcace 100644 --- a/src/Service/AccessManagement/ResolveBase.php +++ b/src/Service/AccessManagement/ResolveBase.php @@ -27,7 +27,7 @@ abstract class ResolveBase * @param AuthenticatedClient $authenticatedClient The client used to access mpx. * @param CacheItemPoolInterface|null $cache (optional) The cache to store responses in. Defaults to an array cache. */ - public function __construct(AuthenticatedClient $authenticatedClient, CacheItemPoolInterface $cache = null) + public function __construct(AuthenticatedClient $authenticatedClient, ?CacheItemPoolInterface $cache = null) { $this->authenticatedClient = $authenticatedClient; diff --git a/src/Service/IdentityManagement/UserSession.php b/src/Service/IdentityManagement/UserSession.php index d296c653..5e194f12 100644 --- a/src/Service/IdentityManagement/UserSession.php +++ b/src/Service/IdentityManagement/UserSession.php @@ -68,7 +68,7 @@ class UserSession * * @see \Psr\Log\NullLogger To disable logging of token requests. */ - public function __construct(UserInterface $user, Client $client, PersistingStoreInterface $store = null, TokenCachePool $tokenCachePool = null) + public function __construct(UserInterface $user, Client $client, ?PersistingStoreInterface $store = null, ?TokenCachePool $tokenCachePool = null) { $this->user = $user; $this->client = $client; @@ -92,7 +92,7 @@ public function __construct(UserInterface $user, Client $client, PersistingStore * * @return Token A valid mpx authentication token. */ - public function acquireToken(int $duration = null, bool $reset = false): Token + public function acquireToken(?int $duration = null, bool $reset = false): Token { if ($reset) { $this->tokenCachePool->deleteToken($this); @@ -169,7 +169,7 @@ public function signOut() * * @return \Lullabot\Mpx\Token The token. */ - protected function signInWithLock(int $duration = null): Token + protected function signInWithLock(?int $duration = null): Token { if ($this->store) { $factory = new LockFactory($this->store); diff --git a/tests/src/Fixtures/Dummy.php b/tests/src/Fixtures/Dummy.php index c5927ce6..13955bd2 100644 --- a/tests/src/Fixtures/Dummy.php +++ b/tests/src/Fixtures/Dummy.php @@ -138,7 +138,7 @@ public function getA() /** * B. */ - public function setB(ParentDummy $parent = null) + public function setB(?ParentDummy $parent = null) { } diff --git a/tests/src/Unit/DataService/CachingPhpDocExtractorTest.php b/tests/src/Unit/DataService/CachingPhpDocExtractorTest.php index e8b6a8a3..f291ef89 100644 --- a/tests/src/Unit/DataService/CachingPhpDocExtractorTest.php +++ b/tests/src/Unit/DataService/CachingPhpDocExtractorTest.php @@ -36,7 +36,7 @@ public function testParamTagTypeIsOmitted() /** * @dataProvider typesWithCustomPrefixesProvider */ - public function testExtractTypesWithCustomPrefixes($property, array $type = null) + public function testExtractTypesWithCustomPrefixes($property, ?array $type = null) { $customExtractor = new CachingPhpDocExtractor(null, ['add', 'remove'], ['is', 'can']); @@ -46,7 +46,7 @@ public function testExtractTypesWithCustomPrefixes($property, array $type = null /** * @dataProvider typesWithNoPrefixesProvider */ - public function testExtractTypesWithNoPrefixes($property, array $type = null) + public function testExtractTypesWithNoPrefixes($property, ?array $type = null) { $noPrefixExtractor = new CachingPhpDocExtractor(null, [], [], []);