-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\Larastan\Types; | ||
|
||
use PHPStan\Type\Type; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Type\ObjectType; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\ShouldNotHappenException; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Database\Eloquent\Model; | ||
use PHPStan\Reflection\FunctionVariant; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\Generic\GenericObjectType; | ||
use PHPStan\Type\Constant\ConstantStringType; | ||
use PHPStan\Type\StringType; | ||
use PHPStan\Type\BooleanType; | ||
use PHPStan\Reflection\ParametersAcceptorSelector; | ||
use PHPStan\Type\DynamicMethodReturnTypeExtension; | ||
|
||
class AppEnvironmentReturnTypeExtension implements DynamicMethodReturnTypeExtension | ||
{ | ||
public function getClass(): string | ||
{ | ||
return Application::class; | ||
} | ||
|
||
public function isMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return $methodReflection->getName() === 'environment'; | ||
} | ||
|
||
public function getTypeFromMethodCall( | ||
MethodReflection $methodReflection, | ||
MethodCall $methodCall, | ||
Scope $scope | ||
): Type { | ||
if (count($methodCall->getArgs()) === 0) { | ||
return new StringType(); | ||
} | ||
|
||
return new BooleanType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Features\ReturnTypes; | ||
|
||
use Illuminate\Auth\AuthManager; | ||
use Illuminate\Container\Container; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class AppAccessTest | ||
{ | ||
public function testEnvironment(): void | ||
{ | ||
assertType('string', app()->environment()); | ||
assertType('bool', app()->environment('local')); | ||
assertType('bool', app()->environment(['local', 'production'])); | ||
} | ||
} |