2019-03-04 04:20:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Psalm\LaravelPlugin;
|
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\Context;
|
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Type;
|
|
|
|
use Psalm\StatementsSource;
|
2020-07-26 00:38:50 +02:00
|
|
|
use function get_class;
|
2019-03-04 04:20:10 +01:00
|
|
|
|
|
|
|
class AppInterfaceProvider implements
|
|
|
|
\Psalm\Plugin\Hook\MethodReturnTypeProviderInterface,
|
|
|
|
\Psalm\Plugin\Hook\MethodExistenceProviderInterface,
|
|
|
|
\Psalm\Plugin\Hook\MethodVisibilityProviderInterface,
|
|
|
|
\Psalm\Plugin\Hook\MethodParamsProviderInterface
|
|
|
|
{
|
2020-01-08 06:10:08 +01:00
|
|
|
/** @return array<string> */
|
2019-03-04 04:20:10 +01:00
|
|
|
public static function getClassLikeNames() : array
|
|
|
|
{
|
2019-03-04 17:45:36 +01:00
|
|
|
return [
|
|
|
|
\Illuminate\Contracts\Foundation\Application::class,
|
|
|
|
\Illuminate\Contracts\Container\Container::class
|
|
|
|
];
|
2019-03-04 04:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ?bool
|
|
|
|
*/
|
|
|
|
public static function doesMethodExist(
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lowercase,
|
|
|
|
StatementsSource $source = null,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
if ($method_name_lowercase === 'offsetget'
|
|
|
|
|| $method_name_lowercase === 'offsetset'
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ?bool
|
|
|
|
*/
|
|
|
|
public static function isMethodVisible(
|
|
|
|
StatementsSource $source,
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lowercase,
|
|
|
|
Context $context,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
if ($method_name_lowercase === 'offsetget'
|
|
|
|
|| $method_name_lowercase === 'offsetset'
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<PhpParser\Node\Arg> $call_args
|
|
|
|
* @return ?array<int, \Psalm\Storage\FunctionLikeParameter>
|
|
|
|
*/
|
|
|
|
public static function getMethodParams(
|
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lowercase,
|
|
|
|
array $call_args = null,
|
|
|
|
StatementsSource $statements_source = null,
|
|
|
|
Context $context = null,
|
|
|
|
CodeLocation $code_location = null
|
|
|
|
) {
|
|
|
|
if ($statements_source) {
|
|
|
|
if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset') {
|
|
|
|
return $statements_source->getCodebase()->getMethodParams(
|
2020-07-26 00:38:50 +02:00
|
|
|
get_class(ApplicationHelper::getApp()) . '::' . $method_name_lowercase
|
2019-03-04 04:20:10 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<PhpParser\Node\Arg> $call_args
|
|
|
|
* @return ?Type\Union
|
|
|
|
*/
|
|
|
|
public static function getMethodReturnType(
|
2019-03-19 15:01:11 +01:00
|
|
|
StatementsSource $source,
|
2019-03-04 04:20:10 +01:00
|
|
|
string $fq_classlike_name,
|
|
|
|
string $method_name_lowercase,
|
|
|
|
array $call_args,
|
|
|
|
Context $context,
|
2019-03-19 15:01:11 +01:00
|
|
|
CodeLocation $code_location,
|
|
|
|
array $template_type_parameters = null,
|
|
|
|
string $called_fq_classlike_name = null,
|
|
|
|
string $called_method_name_lowercase = null
|
2019-03-04 04:20:10 +01:00
|
|
|
) {
|
2020-01-06 00:46:59 +01:00
|
|
|
if ($method_name_lowercase === 'offsetget' || $method_name_lowercase === 'offsetset') {
|
|
|
|
return $source->getCodebase()->getMethodReturnType(
|
2020-07-26 00:38:50 +02:00
|
|
|
get_class(ApplicationHelper::getApp()) . '::' . $method_name_lowercase,
|
2020-01-06 00:46:59 +01:00
|
|
|
$fq_classlike_name
|
|
|
|
);
|
2019-03-04 04:20:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|