From 7b95064826c21cd2fdc640da47a6bad0c6f90ec9 Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Wed, 23 Nov 2022 11:55:23 +0100 Subject: [PATCH 1/2] Remove extensions integrated in Larastan --- extension.neon | 8 --- src/ReturnTypes/DateExtension.php | 71 ------------------- src/ReturnTypes/NowAndTodayExtension.php | 27 ------- .../DateCarbonImmutable/DateExtension.php | 16 ----- .../NowAndTodayExtension.php | 15 ---- .../DateCarbonImmutable/phpstan-tests.neon | 8 --- tests/Features/Default/DateExtension.php | 16 ----- .../Features/Default/NowAndTodayExtension.php | 15 ---- tests/Features/phpstan-tests.neon | 8 --- 9 files changed, 184 deletions(-) delete mode 100644 src/ReturnTypes/DateExtension.php delete mode 100644 src/ReturnTypes/NowAndTodayExtension.php delete mode 100644 tests/Features/DateCarbonImmutable/DateExtension.php delete mode 100644 tests/Features/DateCarbonImmutable/NowAndTodayExtension.php delete mode 100644 tests/Features/Default/DateExtension.php delete mode 100644 tests/Features/Default/NowAndTodayExtension.php diff --git a/extension.neon b/extension.neon index 27c75db..5972550 100644 --- a/extension.neon +++ b/extension.neon @@ -1,12 +1,4 @@ services: - - class: Soyhuce\PhpstanExtension\ReturnTypes\DateExtension - tags: - - phpstan.broker.dynamicStaticMethodReturnTypeExtension - - - class: Soyhuce\PhpstanExtension\ReturnTypes\NowAndTodayExtension - tags: - - phpstan.broker.dynamicFunctionReturnTypeExtension - - class: Soyhuce\PhpstanExtension\ReturnTypes\RequestDateExtension tags: - phpstan.broker.dynamicMethodReturnTypeExtension diff --git a/src/ReturnTypes/DateExtension.php b/src/ReturnTypes/DateExtension.php deleted file mode 100644 index 1afb3ef..0000000 --- a/src/ReturnTypes/DateExtension.php +++ /dev/null @@ -1,71 +0,0 @@ -getName(), - [ - 'create', - 'createFromDate', - 'createFromTime', - 'createFromTimeString', - 'createFromTimestamp', - 'createFromTimestampMs', - 'createFromTimestampUTC', - 'createMidnightDate', - 'fromSerialized', - 'getTestNow', - 'instance', - 'maxValue', - 'minValue', - 'now', - 'parse', - 'today', - 'tomorrow', - 'yesterday', - 'createFromFormat', - 'createSafe', - 'make', - ] - ); - } - - public function getTypeFromStaticMethodCall( - MethodReflection $methodReflection, - StaticCall $methodCall, - Scope $scope, - ): Type { - $dateType = new ObjectType(get_class(now())); - - if (in_array($methodReflection->getName(), ['createFromFormat', 'createSafe'])) { - return TypeCombinator::union($dateType, new ConstantBooleanType(false)); - } - - if (in_array($methodReflection->getName(), ['getTestNow', 'make'])) { - return TypeCombinator::addNull($dateType); - } - - return $dateType; - } -} diff --git a/src/ReturnTypes/NowAndTodayExtension.php b/src/ReturnTypes/NowAndTodayExtension.php deleted file mode 100644 index db34e18..0000000 --- a/src/ReturnTypes/NowAndTodayExtension.php +++ /dev/null @@ -1,27 +0,0 @@ -getName() === 'now' || $functionReflection->getName() === 'today'; - } - - public function getTypeFromFunctionCall( - FunctionReflection $functionReflection, - FuncCall $functionCall, - Scope $scope, - ): Type { - return new ObjectType(get_class(now())); - } -} diff --git a/tests/Features/DateCarbonImmutable/DateExtension.php b/tests/Features/DateCarbonImmutable/DateExtension.php deleted file mode 100644 index 63c673d..0000000 --- a/tests/Features/DateCarbonImmutable/DateExtension.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Wed, 23 Nov 2022 11:58:15 +0100 Subject: [PATCH 2/2] Update readme --- README.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/README.md b/README.md index 3292c2b..464cbce 100644 --- a/README.md +++ b/README.md @@ -91,31 +91,6 @@ $dateTime = new Carbon\ImmutableCarbon($date); // ok ## Extensions -### DateExtension - -Provides return type for various `Illuminate\Support\Facades\Date` methods - -```php -use Carbon\FactoryImmutable; -use Illuminate\Support\Facades\Date; - -Date::use(FactoryImmutable::class); -Date::create(2020, 1, 1); // CarbonImmutable -Date::createFromFormat('Y-m-d', '2020-01-01'); // CarbonImmutable|false -``` - -### NowAndTodayExtension - -Provides return type for `now()` and `today()` helpers. - -```php -use Carbon\FactoryImmutable; -use Illuminate\Support\Facades\Date; - -Date::use(FactoryImmutable::class); -now(); // CarbonImmutable -``` - ### RequestDateExtension Provides return type for `\Illuminate\Support\Request::date()` method.