Update return types

This commit is contained in:
Matt Brown 2020-10-19 12:12:59 -04:00
parent 009b8477bb
commit 62f9610a2a
11 changed files with 81 additions and 26 deletions

View File

@ -11,7 +11,7 @@
"illuminate/database": "5.8.* || ^6.0 || ^7.0 || ^8.0",
"illuminate/http": "5.8.* || ^6.0 || ^7.0 || ^8.0",
"illuminate/support": "5.8.* || ^6.0 || ^7.0 || ^8.0",
"vimeo/psalm": "4.0",
"vimeo/psalm": "4.0.0-beta3",
"orchestra/testbench": "^3.8 || ^4.0 || ^5.0 || ^6.0"
},
"license": "MIT",

View File

@ -19,6 +19,13 @@
<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<file name="src/FakeMetaCommand.php" />
<file name="src/FakeModelsCommand.php" />
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
<stubs>

View File

@ -32,12 +32,14 @@ class AppInterfaceProvider implements
string $method_name_lowercase,
StatementsSource $source = null,
CodeLocation $code_location = null
) {
) : ?bool {
if ($method_name_lowercase === 'offsetget'
|| $method_name_lowercase === 'offsetset'
) {
return true;
}
return null;
}
/**
@ -49,12 +51,14 @@ class AppInterfaceProvider implements
string $method_name_lowercase,
Context $context,
CodeLocation $code_location = null
) {
) : ?bool {
if ($method_name_lowercase === 'offsetget'
|| $method_name_lowercase === 'offsetset'
) {
return true;
}
return null;
}
/**
@ -68,7 +72,7 @@ class AppInterfaceProvider implements
StatementsSource $statements_source = null,
Context $context = null,
CodeLocation $code_location = null
) {
) : ?array {
if ($statements_source) {
if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset') {
return $statements_source->getCodebase()->getMethodParams(
@ -76,11 +80,12 @@ class AppInterfaceProvider implements
);
}
}
return null;
}
/**
* @param array<PhpParser\Node\Arg> $call_args
* @return ?Type\Union
*/
public static function getMethodReturnType(
StatementsSource $source,
@ -92,12 +97,14 @@ class AppInterfaceProvider implements
array $template_type_parameters = null,
string $called_fq_classlike_name = null,
string $called_method_name_lowercase = null
) {
) : ?Type\Union {
if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset') {
return $source->getCodebase()->getMethodReturnType(
get_class(ApplicationHelper::getApp()) . '::' . $method_name_lowercase,
$fq_classlike_name
);
}
return null;
}
}

View File

