From e1b64a0f3120cf40fca9703a718e29b0cef89f9f Mon Sep 17 00:00:00 2001 From: Ahmed Helal Date: Wed, 7 Aug 2024 20:37:33 +0300 Subject: [PATCH] feat: add cloud option to supported method for storage (#2020) * add cloud option to supported method for storage * resolve comments: use strict and import in_array * add tests for adding cloud option for storage * fix code sniffer --- .../StorageDynamicStaticMethodReturnTypeExtension.php | 4 +++- tests/Type/data/facades.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ReturnTypes/StorageDynamicStaticMethodReturnTypeExtension.php b/src/ReturnTypes/StorageDynamicStaticMethodReturnTypeExtension.php index e4cad09f3..2878035a7 100644 --- a/src/ReturnTypes/StorageDynamicStaticMethodReturnTypeExtension.php +++ b/src/ReturnTypes/StorageDynamicStaticMethodReturnTypeExtension.php @@ -14,6 +14,8 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use function in_array; + class StorageDynamicStaticMethodReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension { use HasContainer; @@ -25,7 +27,7 @@ public function getClass(): string public function isStaticMethodSupported(MethodReflection $methodReflection): bool { - return $methodReflection->getName() === 'disk' || $methodReflection->getName() === 'drive'; + return in_array($methodReflection->getName(), ['disk', 'drive', 'cloud'], strict: true); } public function getTypeFromStaticMethodCall( diff --git a/tests/Type/data/facades.php b/tests/Type/data/facades.php index 99709b742..e638b5d6e 100644 --- a/tests/Type/data/facades.php +++ b/tests/Type/data/facades.php @@ -37,8 +37,10 @@ function test(): void assertType('Illuminate\Filesystem\FilesystemAdapter', Storage::disk()); assertType('Illuminate\Filesystem\FilesystemAdapter', Storage::drive()); + assertType('Illuminate\Filesystem\FilesystemAdapter', Storage::cloud()); assertType('bool', Storage::disk()->deleteDirectory('foo')); assertType('bool', Storage::drive()->deleteDirectory('foo')); + assertType('bool', Storage::cloud()->deleteDirectory('foo')); assertType('string|false', Storage::putFile('foo', 'foo/bar')); assertType('mixed', Redis::get('foo'));