diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f41d81820..758c1d4caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] * fix: Resolve correct model factory instance when application namespace is empty - +* fix: fix return types for App::environment() [#1303](https://github.com/nunomaduro/larastan/pull/1303) ### Fixed * fix: Remove stubs for `having()` and `orHaving()` QueryBuilder methods by @Maxoulak in [#1258](https://github.com/nunomaduro/larastan/pull/1258) diff --git a/extension.neon b/extension.neon index cb3c337f43..7bb365bb78 100644 --- a/extension.neon +++ b/extension.neon @@ -372,6 +372,10 @@ services: class: NunoMaduro\Larastan\Types\GenericEloquentBuilderTypeNodeResolverExtension tags: - phpstan.phpDoc.typeNodeResolverExtension + - + class: NunoMaduro\Larastan\Types\AppEnvironmentReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension - class: NunoMaduro\Larastan\Types\ModelProperty\ModelPropertyTypeNodeResolverExtension diff --git a/src/Types/AppEnvironmentReturnTypeExtension.php b/src/Types/AppEnvironmentReturnTypeExtension.php new file mode 100644 index 0000000000..9739fd0eeb --- /dev/null +++ b/src/Types/AppEnvironmentReturnTypeExtension.php @@ -0,0 +1,46 @@ +getName() === 'environment'; + } + + public function getTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type { + if (count($methodCall->getArgs()) === 0) { + return new StringType(); + } + + return new BooleanType(); + } +} diff --git a/tests/Features/ReturnTypes/AppAccessTest.php b/tests/Features/ReturnTypes/AppAccessTest.php new file mode 100644 index 0000000000..cd1941a943 --- /dev/null +++ b/tests/Features/ReturnTypes/AppAccessTest.php @@ -0,0 +1,19 @@ +environment()); + assertType('bool', app()->environment('local')); + assertType('bool', app()->environment(['local', 'production'])); + } +}