@ -23,10 +23,7 @@ class Plugin implements PluginEntryPointInterface
/** @var array<string> */
public static $model_classes = [];
/**
* @return void
*/
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null)
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null) : void
{
$app = ApplicationHelper::bootApp();

View File

@ -37,7 +37,7 @@ class ModelPropertyProvider implements
StatementsSource $source = null,
Context $context = null,
CodeLocation $code_location = null
) {
) : ?bool {
if (!$source || !$read_mode) {
return null;
}
@ -71,7 +71,7 @@ class ModelPropertyProvider implements
bool $read_mode,
Context $context,
CodeLocation $code_location = null
) {
) : ?bool {
if (!$read_mode) {
return null;
}
@ -105,7 +105,7 @@ class ModelPropertyProvider implements
bool $read_mode,
StatementsSource $source = null,
Context $context = null
) {
) : ?Type\Union {
if (!$source || !$read_mode) {
return null;
}
@ -171,6 +171,8 @@ class ModelPropertyProvider implements
return $codebase->getMethodReturnType($fq_classlike_name . '::get' . str_replace('_', '', $property_name) . 'Attribute', $fq_classlike_name)
?: Type::getMixed();
}
return null;
}
/**

View File

@ -47,8 +47,17 @@ final class AppReturnTypeProvider implements FunctionReturnTypeProviderInterface
return [get_class(ApplicationHelper::getApp())];
}
public static function getMethodReturnType(StatementsSource $source, string $fq_classlike_name, string $method_name_lowercase, array $call_args, Context $context, CodeLocation $code_location, array $template_type_parameters = null, string $called_fq_classlike_name = null, string $called_method_name_lowercase = null)
{
public static function getMethodReturnType(
StatementsSource $source,
string $fq_classlike_name,
string $method_name_lowercase,
array $call_args,
Context $context,
CodeLocation $code_location,
?array $template_type_parameters = null,
?string $called_fq_classlike_name = null,
?string $called_method_name_lowercase = null
) : ?Type\Union {
// lumen doesn't have the likes of makeWith, so we will ensure these methods actually exist on the underlying
// app contract
$methods = array_filter(['make', 'makewith'], function (string $methodName) use ($source, $fq_classlike_name) {

View File

@ -39,7 +39,7 @@ final class ModelReturnTypeProvider implements MethodReturnTypeProviderInterface
array $template_type_parameters = null,
string $called_fq_classlike_name = null,
string $called_method_name_lowercase = null
) {
) : ?Type\Union {
if (!$source instanceof \Psalm\Internal\Analyzer\StatementsAnalyzer) {
return null;
}

View File

@ -21,8 +21,13 @@ final class PathHelpersReturnTypeProvider implements FunctionReturnTypeProviderI
return ['app_path', 'base_path', 'config_path', 'database_path', 'resource_path', 'public_path', 'storage_path'];
}
public static function getFunctionReturnType(StatementsSource $statements_source, string $function_id, array $call_args, Context $context, CodeLocation $code_location)
{
public static function getFunctionReturnType(
StatementsSource $statements_source,
string $function_id,
array $call_args,
Context $context,
CodeLocation $code_location
) : ?Union {
/**
* @psalm-suppress MissingClosureReturnType
*/
@ -38,8 +43,17 @@ final class PathHelpersReturnTypeProvider implements FunctionReturnTypeProviderI
];
}
public static function getMethodReturnType(StatementsSource $source, string $fq_classlike_name, string $method_name_lowercase, array $call_args, Context $context, CodeLocation $code_location, array $template_type_parameters = null, string $called_fq_classlike_name = null, string $called_method_name_lowercase = null)
{
public static function getMethodReturnType(
StatementsSource $source,
string $fq_classlike_name,
string $method_name_lowercase,
array $call_args,
Context $context,
CodeLocation $code_location,
array $template_type_parameters = null,
string $called_fq_classlike_name = null,
string $called_method_name_lowercase = null
) : ?Union {
$methods = ['path', 'basepath', 'configpath', 'databasepath', 'resourcepath'];
if (!in_array($method_name_lowercase, $methods)) {

View File

@ -27,8 +27,13 @@ class RedirectReturnTypeProvider implements FunctionReturnTypeProviderInterface
*
* @return ?Type\Union
*/
public static function getFunctionReturnType(StatementsSource $statements_source, string $function_id, array $call_args, Context $context, CodeLocation $code_location)
{
public static function getFunctionReturnType(
StatementsSource $statements_source,
string $function_id,
array $call_args,
Context $context,
CodeLocation $code_location
) : ?Type\Union {
if (!$call_args) {
return new Type\Union([
new Type\Atomic\TNamedObject(Redirector::class)

View File

@ -41,8 +41,17 @@ final class RelationReturnTypeProvider implements MethodReturnTypeProviderInterf
];
}
public static function getMethodReturnType(StatementsSource $source, string $fq_classlike_name, string $method_name_lowercase, array $call_args, Context $context, CodeLocation $code_location, array $template_type_parameters = null, string $called_fq_classlike_name = null, string $called_method_name_lowercase = null)
{
public static function getMethodReturnType(
StatementsSource $source,
string $fq_classlike_name,
string $method_name_lowercase,
array $call_args,
Context $context,
CodeLocation $code_location,
array $template_type_parameters = null,
string $called_fq_classlike_name = null,
string $called_method_name_lowercase = null
) : ?Union {
if (!$source instanceof \Psalm\Internal\Analyzer\StatementsAnalyzer) {
return null;
}

View File

@ -18,8 +18,13 @@ final class UrlReturnTypeProvider implements FunctionReturnTypeProviderInterface
return ['url'];
}
public static function getFunctionReturnType(StatementsSource $statements_source, string $function_id, array $call_args, Context $context, CodeLocation $code_location)
{
public static function getFunctionReturnType(
StatementsSource $statements_source,
string $function_id,
array $call_args,
Context $context,
CodeLocation $code_location
) : ?Union {
if (!$call_args) {
return new Union([
new TNamedObject(UrlGenerator::class),