2016-08-14 05:26:45 +02:00
|
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
|
namespace Psalm\Internal\Analyzer;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2017-05-19 06:48:26 +02:00
|
|
|
|
use PhpParser;
|
2016-10-15 06:12:57 +02:00
|
|
|
|
use PhpParser\Node\Expr\Closure;
|
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
2016-11-02 07:29:00 +01:00
|
|
|
|
use PhpParser\Node\Stmt\Function_;
|
2018-11-06 03:57:36 +01:00
|
|
|
|
use Psalm\Codebase;
|
|
|
|
|
use Psalm\Internal\Analyzer\FunctionLike\ReturnTypeAnalyzer;
|
|
|
|
|
use Psalm\Internal\Analyzer\FunctionLike\ReturnTypeCollector;
|
|
|
|
|
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
|
2017-05-19 06:48:26 +02:00
|
|
|
|
use Psalm\CodeLocation;
|
2016-11-02 07:29:00 +01:00
|
|
|
|
use Psalm\Context;
|
2018-11-12 16:46:55 +01:00
|
|
|
|
use Psalm\Internal\FileManipulation\FunctionDocblockManipulator;
|
2019-02-27 22:00:44 +01:00
|
|
|
|
use Psalm\Issue\InvalidDocblockParamName;
|
2016-12-31 05:40:32 +01:00
|
|
|
|
use Psalm\Issue\InvalidParamDefault;
|
2018-01-05 18:11:12 +01:00
|
|
|
|
use Psalm\Issue\MismatchingDocblockParamType;
|
2018-01-29 02:03:47 +01:00
|
|
|
|
use Psalm\Issue\MissingClosureParamType;
|
|
|
|
|
use Psalm\Issue\MissingParamType;
|
2018-06-22 07:13:49 +02:00
|
|
|
|
use Psalm\Issue\MissingThrowsDocblock;
|
2019-03-03 21:11:09 +01:00
|
|
|
|
use Psalm\Issue\ReferenceConstraintViolation;
|
2018-01-10 06:07:47 +01:00
|
|
|
|
use Psalm\Issue\ReservedWord;
|
2019-03-05 21:45:09 +01:00
|
|
|
|
use Psalm\Issue\UnusedClosureParam;
|
2017-12-29 23:27:16 +01:00
|
|
|
|
use Psalm\Issue\UnusedParam;
|
2016-11-02 07:29:00 +01:00
|
|
|
|
use Psalm\IssueBuffer;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
use Psalm\StatementsSource;
|
2018-05-12 00:35:02 +02:00
|
|
|
|
use Psalm\Storage\FunctionLikeParameter;
|
2017-09-04 02:52:54 +02:00
|
|
|
|
use Psalm\Storage\FunctionLikeStorage;
|
2017-01-06 07:07:11 +01:00
|
|
|
|
use Psalm\Storage\MethodStorage;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
use Psalm\Type;
|
2017-01-15 01:06:58 +01:00
|
|
|
|
use Psalm\Type\Atomic\TNamedObject;
|
2019-06-26 22:52:29 +02:00
|
|
|
|
use function md5;
|
|
|
|
|
use function explode;
|
|
|
|
|
use function strtolower;
|
|
|
|
|
use function array_merge;
|
|
|
|
|
use function array_filter;
|
|
|
|
|
use function is_string;
|
|
|
|
|
use function array_key_exists;
|
|
|
|
|
use function substr;
|
|
|
|
|
use function strpos;
|
|
|
|
|
use function array_search;
|
|
|
|
|
use function array_keys;
|
|
|
|
|
use function end;
|
|
|
|
|
use function array_diff;
|
2019-08-14 06:47:57 +02:00
|
|
|
|
use Psalm\Internal\Taint\Source;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
|
abstract class FunctionLikeAnalyzer extends SourceAnalyzer implements StatementsSource
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
2016-10-14 06:53:43 +02:00
|
|
|
|
/**
|
2016-10-15 06:12:57 +02:00
|
|
|
|
* @var Closure|Function_|ClassMethod
|
2016-10-14 06:53:43 +02:00
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected $function;
|
2016-10-14 06:53:43 +02:00
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
/**
|
|
|
|
|
* @var Codebase
|
|
|
|
|
*/
|
|
|
|
|
protected $codebase;
|
|
|
|
|
|
2016-10-14 06:53:43 +02:00
|
|
|
|
/**
|
2017-01-07 20:35:07 +01:00
|
|
|
|
* @var array<string>
|
2016-10-14 06:53:43 +02:00
|
|
|
|
*/
|
2017-01-07 20:35:07 +01:00
|
|
|
|
protected $suppressed_issues;
|
2016-10-14 06:53:43 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected $is_static = false;
|
2016-10-14 06:53:43 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var StatementsSource
|
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected $source;
|
2016-10-14 06:53:43 +02:00
|
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
|
/**
|
2019-03-06 17:12:36 +01:00
|
|
|
|
* @var ?array<string, Type\Union>
|
2016-10-15 06:12:57 +02:00
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected $return_vars_in_scope = [];
|
2016-10-15 06:12:57 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2019-03-06 17:12:36 +01:00
|
|
|
|
* @var ?array<string, bool>
|
2016-10-15 06:12:57 +02:00
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected $return_vars_possibly_in_scope = [];
|
2016-11-01 05:39:41 +01:00
|
|
|
|
|
2018-01-14 18:09:40 +01:00
|
|
|
|
/**
|
|
|
|
|
* @var Type\Union|null
|
|
|
|
|
*/
|
|
|
|
|
private $local_return_type;
|
|
|
|
|
|
2016-11-01 05:39:41 +01:00
|
|
|
|
/**
|
2019-01-31 18:55:48 +01:00
|
|
|
|
* @var array<string, bool>
|
2016-11-01 05:39:41 +01:00
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
protected static $no_effects_hashes = [];
|
|
|
|
|
|
2018-12-18 05:29:27 +01:00
|
|
|
|
/**
|
2019-06-16 15:12:32 +02:00
|
|
|
|
* @var FunctionLikeStorage
|
2018-12-18 05:29:27 +01:00
|
|
|
|
*/
|
|
|
|
|
protected $storage;
|
|
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param Closure|Function_|ClassMethod $function
|
2018-11-06 03:57:36 +01:00
|
|
|
|
* @param SourceAnalyzer $source
|
2016-10-15 06:12:57 +02:00
|
|
|
|
*/
|
2018-12-18 05:29:27 +01:00
|
|
|
|
protected function __construct($function, SourceAnalyzer $source, FunctionLikeStorage $storage)
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
|
|
|
|
$this->function = $function;
|
|
|
|
|
$this->source = $source;
|
|
|
|
|
$this->suppressed_issues = $source->getSuppressedIssues();
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$this->codebase = $source->getCodebase();
|
2018-12-18 05:29:27 +01:00
|
|
|
|
$this->storage = $storage;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
|
/**
|
2016-11-05 22:53:30 +01:00
|
|
|
|
* @param Context $context
|
|
|
|
|
* @param Context|null $global_context
|
2017-01-12 03:37:53 +01:00
|
|
|
|
* @param bool $add_mutations whether or not to add mutations to this method
|
2019-03-10 21:36:35 +01:00
|
|
|
|
* @param ?array<string, bool> $byref_uses
|
2017-05-27 02:16:18 +02:00
|
|
|
|
*
|
2016-11-02 07:29:00 +01:00
|
|
|
|
* @return false|null
|
|
|
|
|
*/
|
2019-03-10 21:36:35 +01:00
|
|
|
|
public function analyze(
|
|
|
|
|
Context $context,
|
|
|
|
|
Context $global_context = null,
|
|
|
|
|
$add_mutations = false,
|
|
|
|
|
array $byref_uses = null
|
|
|
|
|
) {
|
2018-12-18 05:29:27 +01:00
|
|
|
|
$storage = $this->storage;
|
|
|
|
|
|
2016-12-07 20:13:39 +01:00
|
|
|
|
$function_stmts = $this->function->getStmts() ?: [];
|
2016-09-02 00:02:09 +02:00
|
|
|
|
|
2016-12-07 20:13:39 +01:00
|
|
|
|
$hash = null;
|
2018-04-25 20:45:51 +02:00
|
|
|
|
$real_method_id = null;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2017-01-06 07:07:11 +01:00
|
|
|
|
$cased_method_id = null;
|
2016-11-02 07:29:00 +01:00
|
|
|
|
|
2017-02-10 02:35:17 +01:00
|
|
|
|
$class_storage = null;
|
|
|
|
|
|
2017-01-15 21:58:40 +01:00
|
|
|
|
if ($global_context) {
|
|
|
|
|
foreach ($global_context->constants as $const_name => $var_type) {
|
2017-02-01 05:24:33 +01:00
|
|
|
|
if (!$context->hasVariable($const_name)) {
|
2017-01-15 21:58:40 +01:00
|
|
|
|
$context->vars_in_scope[$const_name] = clone $var_type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$codebase = $this->codebase;
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$project_analyzer = $this->getProjectAnalyzer();
|
2017-07-29 21:05:06 +02:00
|
|
|
|
|
2017-12-03 18:44:08 +01:00
|
|
|
|
$implemented_docblock_param_types = [];
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$classlike_storage_provider = $codebase->classlike_storage_provider;
|
2017-12-29 23:27:16 +01:00
|
|
|
|
|
2019-08-18 23:18:03 +02:00
|
|
|
|
if ($codebase->track_unused_suppressions && !isset($storage->suppressed_issues[0])) {
|
2019-08-18 20:44:45 +02:00
|
|
|
|
foreach ($storage->suppressed_issues as $offset => $issue_name) {
|
|
|
|
|
IssueBuffer::addUnusedSuppression($this->getFilePath(), $offset, $issue_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:28:25 +01:00
|
|
|
|
$overridden_method_ids = [];
|
|
|
|
|
|
2017-01-06 07:07:11 +01:00
|
|
|
|
if ($this->function instanceof ClassMethod) {
|
2018-12-18 05:29:27 +01:00
|
|
|
|
if (!$storage instanceof MethodStorage) {
|
|
|
|
|
throw new \UnexpectedValueException('$storage must be MethodStorage');
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 06:54:41 +01:00
|
|
|
|
$real_method_id = (string)$this->getMethodId();
|
|
|
|
|
|
|
|
|
|
$method_id = (string)$this->getMethodId($context->self);
|
|
|
|
|
|
2017-01-12 03:37:53 +01:00
|
|
|
|
if ($add_mutations) {
|
2019-01-31 18:55:48 +01:00
|
|
|
|
$hash = md5($real_method_id . '::' . $context->getScopeSummary());
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2016-12-07 20:13:39 +01:00
|
|
|
|
// if we know that the function has no effects on vars, we don't bother rechecking
|
|
|
|
|
if (isset(self::$no_effects_hashes[$hash])) {
|
|
|
|
|
return null;
|
2016-11-07 05:29:54 +01:00
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
} elseif ($context->self) {
|
2017-01-15 01:06:58 +01:00
|
|
|
|
$context->vars_in_scope['$this'] = new Type\Union([new TNamedObject($context->self)]);
|
2017-02-08 08:23:17 +01:00
|
|
|
|
$context->vars_possibly_in_scope['$this'] = true;
|
2016-12-07 20:13:39 +01:00
|
|
|
|
}
|
2016-11-07 05:29:54 +01:00
|
|
|
|
|
2017-01-06 07:07:11 +01:00
|
|
|
|
$fq_class_name = (string)$context->self;
|
2016-11-05 03:04:55 +01:00
|
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
|
$class_storage = $classlike_storage_provider->get($fq_class_name);
|
|
|
|
|
|
2018-12-18 05:29:27 +01:00
|
|
|
|
if ($class_storage->has_visitor_issues) {
|
|
|
|
|
return null;
|
2018-01-25 07:04:26 +01:00
|
|
|
|
}
|
2017-01-06 07:07:11 +01:00
|
|
|
|
|
|
|
|
|
$cased_method_id = $fq_class_name . '::' . $storage->cased_name;
|
2016-12-30 18:41:14 +01:00
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
|
$overridden_method_ids = $codebase->methods->getOverriddenMethodIds($method_id);
|
2016-10-18 22:00:03 +02:00
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
|
if ($this->function->name->name === '__construct') {
|
2017-04-15 05:26:58 +02:00
|
|
|
|
$context->inside_constructor = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 19:36:18 +02:00
|
|
|
|
$codeLocation = new CodeLocation(
|
|
|
|
|
$this,
|
|
|
|
|
$this->function,
|
|
|
|
|
null,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
2018-03-13 23:11:57 +01:00
|
|
|
|
if ($overridden_method_ids
|
2018-04-17 18:16:25 +02:00
|
|
|
|
&& $this->function->name->name !== '__construct'
|
2018-03-13 23:11:57 +01:00
|
|
|
|
&& !$context->collect_initializations
|
|
|
|
|
&& !$context->collect_mutations
|
|
|
|
|
) {
|
2017-11-26 22:03:17 +01:00
|
|
|
|
foreach ($overridden_method_ids as $overridden_method_id) {
|
2018-02-04 00:52:35 +01:00
|
|
|
|
$parent_method_storage = $codebase->methods->getStorage($overridden_method_id);
|
2017-01-13 18:03:22 +01:00
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
|
list($overridden_fq_class_name) = explode('::', $overridden_method_id);
|
2016-12-07 20:13:39 +01:00
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
|
$parent_storage = $classlike_storage_provider->get($overridden_fq_class_name);
|
2016-12-07 20:13:39 +01:00
|
|
|
|
|
2019-01-16 16:59:06 +01:00
|
|
|
|
$implementer_visibility = $storage->visibility;
|
|
|
|
|
|
|
|
|
|
$implementer_appearing_method_id = $codebase->methods->getAppearingMethodId($cased_method_id);
|
|
|
|
|
$implementer_declaring_method_id = $real_method_id;
|
|
|
|
|
|
|
|
|
|
if ($implementer_appearing_method_id
|
|
|
|
|
&& $implementer_appearing_method_id !== $implementer_declaring_method_id
|
|
|
|
|
) {
|
|
|
|
|
list($appearing_fq_class_name, $appearing_method_name) = explode(
|
|
|
|
|
'::',
|
|
|
|
|
$implementer_appearing_method_id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$appearing_class_storage = $classlike_storage_provider->get(
|
|
|
|
|
$appearing_fq_class_name
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isset($appearing_class_storage->trait_visibility_map[$appearing_method_name])) {
|
|
|
|
|
$implementer_visibility
|
|
|
|
|
= $appearing_class_storage->trait_visibility_map[$appearing_method_name];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 21:03:13 +01:00
|
|
|
|
// we've already checked this in the class checker
|
|
|
|
|
if (!isset($class_storage->class_implements[strtolower($overridden_fq_class_name)])) {
|
|
|
|
|
MethodAnalyzer::compareMethods(
|
|
|
|
|
$codebase,
|
|
|
|
|
$class_storage,
|
|
|
|
|
$parent_storage,
|
|
|
|
|
$storage,
|
|
|
|
|
$parent_method_storage,
|
|
|
|
|
$fq_class_name,
|
|
|
|
|
$implementer_visibility,
|
|
|
|
|
$codeLocation,
|
|
|
|
|
$storage->suppressed_issues
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-02-09 23:49:13 +01:00
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
|
foreach ($parent_method_storage->params as $i => $guide_param) {
|
2018-12-21 17:01:24 +01:00
|
|
|
|
if ($guide_param->type
|
|
|
|
|
&& (!$guide_param->signature_type
|
|
|
|
|
|| ($guide_param->signature_type !== $guide_param->type
|
|
|
|
|
&& $storage->inheritdoc)
|
|
|
|
|
|| !$parent_storage->user_defined
|
|
|
|
|
)
|
|
|
|
|
) {
|
2019-01-04 14:37:54 +01:00
|
|
|
|
if (!isset($implemented_docblock_param_types[$i])) {
|
|
|
|
|
$implemented_docblock_param_types[$i] = $guide_param->type;
|
|
|
|
|
}
|
2017-09-02 17:18:56 +02:00
|
|
|
|
}
|
2017-01-13 18:03:22 +01:00
|
|
|
|
}
|
2016-10-16 00:01:04 +02:00
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
}
|
2018-04-21 19:36:18 +02:00
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
MethodAnalyzer::checkMethodSignatureMustOmitReturnType($storage, $codeLocation);
|
2018-09-26 00:37:24 +02:00
|
|
|
|
|
|
|
|
|
$context->calling_method_id = strtolower($method_id);
|
2017-01-06 07:07:11 +01:00
|
|
|
|
} elseif ($this->function instanceof Function_) {
|
2019-08-04 16:37:36 +02:00
|
|
|
|
$cased_method_id = $this->function->name->name;
|
2017-01-06 07:07:11 +01:00
|
|
|
|
} else { // Closure
|
2017-11-22 03:50:39 +01:00
|
|
|
|
if ($storage->return_type) {
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$closure_return_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
2017-11-22 03:50:39 +01:00
|
|
|
|
$storage->return_type,
|
|
|
|
|
$context->self,
|
2019-05-25 17:51:09 +02:00
|
|
|
|
$context->self,
|
|
|
|
|
$this->getParentFQCLN()
|
2017-11-22 03:50:39 +01:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$closure_return_type = Type::getMixed();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 01:19:25 +01:00
|
|
|
|
/** @var PhpParser\Node\Expr\Closure $this->function */
|
2016-12-07 20:13:39 +01:00
|
|
|
|
$this->function->inferredType = new Type\Union([
|
2019-06-03 12:19:52 +02:00
|
|
|
|
new Type\Atomic\TFn(
|
2016-12-07 20:13:39 +01:00
|
|
|
|
'Closure',
|
2017-01-06 07:07:11 +01:00
|
|
|
|
$storage->params,
|
2017-11-22 03:50:39 +01:00
|
|
|
|
$closure_return_type
|
2017-05-27 02:05:57 +02:00
|
|
|
|
),
|
2016-12-07 20:13:39 +01:00
|
|
|
|
]);
|
|
|
|
|
}
|
2016-09-02 00:02:09 +02:00
|
|
|
|
|
2019-08-18 18:25:48 +02:00
|
|
|
|
$this->suppressed_issues = $this->getSource()->getSuppressedIssues() + $storage->suppressed_issues;
|
2017-01-06 07:07:11 +01:00
|
|
|
|
|
|
|
|
|
if ($storage instanceof MethodStorage && $storage->is_static) {
|
|
|
|
|
$this->is_static = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$statements_analyzer = new StatementsAnalyzer($this);
|
2017-01-06 07:07:11 +01:00
|
|
|
|
|
2019-03-10 21:36:35 +01:00
|
|
|
|
if ($byref_uses) {
|
|
|
|
|
$statements_analyzer->setByRefUses($byref_uses);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-22 03:54:00 +01:00
|
|
|
|
if ($storage->template_types) {
|
|
|
|
|
foreach ($storage->template_types as $param_name => $_) {
|
|
|
|
|
$fq_classlike_name = Type::getFQCLNFromString(
|
|
|
|
|
$param_name,
|
|
|
|
|
$this->getAliases()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($codebase->classOrInterfaceExists($fq_classlike_name)) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new ReservedWord(
|
|
|
|
|
'Cannot use ' . $param_name . ' as template name since the class already exists',
|
|
|
|
|
new CodeLocation($this, $this->function),
|
|
|
|
|
'resource'
|
|
|
|
|
),
|
|
|
|
|
$this->getSuppressedIssues()
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 02:35:17 +01:00
|
|
|
|
$template_types = $storage->template_types;
|
|
|
|
|
|
|
|
|
|
if ($class_storage && $class_storage->template_types) {
|
|
|
|
|
$template_types = array_merge($template_types ?: [], $class_storage->template_types);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:28:25 +01:00
|
|
|
|
$params = $storage->params;
|
|
|
|
|
|
|
|
|
|
if ($storage instanceof MethodStorage) {
|
2019-01-31 23:48:48 +01:00
|
|
|
|
$non_null_param_types = array_filter(
|
|
|
|
|
$storage->params,
|
|
|
|
|
/** @return bool */
|
|
|
|
|
function (FunctionLikeParameter $p) {
|
|
|
|
|
return $p->type !== null && $p->has_docblock_type;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$non_null_param_types = array_filter(
|
|
|
|
|
$storage->params,
|
|
|
|
|
/** @return bool */
|
|
|
|
|
function (FunctionLikeParameter $p) {
|
|
|
|
|
return $p->type !== null;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-10-08 19:07:28 +02:00
|
|
|
|
|
2019-03-21 23:28:25 +01:00
|
|
|
|
if ($storage instanceof MethodStorage
|
|
|
|
|
&& is_string($cased_method_id)
|
|
|
|
|
&& $overridden_method_ids
|
|
|
|
|
) {
|
|
|
|
|
$types_without_docblocks = array_filter(
|
|
|
|
|
$storage->params,
|
|
|
|
|
/** @return bool */
|
|
|
|
|
function (FunctionLikeParameter $p) {
|
|
|
|
|
return !$p->type || !$p->has_docblock_type;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($types_without_docblocks) {
|
|
|
|
|
$params = $codebase->methods->getMethodParams($cased_method_id, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 18:59:12 +01:00
|
|
|
|
$check_stmts = true;
|
|
|
|
|
|
2019-06-04 22:36:32 +02:00
|
|
|
|
if ($codebase->alter_code) {
|
2019-06-01 16:32:49 +02:00
|
|
|
|
foreach ($this->function->params as $param) {
|
|
|
|
|
$param_name_node = null;
|
|
|
|
|
|
|
|
|
|
if ($param->type instanceof PhpParser\Node\Name) {
|
|
|
|
|
$param_name_node = $param->type;
|
|
|
|
|
} elseif ($param->type instanceof PhpParser\Node\NullableType
|
|
|
|
|
&& $param->type->type instanceof PhpParser\Node\Name
|
|
|
|
|
) {
|
|
|
|
|
$param_name_node = $param->type->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($param_name_node) {
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$resolved_name = ClassLikeAnalyzer::getFQCLNFromNameObject($param_name_node, $this->getAliases());
|
2019-06-01 16:32:49 +02:00
|
|
|
|
|
|
|
|
|
$parent_fqcln = $this->getParentFQCLN();
|
|
|
|
|
|
|
|
|
|
if ($resolved_name === 'self' && $context->self) {
|
|
|
|
|
$resolved_name = (string) $context->self;
|
|
|
|
|
} elseif ($resolved_name === 'parent' && $parent_fqcln) {
|
|
|
|
|
$resolved_name = $parent_fqcln;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$codebase->classlikes->handleClassLikeReferenceInMigration(
|
|
|
|
|
$codebase,
|
|
|
|
|
$this,
|
|
|
|
|
$param_name_node,
|
2019-06-01 16:32:49 +02:00
|
|
|
|
$resolved_name,
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$context->calling_method_id
|
2019-06-01 16:32:49 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-01 19:02:20 +02:00
|
|
|
|
|
|
|
|
|
if ($this->function->returnType) {
|
|
|
|
|
$return_name_node = null;
|
|
|
|
|
|
|
|
|
|
if ($this->function->returnType instanceof PhpParser\Node\Name) {
|
|
|
|
|
$return_name_node = $this->function->returnType;
|
|
|
|
|
} elseif ($this->function->returnType instanceof PhpParser\Node\NullableType
|
|
|
|
|
&& $this->function->returnType->type instanceof PhpParser\Node\Name
|
|
|
|
|
) {
|
|
|
|
|
$return_name_node = $this->function->returnType->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($return_name_node) {
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$resolved_name = ClassLikeAnalyzer::getFQCLNFromNameObject($return_name_node, $this->getAliases());
|
2019-06-01 19:02:20 +02:00
|
|
|
|
|
|
|
|
|
$parent_fqcln = $this->getParentFQCLN();
|
|
|
|
|
|
|
|
|
|
if ($resolved_name === 'self' && $context->self) {
|
|
|
|
|
$resolved_name = (string) $context->self;
|
|
|
|
|
} elseif ($resolved_name === 'parent' && $parent_fqcln) {
|
|
|
|
|
$resolved_name = $parent_fqcln;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$codebase->classlikes->handleClassLikeReferenceInMigration(
|
|
|
|
|
$codebase,
|
|
|
|
|
$this,
|
|
|
|
|
$return_name_node,
|
2019-06-01 19:02:20 +02:00
|
|
|
|
$resolved_name,
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$context->calling_method_id
|
2019-06-01 19:02:20 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($storage->return_type
|
|
|
|
|
&& $storage->return_type_location
|
|
|
|
|
&& $storage->return_type_location !== $storage->signature_return_type_location
|
|
|
|
|
) {
|
|
|
|
|
$replace_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
|
|
|
|
$storage->return_type,
|
|
|
|
|
$context->self,
|
|
|
|
|
$context->self,
|
2019-06-07 00:46:40 +02:00
|
|
|
|
$this->getParentFQCLN(),
|
|
|
|
|
false
|
2019-06-01 19:02:20 +02:00
|
|
|
|
);
|
|
|
|
|
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$codebase->classlikes->handleDocblockTypeInMigration(
|
|
|
|
|
$codebase,
|
|
|
|
|
$this,
|
2019-06-01 19:02:20 +02:00
|
|
|
|
$replace_type,
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$storage->return_type_location,
|
|
|
|
|
$context->calling_method_id
|
2019-06-01 19:02:20 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
2019-06-01 22:57:33 +02:00
|
|
|
|
|
|
|
|
|
foreach ($params as $function_param) {
|
|
|
|
|
if ($function_param->type
|
|
|
|
|
&& $function_param->type_location
|
|
|
|
|
&& $function_param->type_location !== $function_param->signature_type_location
|
2019-06-06 01:32:27 +02:00
|
|
|
|
&& $function_param->type_location->file_path === $this->getFilePath()
|
2019-06-01 22:57:33 +02:00
|
|
|
|
) {
|
|
|
|
|
$replace_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
|
|
|
|
$function_param->type,
|
|
|
|
|
$context->self,
|
|
|
|
|
$context->self,
|
2019-06-07 00:46:40 +02:00
|
|
|
|
$this->getParentFQCLN(),
|
|
|
|
|
false
|
2019-06-01 22:57:33 +02:00
|
|
|
|
);
|
|
|
|
|
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$codebase->classlikes->handleDocblockTypeInMigration(
|
|
|
|
|
$codebase,
|
|
|
|
|
$this,
|
2019-06-01 22:57:33 +02:00
|
|
|
|
$replace_type,
|
2019-06-04 22:36:32 +02:00
|
|
|
|
$function_param->type_location,
|
|
|
|
|
$context->calling_method_id
|
2019-06-01 22:57:33 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-01 16:32:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 18:02:32 +02:00
|
|
|
|
foreach ($codebase->methods_to_rename as $original_method_id => $new_method_name) {
|
|
|
|
|
if ($this->function instanceof ClassMethod
|
|
|
|
|
&& strtolower($this->getMethodId()) === $original_method_id
|
|
|
|
|
) {
|
|
|
|
|
$file_manipulations = [
|
|
|
|
|
new \Psalm\FileManipulation(
|
|
|
|
|
(int) $this->function->name->getAttribute('startFilePos'),
|
|
|
|
|
(int) $this->function->name->getAttribute('endFilePos') + 1,
|
|
|
|
|
$new_method_name
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
\Psalm\Internal\FileManipulation\FileManipulationBuffer::add(
|
|
|
|
|
$this->getFilePath(),
|
|
|
|
|
$file_manipulations
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 23:28:25 +01:00
|
|
|
|
foreach ($params as $offset => $function_param) {
|
2017-07-25 22:11:02 +02:00
|
|
|
|
$signature_type = $function_param->signature_type;
|
2018-10-26 22:17:15 +02:00
|
|
|
|
$signature_type_location = $function_param->signature_type_location;
|
|
|
|
|
|
2019-02-24 07:33:25 +01:00
|
|
|
|
if ($signature_type && $signature_type_location && $signature_type->hasObjectType()) {
|
2018-10-26 22:17:15 +02:00
|
|
|
|
list($start, $end) = $signature_type_location->getSelectionBounds();
|
|
|
|
|
|
|
|
|
|
$codebase->analyzer->addOffsetReference(
|
|
|
|
|
$this->getFilePath(),
|
|
|
|
|
$start,
|
|
|
|
|
$end,
|
|
|
|
|
(string) $signature_type
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-02-01 05:27:25 +01:00
|
|
|
|
|
2019-03-17 16:31:04 +01:00
|
|
|
|
if ($signature_type) {
|
|
|
|
|
$signature_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
|
|
|
|
$signature_type,
|
|
|
|
|
$context->self,
|
2019-05-25 17:51:09 +02:00
|
|
|
|
$context->self,
|
|
|
|
|
$this->getParentFQCLN()
|
2019-03-17 16:31:04 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2018-05-21 06:46:56 +02:00
|
|
|
|
|
2019-03-17 16:31:04 +01:00
|
|
|
|
if ($function_param->type) {
|
2018-12-21 17:01:24 +01:00
|
|
|
|
$is_signature_type = $function_param->type === $function_param->signature_type;
|
|
|
|
|
|
|
|
|
|
if ($is_signature_type
|
|
|
|
|
&& $storage instanceof MethodStorage
|
|
|
|
|
&& $storage->inheritdoc
|
|
|
|
|
&& isset($implemented_docblock_param_types[$offset])
|
|
|
|
|
) {
|
|
|
|
|
$param_type = clone $implemented_docblock_param_types[$offset];
|
|
|
|
|
} else {
|
|
|
|
|
$param_type = clone $function_param->type;
|
|
|
|
|
}
|
2017-09-02 17:18:56 +02:00
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$param_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
2017-09-02 17:18:56 +02:00
|
|
|
|
$param_type,
|
|
|
|
|
$context->self,
|
2019-05-25 17:51:09 +02:00
|
|
|
|
$context->self,
|
|
|
|
|
$this->getParentFQCLN()
|
2017-09-02 17:18:56 +02:00
|
|
|
|
);
|
2019-03-17 16:31:04 +01:00
|
|
|
|
|
|
|
|
|
if ($function_param->type_location) {
|
|
|
|
|
if ($param_type->check(
|
|
|
|
|
$this,
|
|
|
|
|
$function_param->type_location,
|
|
|
|
|
$storage->suppressed_issues,
|
|
|
|
|
[],
|
2019-05-15 00:17:38 +02:00
|
|
|
|
false,
|
|
|
|
|
$this->function instanceof ClassMethod
|
|
|
|
|
&& strtolower($this->function->name->name) !== '__construct'
|
2019-03-17 16:31:04 +01:00
|
|
|
|
) === false) {
|
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-02 17:18:56 +02:00
|
|
|
|
} else {
|
2018-10-08 19:07:28 +02:00
|
|
|
|
if (!$non_null_param_types && isset($implemented_docblock_param_types[$offset])) {
|
2018-10-06 20:00:45 +02:00
|
|
|
|
$param_type = clone $implemented_docblock_param_types[$offset];
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$param_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$codebase,
|
2018-10-06 20:00:45 +02:00
|
|
|
|
$param_type,
|
|
|
|
|
$context->self,
|
2019-05-25 17:51:09 +02:00
|
|
|
|
$context->self,
|
|
|
|
|
$this->getParentFQCLN()
|
2018-10-06 20:00:45 +02:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$param_type = Type::getMixed();
|
|
|
|
|
}
|
2017-09-02 17:18:56 +02:00
|
|
|
|
}
|
2016-12-04 01:11:30 +01:00
|
|
|
|
|
2019-04-09 19:58:49 +02:00
|
|
|
|
$var_type = $param_type;
|
|
|
|
|
|
|
|
|
|
if ($function_param->is_variadic) {
|
|
|
|
|
$var_type = new Type\Union([
|
|
|
|
|
new Type\Atomic\TArray([
|
|
|
|
|
Type::getInt(),
|
|
|
|
|
$param_type,
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 16:37:36 +02:00
|
|
|
|
if ($cased_method_id && $codebase->taint) {
|
2019-08-14 06:47:57 +02:00
|
|
|
|
$type_source = Source::getForMethodArgument(
|
2019-08-06 00:33:33 +02:00
|
|
|
|
$cased_method_id,
|
|
|
|
|
$offset,
|
|
|
|
|
$function_param->location,
|
|
|
|
|
null
|
|
|
|
|
);
|
2019-08-04 16:37:36 +02:00
|
|
|
|
$var_type->sources = [$type_source];
|
|
|
|
|
|
2019-08-13 05:16:05 +02:00
|
|
|
|
if ($tainted_source = $codebase->taint->hasExistingSource($type_source)) {
|
|
|
|
|
$var_type->tainted = $tainted_source->taint;
|
|
|
|
|
$type_source->taint = $tainted_source->taint;
|
2019-08-04 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 19:58:49 +02:00
|
|
|
|
$context->vars_in_scope['$' . $function_param->name] = $var_type;
|
2017-07-09 03:19:16 +02:00
|
|
|
|
$context->vars_possibly_in_scope['$' . $function_param->name] = true;
|
|
|
|
|
|
2018-01-25 07:04:26 +01:00
|
|
|
|
if ($context->collect_references && $function_param->location) {
|
2018-06-17 02:01:33 +02:00
|
|
|
|
$context->unreferenced_vars['$' . $function_param->name] = [
|
|
|
|
|
$function_param->location->getHash() => $function_param->location
|
|
|
|
|
];
|
2018-01-25 07:04:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
|
/**
|
|
|
|
|
* @var PhpParser\Node\Param
|
|
|
|
|
*/
|
2016-12-31 05:40:32 +01:00
|
|
|
|
$parser_param = $this->function->getParams()[$offset];
|
|
|
|
|
|
2019-06-07 20:24:15 +02:00
|
|
|
|
if (!$function_param->type_location || !$function_param->location) {
|
|
|
|
|
if ($parser_param->default) {
|
|
|
|
|
ExpressionAnalyzer::analyze($statements_analyzer, $parser_param->default, $context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
|
if ($signature_type) {
|
2019-07-10 07:35:57 +02:00
|
|
|
|
$union_comparison_result = new TypeComparisonResult();
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
if (!TypeAnalyzer::isContainedBy(
|
2018-06-09 05:54:07 +02:00
|
|
|
|
$codebase,
|
|
|
|
|
$param_type,
|
|
|
|
|
$signature_type,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
2019-07-10 07:35:57 +02:00
|
|
|
|
$union_comparison_result
|
|
|
|
|
) && !$union_comparison_result->type_coerced_from_mixed
|
2017-07-25 22:11:02 +02:00
|
|
|
|
) {
|
2018-11-06 03:57:36 +01:00
|
|
|
|
if ($codebase->alter_code
|
2018-11-11 18:01:14 +01:00
|
|
|
|
&& isset($project_analyzer->getIssuesToFix()['MismatchingDocblockParamType'])
|
2018-01-07 16:23:02 +01:00
|
|
|
|
) {
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$this->addOrUpdateParamType($project_analyzer, $function_param->name, $signature_type, true);
|
2018-01-07 16:23:02 +01:00
|
|
|
|
|
2018-01-07 18:53:25 +01:00
|
|
|
|
continue;
|
2018-01-07 16:23:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
|
if (IssueBuffer::accepts(
|
2018-01-05 18:11:12 +01:00
|
|
|
|
new MismatchingDocblockParamType(
|
2017-07-25 22:11:02 +02:00
|
|
|
|
'Parameter $' . $function_param->name . ' has wrong type \'' . $param_type .
|
|
|
|
|
'\', should be \'' . $signature_type . '\'',
|
2018-01-07 06:11:23 +01:00
|
|
|
|
$function_param->type_location
|
2017-07-25 22:11:02 +02:00
|
|
|
|
),
|
|
|
|
|
$storage->suppressed_issues
|
|
|
|
|
)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 18:59:12 +01:00
|
|
|
|
if ($signature_type->check(
|
2018-01-10 04:46:55 +01:00
|
|
|
|
$this,
|
|
|
|
|
$function_param->type_location,
|
|
|
|
|
$storage->suppressed_issues,
|
|
|
|
|
[],
|
|
|
|
|
false
|
2019-01-05 18:59:12 +01:00
|
|
|
|
) === false) {
|
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
2018-01-10 04:46:55 +01:00
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-31 05:40:32 +01:00
|
|
|
|
if ($parser_param->default) {
|
2018-11-11 18:01:14 +01:00
|
|
|
|
ExpressionAnalyzer::analyze($statements_analyzer, $parser_param->default, $context);
|
2018-02-16 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
$default_type = isset($parser_param->default->inferredType)
|
|
|
|
|
? $parser_param->default->inferredType
|
|
|
|
|
: null;
|
2016-12-31 05:40:32 +01:00
|
|
|
|
|
2018-03-21 04:55:26 +01:00
|
|
|
|
if ($default_type
|
2018-12-08 19:18:55 +01:00
|
|
|
|
&& !$default_type->hasMixed()
|
2018-11-06 03:57:36 +01:00
|
|
|
|
&& !TypeAnalyzer::isContainedBy(
|
2018-02-01 06:50:01 +01:00
|
|
|
|
$codebase,
|
2017-01-02 21:31:18 +01:00
|
|
|
|
$default_type,
|
2019-06-25 15:06:23 +02:00
|
|
|
|
$param_type,
|
|
|
|
|
false,
|
|
|
|
|
false,
|
2019-07-10 07:35:57 +02:00
|
|
|
|
null,
|
2019-06-25 15:06:23 +02:00
|
|
|
|
true
|
2017-01-02 21:31:18 +01:00
|
|
|
|
)
|
|
|
|
|
) {
|
2016-12-31 05:40:32 +01:00
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new InvalidParamDefault(
|
2018-03-21 04:55:26 +01:00
|
|
|
|
'Default value type ' . $default_type . ' for argument ' . ($offset + 1)
|
|
|
|
|
. ' of method ' . $cased_method_id
|
|
|
|
|
. ' does not match the given type ' . $param_type,
|
2017-12-30 03:28:21 +01:00
|
|
|
|
$function_param->type_location
|
2016-12-31 05:40:32 +01:00
|
|
|
|
)
|
|
|
|
|
)) {
|
2016-12-31 06:14:00 +01:00
|
|
|
|
// fall through
|
2016-12-31 05:40:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 02:35:17 +01:00
|
|
|
|
if ($template_types) {
|
2017-02-10 06:14:44 +01:00
|
|
|
|
$substituted_type = clone $param_type;
|
2019-01-05 18:59:12 +01:00
|
|
|
|
if ($substituted_type->check(
|
2017-12-30 03:28:21 +01:00
|
|
|
|
$this->source,
|
|
|
|
|
$function_param->type_location,
|
|
|
|
|
$this->suppressed_issues,
|
|
|
|
|
[],
|
|
|
|
|
false
|
2019-01-05 18:59:12 +01:00
|
|
|
|
) === false) {
|
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
2017-02-10 02:35:17 +01:00
|
|
|
|
} else {
|
2018-01-10 06:07:47 +01:00
|
|
|
|
if ($param_type->isVoid()) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new ReservedWord(
|
|
|
|
|
'Parameter cannot be void',
|
2018-03-21 15:17:57 +01:00
|
|
|
|
$function_param->type_location,
|
|
|
|
|
'void'
|
2018-01-10 06:07:47 +01:00
|
|
|
|
),
|
|
|
|
|
$this->suppressed_issues
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-05 18:59:12 +01:00
|
|
|
|
if ($param_type->check(
|
2018-01-10 06:07:47 +01:00
|
|
|
|
$this->source,
|
|
|
|
|
$function_param->type_location,
|
|
|
|
|
$this->suppressed_issues,
|
|
|
|
|
[],
|
|
|
|
|
false
|
2019-01-05 18:59:12 +01:00
|
|
|
|
) === false) {
|
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
2017-03-02 00:36:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
|
if ($codebase->collect_references) {
|
2017-12-30 03:28:21 +01:00
|
|
|
|
if ($function_param->type_location !== $function_param->signature_type_location &&
|
|
|
|
|
$function_param->signature_type_location &&
|
2017-03-02 00:36:04 +01:00
|
|
|
|
$function_param->signature_type
|
|
|
|
|
) {
|
2019-01-05 18:59:12 +01:00
|
|
|
|
if ($function_param->signature_type->check(
|
2017-03-02 00:36:04 +01:00
|
|
|
|
$this->source,
|
2017-12-30 03:28:21 +01:00
|
|
|
|
$function_param->signature_type_location,
|
2017-03-02 18:19:18 +01:00
|
|
|
|
$this->suppressed_issues,
|
|
|
|
|
[],
|
|
|
|
|
false
|
2019-01-05 18:59:12 +01:00
|
|
|
|
) === false) {
|
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
2017-03-02 00:36:04 +01:00
|
|
|
|
}
|
2017-02-10 02:35:17 +01:00
|
|
|
|
}
|
2016-09-02 00:02:09 +02:00
|
|
|
|
|
2017-02-08 08:23:17 +01:00
|
|
|
|
if ($function_param->by_ref) {
|
|
|
|
|
// register by ref params as having been used, to avoid false positives
|
|
|
|
|
// @todo change the assignment analysis *just* for byref params
|
|
|
|
|
// so that we don't have to do this
|
|
|
|
|
$context->hasVariable('$' . $function_param->name);
|
|
|
|
|
}
|
2016-09-02 00:02:09 +02:00
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$statements_analyzer->registerVariable(
|
2017-02-08 08:23:17 +01:00
|
|
|
|
'$' . $function_param->name,
|
2018-01-21 22:24:20 +01:00
|
|
|
|
$function_param->location,
|
|
|
|
|
null
|
2016-12-07 20:13:39 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2019-07-18 07:31:48 +02:00
|
|
|
|
if ($storage->pure) {
|
|
|
|
|
$context->pure = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 22:00:44 +01:00
|
|
|
|
if ($storage->unused_docblock_params) {
|
|
|
|
|
foreach ($storage->unused_docblock_params as $param_name => $param_location) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new InvalidDocblockParamName(
|
|
|
|
|
'Incorrect param name $' . $param_name . ' in docblock for ' . $cased_method_id,
|
|
|
|
|
$param_location
|
|
|
|
|
)
|
|
|
|
|
)) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 22:58:49 +01:00
|
|
|
|
if (ReturnTypeAnalyzer::checkReturnType(
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$this->function,
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$project_analyzer,
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$this,
|
|
|
|
|
$storage,
|
|
|
|
|
$context
|
|
|
|
|
) === false) {
|
2019-01-05 18:59:12 +01:00
|
|
|
|
$check_stmts = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$check_stmts) {
|
2018-02-22 00:59:31 +01:00
|
|
|
|
return false;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 17:12:36 +01:00
|
|
|
|
if ($context->collect_initializations || $context->collect_mutations) {
|
2019-02-17 02:27:42 +01:00
|
|
|
|
$statements_analyzer->addSuppressedIssues([
|
|
|
|
|
'DocblockTypeContradiction',
|
2019-02-19 03:31:08 +01:00
|
|
|
|
'InvalidReturnStatement',
|
2019-02-17 02:27:42 +01:00
|
|
|
|
'RedundantCondition',
|
|
|
|
|
'RedundantConditionGivenDocblockType',
|
2019-02-19 03:31:08 +01:00
|
|
|
|
'TypeDoesNotContainNull',
|
|
|
|
|
'TypeDoesNotContainType',
|
2019-03-04 06:17:45 +01:00
|
|
|
|
'LoopInvalidation',
|
2019-02-17 02:27:42 +01:00
|
|
|
|
]);
|
2019-06-09 15:17:45 +02:00
|
|
|
|
|
|
|
|
|
if ($context->collect_initializations) {
|
|
|
|
|
$statements_analyzer->addSuppressedIssues([
|
|
|
|
|
'UndefinedInterfaceMethod',
|
|
|
|
|
'UndefinedMethod',
|
|
|
|
|
'PossiblyUndefinedMethod',
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-02-17 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$statements_analyzer->analyze($function_stmts, $context, $global_context, true);
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2019-03-03 21:11:09 +01:00
|
|
|
|
$this->examineParamTypes($statements_analyzer, $context, $codebase);
|
2019-02-02 20:16:49 +01:00
|
|
|
|
|
2017-09-03 00:15:52 +02:00
|
|
|
|
foreach ($storage->params as $offset => $function_param) {
|
|
|
|
|
// only complain if there's no type defined by a parent type
|
|
|
|
|
if (!$function_param->type
|
|
|
|
|
&& $function_param->location
|
|
|
|
|
&& !isset($implemented_docblock_param_types[$offset])
|
|
|
|
|
) {
|
2018-01-29 02:03:47 +01:00
|
|
|
|
if ($this->function instanceof Closure) {
|
|
|
|
|
IssueBuffer::accepts(
|
|
|
|
|
new MissingClosureParamType(
|
2019-02-02 17:28:48 +01:00
|
|
|
|
'Parameter $' . $function_param->name . ' has no provided type',
|
2018-01-29 02:03:47 +01:00
|
|
|
|
$function_param->location
|
|
|
|
|
),
|
2019-08-18 18:25:48 +02:00
|
|
|
|
$storage->suppressed_issues + $this->getSuppressedIssues()
|
2018-01-29 02:03:47 +01:00
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
IssueBuffer::accepts(
|
|
|
|
|
new MissingParamType(
|
2019-02-02 17:28:48 +01:00
|
|
|
|
'Parameter $' . $function_param->name . ' has no provided type',
|
2018-01-29 02:03:47 +01:00
|
|
|
|
$function_param->location
|
|
|
|
|
),
|
2019-08-18 18:25:48 +02:00
|
|
|
|
$storage->suppressed_issues + $this->getSuppressedIssues()
|
2018-01-29 02:03:47 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2017-09-03 00:15:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
|
if ($storage->signature_return_type && $storage->signature_return_type_location) {
|
|
|
|
|
list($start, $end) = $storage->signature_return_type_location->getSelectionBounds();
|
|
|
|
|
|
|
|
|
|
$codebase->analyzer->addOffsetReference(
|
|
|
|
|
$this->getFilePath(),
|
|
|
|
|
$start,
|
|
|
|
|
$end,
|
|
|
|
|
(string) $storage->signature_return_type
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 20:13:39 +01:00
|
|
|
|
if ($this->function instanceof Closure) {
|
2017-01-07 21:09:47 +01:00
|
|
|
|
$this->verifyReturnType(
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$statements_analyzer,
|
2017-01-06 07:07:11 +01:00
|
|
|
|
$storage->return_type,
|
2017-01-07 20:35:07 +01:00
|
|
|
|
$this->source->getFQCLN(),
|
2019-05-07 02:47:55 +02:00
|
|
|
|
$storage->return_type_location,
|
|
|
|
|
$global_context && $global_context->inside_call
|
2016-12-07 20:13:39 +01:00
|
|
|
|
);
|
|
|
|
|
|
2018-04-10 19:05:31 +02:00
|
|
|
|
$closure_yield_types = [];
|
|
|
|
|
|
2019-02-20 23:43:12 +01:00
|
|
|
|
$ignore_nullable_issues = false;
|
|
|
|
|
$ignore_falsable_issues = false;
|
|
|
|
|
|
2018-05-12 00:35:02 +02:00
|
|
|
|
$closure_return_types = ReturnTypeCollector::getReturnTypes(
|
2018-04-10 19:05:31 +02:00
|
|
|
|
$this->function->stmts,
|
|
|
|
|
$closure_yield_types,
|
|
|
|
|
$ignore_nullable_issues,
|
|
|
|
|
$ignore_falsable_issues,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($closure_return_types) {
|
|
|
|
|
$closure_return_type = new Type\Union($closure_return_types);
|
|
|
|
|
|
|
|
|
|
if (!$storage->return_type
|
2018-12-08 19:18:55 +01:00
|
|
|
|
|| $storage->return_type->hasMixed()
|
2018-11-06 03:57:36 +01:00
|
|
|
|
|| TypeAnalyzer::isContainedBy(
|
|
|
|
|
$codebase,
|
2018-04-10 19:05:31 +02:00
|
|
|
|
$closure_return_type,
|
2018-04-10 04:00:36 +02:00
|
|
|
|
$storage->return_type
|
|
|
|
|
)
|
2018-04-10 19:05:31 +02:00
|
|
|
|
) {
|
|
|
|
|
if ($this->function->inferredType) {
|
2019-06-03 12:19:52 +02:00
|
|
|
|
/** @var Type\Atomic\TFn */
|
2018-04-10 19:05:31 +02:00
|
|
|
|
$closure_atomic = $this->function->inferredType->getTypes()['Closure'];
|
|
|
|
|
$closure_atomic->return_type = $closure_return_type;
|
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
|
2019-06-09 23:02:21 +02:00
|
|
|
|
$unused_params = [];
|
|
|
|
|
|
2018-01-25 07:04:26 +01:00
|
|
|
|
if ($context->collect_references
|
2018-02-17 18:02:31 +01:00
|
|
|
|
&& !$context->collect_initializations
|
2019-03-05 21:45:09 +01:00
|
|
|
|
&& $codebase->find_unused_variables
|
2018-01-25 07:04:26 +01:00
|
|
|
|
&& $context->check_variables
|
2017-02-27 07:30:44 +01:00
|
|
|
|
) {
|
2018-11-11 18:01:14 +01:00
|
|
|
|
foreach ($statements_analyzer->getUnusedVarLocations() as list($var_name, $original_location)) {
|
2018-01-25 07:04:26 +01:00
|
|
|
|
if (!array_key_exists(substr($var_name, 1), $storage->param_types)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-02 17:32:34 +01:00
|
|
|
|
if (strpos($var_name, '$_') === 0 || (strpos($var_name, '$unused') === 0 && $var_name !== '$unused')) {
|
2018-02-27 17:39:26 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-28 18:01:51 +01:00
|
|
|
|
$position = array_search(substr($var_name, 1), array_keys($storage->param_types), true);
|
|
|
|
|
|
|
|
|
|
if ($position === false) {
|
|
|
|
|
throw new \UnexpectedValueException('$position should not be false here');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($storage->params[$position]->by_ref) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 07:04:26 +01:00
|
|
|
|
if (!($storage instanceof MethodStorage)
|
2018-11-06 03:57:36 +01:00
|
|
|
|
|| $storage->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
2017-02-01 05:24:33 +01:00
|
|
|
|
) {
|
2019-03-05 21:45:09 +01:00
|
|
|
|
if ($this->function instanceof Closure) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new UnusedClosureParam(
|
|
|
|
|
'Param ' . $var_name . ' is never referenced in this method',
|
|
|
|
|
$original_location
|
|
|
|
|
),
|
|
|
|
|
$this->getSuppressedIssues()
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new UnusedParam(
|
|
|
|
|
'Param ' . $var_name . ' is never referenced in this method',
|
|
|
|
|
$original_location
|
|
|
|
|
),
|
|
|
|
|
$this->getSuppressedIssues()
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
2018-01-25 07:04:26 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$fq_class_name = (string)$context->self;
|
|
|
|
|
|
|
|
|
|
$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);
|
|
|
|
|
|
2018-01-25 21:40:01 +01:00
|
|
|
|
$method_name_lc = strtolower($storage->cased_name);
|
|
|
|
|
|
2018-02-06 19:40:28 +01:00
|
|
|
|
if ($storage->abstract || !isset($class_storage->overridden_method_ids[$method_name_lc])) {
|
2018-01-25 07:04:26 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$parent_method_id = end($class_storage->overridden_method_ids[$method_name_lc]);
|
|
|
|
|
|
|
|
|
|
if ($parent_method_id) {
|
2018-02-04 00:52:35 +01:00
|
|
|
|
$parent_method_storage = $codebase->methods->getStorage($parent_method_id);
|
2018-01-25 07:04:26 +01:00
|
|
|
|
|
|
|
|
|
// if the parent method has a param at that position and isn't abstract
|
|
|
|
|
if (!$parent_method_storage->abstract
|
|
|
|
|
&& isset($parent_method_storage->params[$position])
|
2017-12-29 23:27:16 +01:00
|
|
|
|
) {
|
2018-01-25 07:04:26 +01:00
|
|
|
|
continue;
|
2017-12-30 14:47:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-25 07:04:26 +01:00
|
|
|
|
|
2019-06-09 23:02:21 +02:00
|
|
|
|
$unused_params[$position] = $original_location;
|
2017-12-30 14:47:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 23:29:38 +02:00
|
|
|
|
if ($storage instanceof MethodStorage
|
|
|
|
|
&& $class_storage
|
|
|
|
|
&& $storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PRIVATE
|
|
|
|
|
) {
|
|
|
|
|
$method_id_lc = strtolower($this->getMethodId());
|
|
|
|
|
|
2017-12-30 14:47:00 +01:00
|
|
|
|
foreach ($storage->params as $i => $_) {
|
2019-06-09 23:02:21 +02:00
|
|
|
|
if (!isset($unused_params[$i])) {
|
2019-04-29 23:29:38 +02:00
|
|
|
|
$codebase->file_reference_provider->addMethodParamUse(
|
|
|
|
|
$method_id_lc,
|
|
|
|
|
$i,
|
|
|
|
|
$method_id_lc
|
|
|
|
|
);
|
2017-12-30 14:47:00 +01:00
|
|
|
|
|
|
|
|
|
/** @var ClassMethod $this->function */
|
2018-01-25 07:04:26 +01:00
|
|
|
|
$method_name_lc = strtolower($storage->cased_name);
|
2017-12-30 14:47:00 +01:00
|
|
|
|
|
|
|
|
|
if (!isset($class_storage->overridden_method_ids[$method_name_lc])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($class_storage->overridden_method_ids[$method_name_lc] as $parent_method_id) {
|
2019-04-29 23:29:38 +02:00
|
|
|
|
$codebase->file_reference_provider->addMethodParamUse(
|
|
|
|
|
strtolower($parent_method_id),
|
|
|
|
|
$i,
|
|
|
|
|
$method_id_lc
|
|
|
|
|
);
|
2017-02-08 00:18:33 +01:00
|
|
|
|
}
|
2017-02-01 05:24:33 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 05:42:51 +02:00
|
|
|
|
foreach ($storage->throws as $expected_exception => $_) {
|
2019-08-13 21:44:18 +02:00
|
|
|
|
if (isset($storage->throw_locations[$expected_exception])) {
|
|
|
|
|
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
|
2019-08-13 05:42:51 +02:00
|
|
|
|
$statements_analyzer,
|
|
|
|
|
$expected_exception,
|
2019-08-13 21:44:18 +02:00
|
|
|
|
$storage->throw_locations[$expected_exception],
|
2019-08-13 05:42:51 +02:00
|
|
|
|
$statements_analyzer->getSuppressedIssues(),
|
2019-08-13 19:41:12 +02:00
|
|
|
|
false,
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
true
|
2019-08-13 21:44:18 +02:00
|
|
|
|
)) {
|
|
|
|
|
$input_type = new Type\Union([new TNamedObject($expected_exception)]);
|
|
|
|
|
$container_type = new Type\Union([new TNamedObject('Exception'), new TNamedObject('Throwable')]);
|
2019-08-13 05:42:51 +02:00
|
|
|
|
|
2019-08-13 21:44:18 +02:00
|
|
|
|
if (!TypeAnalyzer::isContainedBy($codebase, $input_type, $container_type)) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new \Psalm\Issue\InvalidThrow(
|
|
|
|
|
'Class supplied for @throws ' . $expected_exception
|
|
|
|
|
. ' does not implement Throwable',
|
|
|
|
|
$storage->throw_locations[$expected_exception],
|
|
|
|
|
$expected_exception
|
|
|
|
|
),
|
|
|
|
|
$statements_analyzer->getSuppressedIssues()
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
2019-08-13 05:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 00:43:14 +01:00
|
|
|
|
foreach ($statements_analyzer->getUncaughtThrows($context) as $possibly_thrown_exception => $codelocations) {
|
2019-03-24 21:17:14 +01:00
|
|
|
|
$is_expected = false;
|
2019-02-01 00:40:40 +01:00
|
|
|
|
|
2019-03-24 21:17:14 +01:00
|
|
|
|
foreach ($storage->throws as $expected_exception => $_) {
|
|
|
|
|
if ($expected_exception === $possibly_thrown_exception
|
|
|
|
|
|| $codebase->classExtends($possibly_thrown_exception, $expected_exception)
|
|
|
|
|
) {
|
|
|
|
|
$is_expected = true;
|
|
|
|
|
break;
|
2018-12-06 04:50:16 +01:00
|
|
|
|
}
|
2019-03-24 21:17:14 +01:00
|
|
|
|
}
|
2018-06-22 07:13:49 +02:00
|
|
|
|
|
2019-03-24 21:17:14 +01:00
|
|
|
|
if (!$is_expected) {
|
2019-03-29 00:43:14 +01:00
|
|
|
|
foreach ($codelocations as $codelocation) {
|
2019-03-29 00:50:29 +01:00
|
|
|
|
// issues are suppressed in ThrowAnalyzer, CallAnalyzer, etc.
|
2019-03-29 00:43:14 +01:00
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new MissingThrowsDocblock(
|
|
|
|
|
$possibly_thrown_exception . ' is thrown but not caught - please either catch'
|
|
|
|
|
. ' or add a @throws annotation',
|
|
|
|
|
$codelocation
|
2019-03-29 00:50:29 +01:00
|
|
|
|
)
|
2019-03-29 00:43:14 +01:00
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
|
|
|
|
}
|
2018-06-22 07:13:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 03:37:53 +01:00
|
|
|
|
if ($add_mutations) {
|
2019-03-06 17:12:36 +01:00
|
|
|
|
if ($this->return_vars_in_scope !== null) {
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$context->vars_in_scope = TypeAnalyzer::combineKeyedTypes(
|
2017-01-12 03:37:53 +01:00
|
|
|
|
$context->vars_in_scope,
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_in_scope
|
2017-01-12 03:37:53 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
|
2019-03-06 17:12:36 +01:00
|
|
|
|
if ($this->return_vars_possibly_in_scope !== null) {
|
2017-01-12 03:37:53 +01:00
|
|
|
|
$context->vars_possibly_in_scope = array_merge(
|
|
|
|
|
$context->vars_possibly_in_scope,
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_possibly_in_scope
|
2017-01-12 03:37:53 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
|
2017-02-11 01:10:13 +01:00
|
|
|
|
foreach ($context->vars_in_scope as $var => $_) {
|
2017-01-28 02:54:27 +01:00
|
|
|
|
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
2017-01-12 03:37:53 +01:00
|
|
|
|
unset($context->vars_in_scope[$var]);
|
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-11 01:10:13 +01:00
|
|
|
|
foreach ($context->vars_possibly_in_scope as $var => $_) {
|
2017-01-28 02:54:27 +01:00
|
|
|
|
if (strpos($var, '$this->') !== 0 && $var !== '$this') {
|
2017-01-12 03:37:53 +01:00
|
|
|
|
unset($context->vars_possibly_in_scope[$var]);
|
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
2016-11-02 07:29:00 +01:00
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
if ($hash && $real_method_id && $this instanceof MethodAnalyzer) {
|
2019-01-31 18:55:48 +01:00
|
|
|
|
$new_hash = md5($real_method_id . '::' . $context->getScopeSummary());
|
2018-04-25 20:33:39 +02:00
|
|
|
|
|
|
|
|
|
if ($new_hash === $hash) {
|
2019-01-31 18:55:48 +01:00
|
|
|
|
self::$no_effects_hashes[$hash] = true;
|
2018-04-25 20:33:39 +02:00
|
|
|
|
}
|
2017-01-12 03:37:53 +01:00
|
|
|
|
}
|
2016-12-07 20:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
|
return null;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
|
/**
|
2018-02-22 00:59:31 +01:00
|
|
|
|
* @param Type\Union|null $return_type
|
|
|
|
|
* @param string $fq_class_name
|
|
|
|
|
* @param CodeLocation|null $return_type_location
|
2017-11-26 22:03:17 +01:00
|
|
|
|
*
|
2018-02-22 00:59:31 +01:00
|
|
|
|
* @return false|null
|
2017-11-26 22:03:17 +01:00
|
|
|
|
*/
|
2018-02-22 00:59:31 +01:00
|
|
|
|
public function verifyReturnType(
|
2018-11-11 18:01:14 +01:00
|
|
|
|
StatementsAnalyzer $statements_analyzer,
|
2018-02-22 00:59:31 +01:00
|
|
|
|
Type\Union $return_type = null,
|
|
|
|
|
$fq_class_name = null,
|
2019-05-07 02:47:55 +02:00
|
|
|
|
CodeLocation $return_type_location = null,
|
|
|
|
|
bool $closure_inside_call = false
|
2017-11-26 22:03:17 +01:00
|
|
|
|
) {
|
2018-11-06 03:57:36 +01:00
|
|
|
|
ReturnTypeAnalyzer::verifyReturnType(
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$this->function,
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$statements_analyzer,
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$this,
|
|
|
|
|
$return_type,
|
|
|
|
|
$fq_class_name,
|
2019-05-07 02:47:55 +02:00
|
|
|
|
$return_type_location,
|
|
|
|
|
[],
|
|
|
|
|
$closure_inside_call
|
2018-02-22 00:59:31 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-26 22:03:17 +01:00
|
|
|
|
|
2018-02-22 00:59:31 +01:00
|
|
|
|
/**
|
|
|
|
|
* @param string $param_name
|
|
|
|
|
* @param bool $docblock_only
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2019-05-31 07:47:35 +02:00
|
|
|
|
public function addOrUpdateParamType(
|
2018-11-11 18:01:14 +01:00
|
|
|
|
ProjectAnalyzer $project_analyzer,
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$param_name,
|
|
|
|
|
Type\Union $inferred_return_type,
|
|
|
|
|
$docblock_only = false
|
|
|
|
|
) {
|
|
|
|
|
$manipulator = FunctionDocblockManipulator::getForFunction(
|
2018-11-11 18:01:14 +01:00
|
|
|
|
$project_analyzer,
|
2018-02-22 00:59:31 +01:00
|
|
|
|
$this->source->getFilePath(),
|
|
|
|
|
$this->getMethodId(),
|
|
|
|
|
$this->function
|
|
|
|
|
);
|
|
|
|
|
$manipulator->setParamType(
|
|
|
|
|
$param_name,
|
2019-02-07 18:25:57 +01:00
|
|
|
|
!$docblock_only && $project_analyzer->getCodebase()->php_major_version >= 7
|
2018-02-22 00:59:31 +01:00
|
|
|
|
? $inferred_return_type->toPhpString(
|
|
|
|
|
$this->source->getNamespace(),
|
|
|
|
|
$this->source->getAliasedClassesFlipped(),
|
|
|
|
|
$this->source->getFQCLN(),
|
2019-02-07 18:25:57 +01:00
|
|
|
|
$project_analyzer->getCodebase()->php_major_version,
|
|
|
|
|
$project_analyzer->getCodebase()->php_minor_version
|
2018-02-22 00:59:31 +01:00
|
|
|
|
) : null,
|
|
|
|
|
$inferred_return_type->toNamespacedString(
|
|
|
|
|
$this->source->getNamespace(),
|
|
|
|
|
$this->source->getAliasedClassesFlipped(),
|
|
|
|
|
$this->source->getFQCLN(),
|
|
|
|
|
false
|
|
|
|
|
),
|
|
|
|
|
$inferred_return_type->toNamespacedString(
|
|
|
|
|
$this->source->getNamespace(),
|
|
|
|
|
$this->source->getAliasedClassesFlipped(),
|
|
|
|
|
$this->source->getFQCLN(),
|
|
|
|
|
true
|
|
|
|
|
),
|
|
|
|
|
$inferred_return_type->canBeFullyExpressedInPhp()
|
|
|
|
|
);
|
2017-11-26 22:03:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-14 05:26:45 +02:00
|
|
|
|
/**
|
|
|
|
|
* Adds return types for the given function
|
2016-11-02 07:29:00 +01:00
|
|
|
|
*
|
|
|
|
|
* @param string $return_type
|
|
|
|
|
* @param Context $context
|
2017-05-27 02:16:18 +02:00
|
|
|
|
*
|
2016-11-02 07:29:00 +01:00
|
|
|
|
* @return void
|
2016-08-14 05:26:45 +02:00
|
|
|
|
*/
|
2019-03-06 17:12:36 +01:00
|
|
|
|
public function addReturnTypes(Context $context)
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
2019-03-06 17:12:36 +01:00
|
|
|
|
if ($this->return_vars_in_scope !== null) {
|
|
|
|
|
$this->return_vars_in_scope = TypeAnalyzer::combineKeyedTypes(
|
2016-11-02 07:29:00 +01:00
|
|
|
|
$context->vars_in_scope,
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_in_scope
|
2016-11-02 07:29:00 +01:00
|
|
|
|
);
|
|
|
|
|
} else {
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_in_scope = $context->vars_in_scope;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 17:12:36 +01:00
|
|
|
|
if ($this->return_vars_possibly_in_scope !== null) {
|
|
|
|
|
$this->return_vars_possibly_in_scope = array_merge(
|
2016-11-02 07:29:00 +01:00
|
|
|
|
$context->vars_possibly_in_scope,
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_possibly_in_scope
|
2016-11-02 07:29:00 +01:00
|
|
|
|
);
|
|
|
|
|
} else {
|
2019-03-06 17:12:36 +01:00
|
|
|
|
$this->return_vars_possibly_in_scope = $context->vars_possibly_in_scope;
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 20:16:49 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2019-03-04 00:21:12 +01:00
|
|
|
|
public function examineParamTypes(
|
|
|
|
|
StatementsAnalyzer $statements_analyzer,
|
|
|
|
|
Context $context,
|
|
|
|
|
Codebase $codebase,
|
|
|
|
|
PhpParser\Node $stmt = null
|
|
|
|
|
) {
|
2019-05-31 07:47:35 +02:00
|
|
|
|
$storage = $this->getFunctionLikeStorage($statements_analyzer);
|
2019-03-03 21:11:09 +01:00
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
|
foreach ($storage->params as $i => $param) {
|
|
|
|
|
if ($param->by_ref && isset($context->vars_in_scope['$' . $param->name]) && !$param->is_variadic) {
|
|
|
|
|
$actual_type = $context->vars_in_scope['$' . $param->name];
|
|
|
|
|
$param_out_type = $param->type;
|
2019-03-03 21:11:09 +01:00
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
|
if (isset($storage->param_out_types[$i])) {
|
|
|
|
|
$param_out_type = $storage->param_out_types[$i];
|
|
|
|
|
}
|
2019-03-03 21:11:09 +01:00
|
|
|
|
|
2019-05-31 07:47:35 +02:00
|
|
|
|
if ($param_out_type && !$actual_type->hasMixed() && $param->location) {
|
|
|
|
|
if (!TypeAnalyzer::isContainedBy(
|
|
|
|
|
$codebase,
|
|
|
|
|
$actual_type,
|
|
|
|
|
$param_out_type,
|
|
|
|
|
$actual_type->ignore_nullable_issues,
|
|
|
|
|
$actual_type->ignore_falsable_issues
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
|
new ReferenceConstraintViolation(
|
|
|
|
|
'Variable ' . '$' . $param->name . ' is limited to values of type '
|
|
|
|
|
. $param_out_type->getId()
|
|
|
|
|
. ' because it is passed by reference, '
|
|
|
|
|
. $actual_type->getId() . ' type found. Use @param-out to specify '
|
|
|
|
|
. 'a different output type',
|
|
|
|
|
$stmt
|
|
|
|
|
? new CodeLocation($this, $stmt)
|
|
|
|
|
: $param->location
|
|
|
|
|
),
|
|
|
|
|
$statements_analyzer->getSuppressedIssues()
|
|
|
|
|
)) {
|
|
|
|
|
// fall through
|
2019-03-03 21:11:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-02 20:16:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 06:51:34 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return null|string
|
|
|
|
|
*/
|
|
|
|
|
public function getMethodName()
|
|
|
|
|
{
|
|
|
|
|
if ($this->function instanceof ClassMethod) {
|
|
|
|
|
return (string)$this->function->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-14 05:26:45 +02:00
|
|
|
|
/**
|
2016-12-30 18:41:14 +01:00
|
|
|
|
* @param string|null $context_self
|
2017-05-27 02:16:18 +02:00
|
|
|
|
*
|
2017-08-15 01:30:11 +02:00
|
|
|
|
* @return string
|
2016-08-14 05:26:45 +02:00
|
|
|
|
*/
|
2016-12-30 18:41:14 +01:00
|
|
|
|
public function getMethodId($context_self = null)
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
2016-11-21 03:49:06 +01:00
|
|
|
|
if ($this->function instanceof ClassMethod) {
|
2016-11-21 22:44:35 +01:00
|
|
|
|
$function_name = (string)$this->function->name;
|
2016-11-21 20:36:06 +01:00
|
|
|
|
|
2017-01-07 20:35:07 +01:00
|
|
|
|
return ($context_self ?: $this->source->getFQCLN()) . '::' . strtolower($function_name);
|
2016-11-21 03:49:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->function instanceof Function_) {
|
2017-11-26 22:03:17 +01:00
|
|
|
|
$namespace = $this->source->getNamespace();
|
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
|
return ($namespace ? strtolower($namespace) . '\\' : '') . strtolower($this->function->name->name);
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
2016-11-02 07:29:00 +01:00
|
|
|
|
|
2018-05-25 10:21:54 +02:00
|
|
|
|
return $this->getFilePath()
|
|
|
|
|
. ':' . $this->function->getLine()
|
|
|
|
|
. ':' . (int)$this->function->getAttribute('startFilePos')
|
|
|
|
|
. ':-:closure';
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 21:50:25 +01:00
|
|
|
|
/**
|
|
|
|
|
* @param string|null $context_self
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getCorrectlyCasedMethodId($context_self = null)
|
|
|
|
|
{
|
|
|
|
|
if ($this->function instanceof ClassMethod) {
|
|
|
|
|
$function_name = (string)$this->function->name;
|
|
|
|
|
|
|
|
|
|
return ($context_self ?: $this->source->getFQCLN()) . '::' . $function_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->function instanceof Function_) {
|
|
|
|
|
$namespace = $this->source->getNamespace();
|
|
|
|
|
|
|
|
|
|
return ($namespace ? $namespace . '\\' : '') . $this->function->name;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 10:21:54 +02:00
|
|
|
|
return $this->getMethodId();
|
2017-12-07 21:50:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-04 02:52:54 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return FunctionLikeStorage
|
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
|
public function getFunctionLikeStorage(StatementsAnalyzer $statements_analyzer = null)
|
2017-09-04 02:52:54 +02:00
|
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$codebase = $this->codebase;
|
2017-09-04 02:52:54 +02:00
|
|
|
|
|
2018-01-25 07:04:26 +01:00
|
|
|
|
if ($this->function instanceof ClassMethod) {
|
|
|
|
|
$method_id = (string) $this->getMethodId();
|
2018-02-04 00:52:35 +01:00
|
|
|
|
$codebase_methods = $codebase->methods;
|
2018-01-25 07:04:26 +01:00
|
|
|
|
|
|
|
|
|
try {
|
2018-02-04 00:52:35 +01:00
|
|
|
|
return $codebase_methods->getStorage($method_id);
|
2018-01-25 07:04:26 +01:00
|
|
|
|
} catch (\UnexpectedValueException $e) {
|
2018-03-03 22:52:48 +01:00
|
|
|
|
$declaring_method_id = $codebase_methods->getDeclaringMethodId($method_id);
|
|
|
|
|
|
|
|
|
|
if (!$declaring_method_id) {
|
|
|
|
|
throw new \UnexpectedValueException('Cannot get storage for function that doesn‘t exist');
|
|
|
|
|
}
|
2017-09-04 02:52:54 +02:00
|
|
|
|
|
2018-01-25 07:04:26 +01:00
|
|
|
|
// happens for fake constructors
|
2018-02-04 00:52:35 +01:00
|
|
|
|
return $codebase_methods->getStorage($declaring_method_id);
|
2017-09-04 02:52:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
|
return $codebase->functions->getStorage($statements_analyzer, (string) $this->getMethodId());
|
2017-09-04 02:52:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 00:51:48 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public function getAliasedClassesFlipped()
|
|
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
|
if ($this->source instanceof NamespaceAnalyzer ||
|
|
|
|
|
$this->source instanceof FileAnalyzer ||
|
|
|
|
|
$this->source instanceof ClassLikeAnalyzer
|
2017-04-28 06:31:55 +02:00
|
|
|
|
) {
|
2016-11-13 17:24:46 +01:00
|
|
|
|
return $this->source->getAliasedClassesFlipped();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
2016-11-13 00:51:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 04:13:33 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
public function getAliasedClassesFlippedReplaceable()
|
|
|
|
|
{
|
|
|
|
|
if ($this->source instanceof NamespaceAnalyzer ||
|
|
|
|
|
$this->source instanceof FileAnalyzer ||
|
|
|
|
|
$this->source instanceof ClassLikeAnalyzer
|
|
|
|
|
) {
|
|
|
|
|
return $this->source->getAliasedClassesFlippedReplaceable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
|
/**
|
2017-01-07 20:35:07 +01:00
|
|
|
|
* @return string|null
|
2016-11-02 07:29:00 +01:00
|
|
|
|
*/
|
2016-11-08 01:16:51 +01:00
|
|
|
|
public function getFQCLN()
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
2017-01-07 20:35:07 +01:00
|
|
|
|
return $this->source->getFQCLN();
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return null|string
|
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
public function getClassName()
|
|
|
|
|
{
|
2017-01-07 20:35:07 +01:00
|
|
|
|
return $this->source->getClassName();
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-18 05:29:27 +01:00
|
|
|
|
/**
|
2019-03-22 20:59:10 +01:00
|
|
|
|
* @return array<string, array<string, array{Type\Union}>>|null
|
2018-12-18 05:29:27 +01:00
|
|
|
|
*/
|
|
|
|
|
public function getTemplateTypeMap()
|
|
|
|
|
{
|
|
|
|
|
if ($this->source instanceof ClassLikeAnalyzer) {
|
|
|
|
|
return ($this->source->getTemplateTypeMap() ?: [])
|
|
|
|
|
+ ($this->storage->template_types ?: []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->storage->template_types;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-09 23:54:58 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
2017-01-07 20:35:07 +01:00
|
|
|
|
public function getParentFQCLN()
|
2016-08-14 05:26:45 +02:00
|
|
|
|
{
|
2017-01-07 20:35:07 +01:00
|
|
|
|
return $this->source->getParentFQCLN();
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
public function isStatic()
|
|
|
|
|
{
|
|
|
|
|
return $this->is_static;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
|
/**
|
|
|
|
|
* @return StatementsSource
|
|
|
|
|
*/
|
2016-08-14 05:26:45 +02:00
|
|
|
|
public function getSource()
|
|
|
|
|
{
|
|
|
|
|
return $this->source;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
public function getCodebase() : Codebase
|
|
|
|
|
{
|
|
|
|
|
return $this->codebase;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 20:35:07 +01:00
|
|
|
|
/**
|
|
|
|
|
* Get a list of suppressed issues
|
|
|
|
|
*
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public function getSuppressedIssues()
|
|
|
|
|
{
|
|
|
|
|
return $this->suppressed_issues;
|
|
|
|
|
}
|
2017-01-27 07:23:12 +01:00
|
|
|
|
|
2017-10-27 00:19:19 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param array<int, string> $new_issues
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function addSuppressedIssues(array $new_issues)
|
|
|
|
|
{
|
2019-08-18 18:25:48 +02:00
|
|
|
|
if (isset($new_issues[0])) {
|
|
|
|
|
$new_issues = \array_combine($new_issues, $new_issues);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->suppressed_issues = $new_issues + $this->suppressed_issues;
|
2017-10-27 00:19:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array<int, string> $new_issues
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function removeSuppressedIssues(array $new_issues)
|
|
|
|
|
{
|
2019-08-18 18:25:48 +02:00
|
|
|
|
if (isset($new_issues[0])) {
|
|
|
|
|
$new_issues = \array_combine($new_issues, $new_issues);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->suppressed_issues = \array_diff_key($this->suppressed_issues, $new_issues);
|
2017-10-27 00:19:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 22:09:09 +02:00
|
|
|
|
/**
|
|
|
|
|
* Adds a suppressed issue, useful when creating a method checker from scratch
|
|
|
|
|
*
|
2017-07-27 05:47:29 +02:00
|
|
|
|
* @param string $issue_name
|
|
|
|
|
*
|
2017-07-26 22:09:09 +02:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-07-27 05:47:29 +02:00
|
|
|
|
public function addSuppressedIssue($issue_name)
|
2017-07-26 22:09:09 +02:00
|
|
|
|
{
|
|
|
|
|
$this->suppressed_issues[] = $issue_name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 07:23:12 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function clearCache()
|
|
|
|
|
{
|
|
|
|
|
self::$no_effects_hashes = [];
|
|
|
|
|
}
|
2017-07-29 21:05:06 +02:00
|
|
|
|
|
2018-01-14 18:09:40 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return Type\Union
|
|
|
|
|
*/
|
|
|
|
|
public function getLocalReturnType(Type\Union $storage_return_type)
|
|
|
|
|
{
|
|
|
|
|
if ($this->local_return_type) {
|
|
|
|
|
return $this->local_return_type;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
|
$this->local_return_type = ExpressionAnalyzer::fleshOutType(
|
|
|
|
|
$this->codebase,
|
2018-01-14 18:09:40 +01:00
|
|
|
|
$storage_return_type,
|
|
|
|
|
$this->getFQCLN(),
|
2019-05-25 17:51:09 +02:00
|
|
|
|
$this->getFQCLN(),
|
|
|
|
|
$this->getParentFQCLN()
|
2018-01-14 18:09:40 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->local_return_type;
|
|
|
|
|
}
|
2016-08-14 05:26:45 +02:00
|
|
|
|
}
|