2017-07-25 22:11:02 +02:00
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Visitor;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\Aliases;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\ClassAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\CommentAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\Statements\Expression\IncludeAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
2018-01-21 19:38:51 +01:00
|
|
|
use Psalm\Codebase;
|
2018-11-12 16:46:55 +01:00
|
|
|
use Psalm\Internal\Codebase\CallMap;
|
|
|
|
use Psalm\Internal\Codebase\PropertyMap;
|
2019-02-17 00:50:25 +01:00
|
|
|
use Psalm\Internal\Scanner\PhpStormMetaScanner;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\CodeLocation;
|
|
|
|
use Psalm\Config;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\DocComment;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\Exception\DocblockParseException;
|
|
|
|
use Psalm\Exception\FileIncludeException;
|
2017-11-15 03:43:31 +01:00
|
|
|
use Psalm\Exception\IncorrectDocblockException;
|
2017-10-22 07:04:35 +02:00
|
|
|
use Psalm\Exception\TypeParseTreeException;
|
2018-02-23 21:39:33 +01:00
|
|
|
use Psalm\FileSource;
|
2018-04-07 17:38:41 +02:00
|
|
|
use Psalm\Issue\DuplicateClass;
|
2019-01-06 22:40:44 +01:00
|
|
|
use Psalm\Issue\DuplicateFunction;
|
2019-01-02 17:18:22 +01:00
|
|
|
use Psalm\Issue\DuplicateMethod;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\Issue\DuplicateParam;
|
|
|
|
use Psalm\Issue\InvalidDocblock;
|
|
|
|
use Psalm\Issue\MisplacedRequiredParam;
|
2017-11-15 03:43:31 +01:00
|
|
|
use Psalm\Issue\MissingDocblockType;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\IssueBuffer;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Scanner\FileScanner;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\Storage\ClassLikeStorage;
|
2017-07-29 21:05:06 +02:00
|
|
|
use Psalm\Storage\FileStorage;
|
2018-05-12 00:35:02 +02:00
|
|
|
use Psalm\Storage\FunctionLikeParameter;
|
2017-07-25 22:11:02 +02:00
|
|
|
use Psalm\Storage\FunctionLikeStorage;
|
|
|
|
use Psalm\Storage\MethodStorage;
|
|
|
|
use Psalm\Storage\PropertyStorage;
|
|
|
|
use Psalm\Type;
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2018-11-13 20:09:37 +01:00
|
|
|
class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParser\NodeVisitor, FileSource
|
2017-07-25 22:11:02 +02:00
|
|
|
{
|
|
|
|
/** @var Aliases */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $aliases;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
/** @var Aliases */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $file_aliases;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-14 21:46:01 +02:00
|
|
|
* @var string[]
|
2017-07-25 22:11:02 +02:00
|
|
|
*/
|
2018-01-21 18:44:46 +01:00
|
|
|
private $fq_classlike_names = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-01-21 18:44:46 +01:00
|
|
|
/** @var FileScanner */
|
|
|
|
private $file_scanner;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
/** @var Codebase */
|
|
|
|
private $codebase;
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/** @var string */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $file_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
/** @var bool */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $scan_deep;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
/** @var Config */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $config;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-03-22 20:59:10 +01:00
|
|
|
/** @var array<string, array<string, array{Type\Union}>> */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $class_template_types = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-03-22 20:59:10 +01:00
|
|
|
/** @var array<string, array<string, array{Type\Union}>> */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $function_template_types = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
/** @var FunctionLikeStorage[] */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $functionlike_storages = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
/** @var FileStorage */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $file_storage;
|
2017-07-29 21:05:06 +02:00
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
/** @var ClassLikeStorage[] */
|
2018-01-21 18:44:46 +01:00
|
|
|
private $classlike_storages = [];
|
2017-07-29 21:05:06 +02:00
|
|
|
|
2019-01-02 15:00:45 +01:00
|
|
|
/** @var class-string<\Psalm\Plugin\Hook\AfterClassLikeVisitInterface>[] */
|
2018-02-12 04:49:19 +01:00
|
|
|
private $after_classlike_check_plugins;
|
2017-11-07 20:46:53 +01:00
|
|
|
|
2019-02-07 18:25:57 +01:00
|
|
|
/** @var int */
|
|
|
|
private $php_major_version;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
private $php_minor_version;
|
|
|
|
|
2018-07-15 23:23:17 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, array<int, string>>
|
|
|
|
*/
|
|
|
|
private $type_aliases = [];
|
|
|
|
|
2018-02-23 04:22:31 +01:00
|
|
|
public function __construct(
|
|
|
|
Codebase $codebase,
|
|
|
|
FileStorage $file_storage,
|
2018-02-23 04:52:22 +01:00
|
|
|
FileScanner $file_scanner
|
2018-02-23 04:22:31 +01:00
|
|
|
) {
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->codebase = $codebase;
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner = $file_scanner;
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->file_path = $file_scanner->file_path;
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->scan_deep = $file_scanner->will_analyze;
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->config = $codebase->config;
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->aliases = $this->file_aliases = new Aliases();
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_storage = $file_storage;
|
2018-02-12 04:49:19 +01:00
|
|
|
$this->after_classlike_check_plugins = $this->config->after_visit_classlikes;
|
2019-02-07 18:25:57 +01:00
|
|
|
$this->php_major_version = $codebase->php_major_version;
|
|
|
|
$this->php_minor_version = $codebase->php_minor_version;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @param PhpParser\Node $node
|
|
|
|
*
|
2018-01-28 23:07:09 +01:00
|
|
|
* @return null|int
|
2017-11-26 22:03:17 +01:00
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function enterNode(PhpParser\Node $node)
|
|
|
|
{
|
2018-07-22 04:24:33 +02:00
|
|
|
foreach ($node->getComments() as $comment) {
|
|
|
|
if ($comment instanceof PhpParser\Comment\Doc) {
|
|
|
|
try {
|
2018-11-06 03:57:36 +01:00
|
|
|
$type_alias_tokens = CommentAnalyzer::getTypeAliasesFromComment(
|
2018-07-22 04:24:33 +02:00
|
|
|
(string) $comment,
|
|
|
|
$this->aliases,
|
|
|
|
$this->type_aliases
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($type_alias_tokens as $type_tokens) {
|
|
|
|
// finds issues, if there are any
|
|
|
|
Type::parseTokens($type_tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->type_aliases += $type_alias_tokens;
|
|
|
|
} catch (DocblockParseException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
(string)$e->getMessage(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
// fall through
|
|
|
|
}
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
(string)$e->getMessage(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
2018-07-22 04:55:16 +02:00
|
|
|
// fall through
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($node instanceof PhpParser\Node\Stmt\Namespace_) {
|
|
|
|
$this->file_aliases = $this->aliases;
|
|
|
|
$this->aliases = new Aliases(
|
|
|
|
$node->name ? implode('\\', $node->name->parts) : '',
|
|
|
|
$this->aliases->uses,
|
|
|
|
$this->aliases->functions,
|
|
|
|
$this->aliases->constants
|
|
|
|
);
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Use_) {
|
|
|
|
foreach ($node->uses as $use) {
|
|
|
|
$use_path = implode('\\', $use->name->parts);
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
$use_alias = $use->alias ? $use->alias->name : $use->name->getLast();
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) {
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->functions[strtolower($use_alias)] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_CONSTANT:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->constants[$use_alias] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_NORMAL:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->uses[strtolower($use_alias)] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\GroupUse) {
|
|
|
|
$use_prefix = implode('\\', $node->prefix->parts);
|
|
|
|
|
|
|
|
foreach ($node->uses as $use) {
|
|
|
|
$use_path = $use_prefix . '\\' . implode('\\', $use->name->parts);
|
2018-04-17 18:16:25 +02:00
|
|
|
$use_alias = $use->alias ? $use->alias->name : $use->name->getLast();
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) {
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->functions[strtolower($use_alias)] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_CONSTANT:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->constants[$use_alias] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PhpParser\Node\Stmt\Use_::TYPE_NORMAL:
|
2018-04-17 18:16:25 +02:00
|
|
|
$this->aliases->uses[strtolower($use_alias)] = $use_path;
|
2017-07-25 22:11:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\ClassLike) {
|
2018-07-22 04:24:33 +02:00
|
|
|
if ($this->registerClassLike($node) === false) {
|
|
|
|
return PhpParser\NodeTraverser::STOP_TRAVERSAL;
|
2018-01-21 18:44:46 +01:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif (($node instanceof PhpParser\Node\Expr\New_
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\Instanceof_
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\StaticPropertyFetch
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\ClassConstFetch
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\StaticCall)
|
|
|
|
&& $node->class instanceof PhpParser\Node\Name
|
|
|
|
) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$fq_classlike_name = ClassLikeAnalyzer::getFQCLNFromNameObject($node->class, $this->aliases);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-11-15 03:56:29 +01:00
|
|
|
if (!in_array(strtolower($fq_classlike_name), ['self', 'static', 'parent'], true)) {
|
2018-05-22 17:59:57 +02:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning(
|
|
|
|
$fq_classlike_name,
|
|
|
|
$this->file_path,
|
|
|
|
false,
|
|
|
|
!($node instanceof PhpParser\Node\Expr\ClassConstFetch)
|
|
|
|
|| !($node->name instanceof PhpParser\Node\Identifier)
|
|
|
|
|| strtolower($node->name->name) !== 'class'
|
|
|
|
);
|
2018-02-23 04:22:31 +01:00
|
|
|
$this->file_storage->referenced_classlikes[strtolower($fq_classlike_name)] = $fq_classlike_name;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\TryCatch) {
|
|
|
|
foreach ($node->catches as $catch) {
|
|
|
|
foreach ($catch->types as $catch_type) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$catch_fqcln = ClassLikeAnalyzer::getFQCLNFromNameObject($catch_type, $this->aliases);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-11-15 03:56:29 +01:00
|
|
|
if (!in_array(strtolower($catch_fqcln), ['self', 'static', 'parent'], true)) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($catch_fqcln, $this->file_path);
|
2018-02-23 04:22:31 +01:00
|
|
|
$this->file_storage->referenced_classlikes[strtolower($catch_fqcln)] = $catch_fqcln;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 00:07:38 +01:00
|
|
|
} elseif ($node instanceof PhpParser\Node\FunctionLike) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->registerFunctionLike($node);
|
|
|
|
|
2019-02-10 22:23:31 +01:00
|
|
|
if ($node instanceof PhpParser\Node\Expr\Closure) {
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning('Closure', $this->file_path);
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if (!$this->scan_deep) {
|
|
|
|
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
|
|
|
}
|
2018-05-31 04:09:46 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Global_) {
|
|
|
|
$function_like_storage = end($this->functionlike_storages);
|
|
|
|
|
|
|
|
if ($function_like_storage) {
|
|
|
|
foreach ($node->vars as $var) {
|
|
|
|
if ($var instanceof PhpParser\Node\Expr\Variable) {
|
2018-05-31 04:56:46 +02:00
|
|
|
if (is_string($var->name) && $var->name !== 'argv' && $var->name !== 'argc') {
|
2018-05-31 04:09:46 +02:00
|
|
|
$var_id = '$' . $var->name;
|
|
|
|
|
|
|
|
$function_like_storage->global_variables[$var_id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Expr\FuncCall && $node->name instanceof PhpParser\Node\Name) {
|
|
|
|
$function_id = implode('\\', $node->name->parts);
|
2018-02-04 00:52:35 +01:00
|
|
|
if (CallMap::inCallMap($function_id)) {
|
2019-01-28 23:54:50 +01:00
|
|
|
$this->registerClassMapFunctionCall($function_id, $node);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\TraitUse) {
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->classlike_storages) {
|
|
|
|
throw new \LogicException('$this->classlike_storages should not be empty');
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$storage = $this->classlike_storages[count($this->classlike_storages) - 1];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-03-13 04:37:21 +01:00
|
|
|
$method_map = $storage->trait_alias_map ?: [];
|
2019-01-07 17:53:22 +01:00
|
|
|
$visibility_map = $storage->trait_visibility_map ?: [];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
foreach ($node->adaptations as $adaptation) {
|
|
|
|
if ($adaptation instanceof PhpParser\Node\Stmt\TraitUseAdaptation\Alias) {
|
2019-01-07 17:53:22 +01:00
|
|
|
$old_name = strtolower($adaptation->method->name);
|
|
|
|
$new_name = $old_name;
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if ($adaptation->newName) {
|
2019-01-07 17:53:22 +01:00
|
|
|
$new_name = strtolower($adaptation->newName->name);
|
|
|
|
|
|
|
|
if ($new_name !== $old_name) {
|
|
|
|
$method_map[$new_name] = $old_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($adaptation->newModifier) {
|
|
|
|
switch ($adaptation->newModifier) {
|
|
|
|
case 1:
|
|
|
|
$visibility_map[$new_name] = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
$visibility_map[$new_name] = ClassLikeAnalyzer::VISIBILITY_PROTECTED;
|
|
|
|
break;
|
2019-01-13 16:19:27 +01:00
|
|
|
|
|
|
|
case 4:
|
|
|
|
$visibility_map[$new_name] = ClassLikeAnalyzer::VISIBILITY_PRIVATE;
|
|
|
|
break;
|
2019-01-07 17:53:22 +01:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->trait_alias_map = $method_map;
|
2019-01-07 17:53:22 +01:00
|
|
|
$storage->trait_visibility_map = $visibility_map;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
foreach ($node->traits as $trait) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$trait_fqcln = ClassLikeAnalyzer::getFQCLNFromNameObject($trait, $this->aliases);
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($trait_fqcln, $this->file_path, $this->scan_deep);
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->used_traits[strtolower($trait_fqcln)] = $trait_fqcln;
|
2018-02-23 04:22:31 +01:00
|
|
|
$this->file_storage->required_classes[strtolower($trait_fqcln)] = $trait_fqcln;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2019-01-28 05:12:40 +01:00
|
|
|
|
|
|
|
if ($node_comment = $node->getDocComment()) {
|
|
|
|
$comments = DocComment::parse((string) $node_comment, 0);
|
|
|
|
|
|
|
|
if (isset($comments['specials']['template-use'])
|
|
|
|
|| isset($comments['specials']['use'])
|
|
|
|
) {
|
|
|
|
$all_inheritance = array_merge(
|
|
|
|
$comments['specials']['template-use'] ?? [],
|
|
|
|
$comments['specials']['use'] ?? []
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($all_inheritance as $template_line) {
|
|
|
|
$this->useTemplatedType($storage, $node, $template_line);
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 22:56:42 +01:00
|
|
|
|
|
|
|
if (isset($comments['specials']['template-extends'])
|
|
|
|
|| isset($comments['specials']['extends'])
|
|
|
|
|| isset($comments['specials']['template-implements'])
|
|
|
|
|| isset($comments['specials']['implements'])
|
|
|
|
) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'You must use @use or @template-use to parameterize traits',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 05:12:40 +01:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Expr\Include_) {
|
|
|
|
$this->visitInclude($node);
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Expr\Assign
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\AssignOp
|
|
|
|
|| $node instanceof PhpParser\Node\Expr\AssignRef
|
2018-10-09 01:39:36 +02:00
|
|
|
|| $node instanceof PhpParser\Node\Stmt\For_
|
|
|
|
|| $node instanceof PhpParser\Node\Stmt\Foreach_
|
|
|
|
|| $node instanceof PhpParser\Node\Stmt\While_
|
|
|
|
|| $node instanceof PhpParser\Node\Stmt\Do_
|
2017-07-25 22:11:02 +02:00
|
|
|
) {
|
|
|
|
if ($doc_comment = $node->getDocComment()) {
|
2018-02-08 05:33:31 +01:00
|
|
|
$var_comments = [];
|
2017-11-15 03:43:31 +01:00
|
|
|
|
|
|
|
try {
|
2018-11-06 03:57:36 +01:00
|
|
|
$var_comments = CommentAnalyzer::getTypeFromComment(
|
2017-11-15 03:43:31 +01:00
|
|
|
(string)$doc_comment,
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner,
|
2017-11-15 03:43:31 +01:00
|
|
|
$this->aliases,
|
|
|
|
null,
|
2018-07-15 23:23:17 +02:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
2017-11-15 03:43:31 +01:00
|
|
|
);
|
|
|
|
} catch (DocblockParseException $e) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-02-08 05:33:31 +01:00
|
|
|
foreach ($var_comments as $var_comment) {
|
2018-01-02 02:04:03 +01:00
|
|
|
$var_type = $var_comment->type;
|
2018-02-19 06:27:39 +01:00
|
|
|
$var_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-27 01:54:22 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Const_) {
|
2017-07-28 16:42:30 +02:00
|
|
|
foreach ($node->consts as $const) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$const_type = StatementsAnalyzer::getSimpleType($this->codebase, $const->value, $this->aliases)
|
2018-05-10 20:12:50 +02:00
|
|
|
?: Type::getMixed();
|
2017-07-28 16:42:30 +02:00
|
|
|
|
2018-08-08 22:13:37 +02:00
|
|
|
$fq_const_name = Type::getFQCLNFromString($const->name->name, $this->aliases);
|
|
|
|
|
2018-06-30 21:29:37 +02:00
|
|
|
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
|
2018-08-08 22:13:37 +02:00
|
|
|
$this->codebase->addGlobalConstantType($fq_const_name, $const_type);
|
2017-07-27 01:54:22 +02:00
|
|
|
}
|
2018-06-29 21:28:45 +02:00
|
|
|
|
2018-08-08 22:13:37 +02:00
|
|
|
$this->file_storage->constants[$fq_const_name] = $const_type;
|
|
|
|
$this->file_storage->declaring_constants[$fq_const_name] = $this->file_path;
|
2017-07-27 01:54:22 +02:00
|
|
|
}
|
2018-06-30 21:29:37 +02:00
|
|
|
} elseif ($this->codebase->register_autoload_files && $node instanceof PhpParser\Node\Stmt\If_) {
|
2018-04-27 21:00:22 +02:00
|
|
|
if ($node->cond instanceof PhpParser\Node\Expr\BooleanNot) {
|
|
|
|
if ($node->cond->expr instanceof PhpParser\Node\Expr\FuncCall
|
|
|
|
&& $node->cond->expr->name instanceof PhpParser\Node\Name
|
|
|
|
) {
|
|
|
|
if ($node->cond->expr->name->parts === ['function_exists']
|
|
|
|
&& isset($node->cond->expr->args[0])
|
|
|
|
&& $node->cond->expr->args[0]->value instanceof PhpParser\Node\Scalar\String_
|
|
|
|
&& function_exists($node->cond->expr->args[0]->value->value)
|
|
|
|
) {
|
2018-08-30 02:54:41 +02:00
|
|
|
$reflection_function = new \ReflectionFunction($node->cond->expr->args[0]->value->value);
|
|
|
|
|
2019-04-20 23:16:42 +02:00
|
|
|
if ($reflection_function->isInternal()) {
|
2018-08-30 02:54:41 +02:00
|
|
|
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
|
|
|
}
|
2019-04-20 23:16:42 +02:00
|
|
|
} elseif ($node->cond->expr->name->parts === ['class_exists']
|
2018-04-27 21:00:22 +02:00
|
|
|
&& isset($node->cond->expr->args[0])
|
|
|
|
&& $node->cond->expr->args[0]->value instanceof PhpParser\Node\Scalar\String_
|
|
|
|
&& class_exists($node->cond->expr->args[0]->value->value, false)
|
|
|
|
) {
|
2018-07-04 21:33:48 +02:00
|
|
|
$reflection_class = new \ReflectionClass($node->cond->expr->args[0]->value->value);
|
2018-07-04 20:32:58 +02:00
|
|
|
|
2018-07-04 21:33:48 +02:00
|
|
|
if ($reflection_class->getFileName() !== $this->file_path) {
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning(
|
|
|
|
$node->cond->expr->args[0]->value->value,
|
|
|
|
$this->file_path
|
|
|
|
);
|
|
|
|
|
|
|
|
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
|
|
|
}
|
2018-04-27 21:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 19:29:35 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Expr\Yield_ || $node instanceof PhpParser\Node\Expr\YieldFrom) {
|
2018-07-15 23:47:58 +02:00
|
|
|
$function_like_storage = end($this->functionlike_storages);
|
|
|
|
|
|
|
|
if ($function_like_storage) {
|
|
|
|
$function_like_storage->has_yield = true;
|
|
|
|
}
|
2018-10-11 15:14:34 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Expr\Cast\Object_) {
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning('stdClass', null, false, false);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
2018-03-07 17:16:56 +01:00
|
|
|
* @return null
|
2017-11-26 22:03:17 +01:00
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function leaveNode(PhpParser\Node $node)
|
|
|
|
{
|
|
|
|
if ($node instanceof PhpParser\Node\Stmt\Namespace_) {
|
|
|
|
$this->aliases = $this->file_aliases;
|
2019-02-17 00:50:25 +01:00
|
|
|
|
|
|
|
if ($this->codebase->register_stub_files
|
|
|
|
&& $node->name
|
|
|
|
&& $node->name->parts === ['PHPSTORM_META']
|
|
|
|
) {
|
|
|
|
foreach ($node->stmts as $meta_stmt) {
|
|
|
|
if ($meta_stmt instanceof PhpParser\Node\Stmt\Expression
|
|
|
|
&& $meta_stmt->expr instanceof PhpParser\Node\Expr\FuncCall
|
|
|
|
&& $meta_stmt->expr->name instanceof PhpParser\Node\Name
|
|
|
|
&& $meta_stmt->expr->name->parts === ['override']
|
|
|
|
&& count($meta_stmt->expr->args) > 1
|
|
|
|
) {
|
|
|
|
PhpStormMetaScanner::handleOverride($meta_stmt->expr->args, $this->codebase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\ClassLike) {
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->fq_classlike_names) {
|
|
|
|
throw new \LogicException('$this->fq_classlike_names should not be empty');
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-10-19 20:40:38 +02:00
|
|
|
$fq_classlike_name = array_pop($this->fq_classlike_names);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-02-04 18:34:08 +01:00
|
|
|
if (PropertyMap::inPropertyMap($fq_classlike_name)) {
|
|
|
|
$public_mapped_properties = PropertyMap::getPropertyMap()[strtolower($fq_classlike_name)];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->classlike_storages) {
|
|
|
|
throw new \UnexpectedValueException('$this->classlike_storages cannot be empty');
|
2017-07-29 21:05:06 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$storage = $this->classlike_storages[count($this->classlike_storages) - 1];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
foreach ($public_mapped_properties as $property_name => $public_mapped_property) {
|
|
|
|
$property_type = Type::parseString($public_mapped_property);
|
|
|
|
|
2018-02-19 06:27:39 +01:00
|
|
|
$property_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
if (!isset($storage->properties[$property_name])) {
|
|
|
|
$storage->properties[$property_name] = new PropertyStorage();
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->properties[$property_name]->type = $property_type;
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->properties[$property_name]->visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
$property_id = $fq_classlike_name . '::$' . $property_name;
|
|
|
|
|
2018-07-22 01:56:26 +02:00
|
|
|
$storage->declaring_property_ids[$property_name] = $fq_classlike_name;
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->appearing_property_ids[$property_name] = $property_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 22:15:19 +01:00
|
|
|
if (!$this->classlike_storages) {
|
|
|
|
throw new \LogicException('$this->classlike_storages should not be empty');
|
|
|
|
}
|
|
|
|
|
2017-11-07 20:46:53 +01:00
|
|
|
$classlike_storage = array_pop($this->classlike_storages);
|
2017-07-29 21:05:06 +02:00
|
|
|
|
2018-05-29 16:13:26 +02:00
|
|
|
if ($classlike_storage->has_visitor_issues) {
|
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
}
|
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
if ($classlike_storage->has_docblock_issues) {
|
|
|
|
$this->file_storage->has_docblock_issues = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->class_template_types = [];
|
2017-11-07 20:46:53 +01:00
|
|
|
|
2018-02-12 04:49:19 +01:00
|
|
|
if ($this->after_classlike_check_plugins) {
|
2017-11-07 20:46:53 +01:00
|
|
|
$file_manipulations = [];
|
|
|
|
|
2018-02-12 04:49:19 +01:00
|
|
|
foreach ($this->after_classlike_check_plugins as $plugin_fq_class_name) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$plugin_fq_class_name::afterClassLikeVisit(
|
2017-11-07 20:46:53 +01:00
|
|
|
$node,
|
|
|
|
$classlike_storage,
|
2018-11-13 20:09:37 +01:00
|
|
|
$this,
|
|
|
|
$this->codebase,
|
2017-11-07 20:46:53 +01:00
|
|
|
$file_manipulations
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-02-19 06:27:39 +01:00
|
|
|
|
2018-05-29 16:13:26 +02:00
|
|
|
if (!$this->file_storage->has_visitor_issues) {
|
|
|
|
$this->codebase->cacheClassLikeStorage($classlike_storage, $this->file_path);
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Function_
|
|
|
|
|| $node instanceof PhpParser\Node\Stmt\ClassMethod
|
|
|
|
) {
|
|
|
|
$this->function_template_types = [];
|
|
|
|
} elseif ($node instanceof PhpParser\Node\FunctionLike) {
|
2018-12-19 22:15:19 +01:00
|
|
|
if (!$this->functionlike_storages) {
|
|
|
|
throw new \UnexpectedValueException('There should be function storages');
|
|
|
|
}
|
|
|
|
|
2018-05-29 16:13:26 +02:00
|
|
|
$functionlike_storage = array_pop($this->functionlike_storages);
|
|
|
|
|
|
|
|
if ($functionlike_storage->has_visitor_issues) {
|
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
if ($functionlike_storage->has_docblock_issues) {
|
|
|
|
$this->file_storage->has_docblock_issues = true;
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2017-11-26 22:03:17 +01:00
|
|
|
|
|
|
|
return null;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2019-01-28 23:54:50 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function registerClassMapFunctionCall(
|
|
|
|
string $function_id,
|
|
|
|
PhpParser\Node\Expr\FuncCall $node
|
|
|
|
) {
|
|
|
|
$function_params = CallMap::getParamsFromCallMap($function_id);
|
|
|
|
|
|
|
|
if ($function_params) {
|
|
|
|
foreach ($function_params as $function_param_group) {
|
|
|
|
foreach ($function_param_group as $function_param) {
|
|
|
|
if ($function_param->type) {
|
|
|
|
$function_param->type->queueClassLikesForScanning(
|
|
|
|
$this->codebase,
|
|
|
|
$this->file_storage
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$return_type = CallMap::getReturnTypeFromCallMap($function_id);
|
|
|
|
|
|
|
|
$return_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
|
|
|
|
|
|
|
if ($function_id === 'define') {
|
|
|
|
$first_arg_value = isset($node->args[0]) ? $node->args[0]->value : null;
|
|
|
|
$second_arg_value = isset($node->args[1]) ? $node->args[1]->value : null;
|
2019-02-18 19:51:27 +01:00
|
|
|
if ($first_arg_value && $second_arg_value) {
|
2019-02-22 00:19:12 +01:00
|
|
|
$const_name = StatementsAnalyzer::getConstName($first_arg_value, $this->codebase, $this->aliases);
|
|
|
|
|
2019-02-18 19:51:27 +01:00
|
|
|
if ($const_name !== null) {
|
|
|
|
$const_type = StatementsAnalyzer::getSimpleType(
|
|
|
|
$this->codebase,
|
|
|
|
$second_arg_value,
|
|
|
|
$this->aliases
|
|
|
|
) ?: Type::getMixed();
|
2019-03-25 05:07:32 +01:00
|
|
|
|
2019-02-18 19:51:27 +01:00
|
|
|
if ($this->functionlike_storages && !$this->config->hoist_constants) {
|
|
|
|
$functionlike_storage =
|
|
|
|
$this->functionlike_storages[count($this->functionlike_storages) - 1];
|
|
|
|
$functionlike_storage->defined_constants[$const_name] = $const_type;
|
|
|
|
} else {
|
|
|
|
$this->file_storage->constants[$const_name] = $const_type;
|
|
|
|
$this->file_storage->declaring_constants[$const_name] = $this->file_path;
|
|
|
|
}
|
2019-03-25 05:07:32 +01:00
|
|
|
|
|
|
|
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
|
|
|
|
$this->codebase->addGlobalConstantType($const_name, $const_type);
|
|
|
|
}
|
2019-01-28 23:54:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mapping_function_ids = [];
|
|
|
|
|
|
|
|
if (($function_id === 'array_map' && isset($node->args[0]))
|
|
|
|
|| ($function_id === 'array_filter' && isset($node->args[1]))
|
|
|
|
) {
|
|
|
|
$node_arg_value = $function_id = 'array_map' ? $node->args[0]->value : $node->args[1]->value;
|
|
|
|
|
|
|
|
if ($node_arg_value instanceof PhpParser\Node\Scalar\String_
|
|
|
|
|| $node_arg_value instanceof PhpParser\Node\Expr\Array_
|
|
|
|
|| $node_arg_value instanceof PhpParser\Node\Expr\BinaryOp\Concat
|
|
|
|
) {
|
|
|
|
$mapping_function_ids = CallAnalyzer::getFunctionIdsFromCallableArg(
|
|
|
|
$this->file_scanner,
|
|
|
|
$node_arg_value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($mapping_function_ids as $potential_method_id) {
|
|
|
|
if (strpos($potential_method_id, '::') === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
list($callable_fqcln) = explode('::', $potential_method_id);
|
|
|
|
|
|
|
|
if (!in_array(strtolower($callable_fqcln), ['self', 'parent', 'static'], true)) {
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning(
|
|
|
|
$callable_fqcln,
|
|
|
|
$this->file_path
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($function_id === 'func_get_arg'
|
|
|
|
|| $function_id === 'func_get_args'
|
|
|
|
|| $function_id === 'func_num_args'
|
|
|
|
) {
|
|
|
|
$function_like_storage = end($this->functionlike_storages);
|
|
|
|
|
|
|
|
if ($function_like_storage) {
|
|
|
|
$function_like_storage->variadic = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($function_id === 'is_a' || $function_id === 'is_subclass_of') {
|
|
|
|
$second_arg = $node->args[1]->value ?? null;
|
|
|
|
|
|
|
|
if ($second_arg instanceof PhpParser\Node\Scalar\String_) {
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning(
|
|
|
|
$second_arg->value,
|
|
|
|
$this->file_path
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($function_id === 'class_alias') {
|
|
|
|
$first_arg = $node->args[0]->value ?? null;
|
|
|
|
$second_arg = $node->args[1]->value ?? null;
|
|
|
|
|
|
|
|
if ($first_arg instanceof PhpParser\Node\Scalar\String_) {
|
|
|
|
$first_arg_value = $first_arg->value;
|
|
|
|
} elseif ($first_arg instanceof PhpParser\Node\Expr\ClassConstFetch
|
|
|
|
&& $first_arg->class instanceof PhpParser\Node\Name
|
|
|
|
&& $first_arg->name instanceof PhpParser\Node\Identifier
|
|
|
|
&& strtolower($first_arg->name->name) === 'class'
|
|
|
|
) {
|
|
|
|
/** @var string */
|
|
|
|
$first_arg_value = $first_arg->class->getAttribute('resolvedName');
|
|
|
|
} else {
|
|
|
|
$first_arg_value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($second_arg instanceof PhpParser\Node\Scalar\String_) {
|
|
|
|
$second_arg_value = $second_arg->value;
|
|
|
|
} elseif ($second_arg instanceof PhpParser\Node\Expr\ClassConstFetch
|
|
|
|
&& $second_arg->class instanceof PhpParser\Node\Name
|
|
|
|
&& $second_arg->name instanceof PhpParser\Node\Identifier
|
|
|
|
&& strtolower($second_arg->name->name) === 'class'
|
|
|
|
) {
|
|
|
|
/** @var string */
|
|
|
|
$second_arg_value = $second_arg->class->getAttribute('resolvedName');
|
|
|
|
} else {
|
|
|
|
$second_arg_value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($first_arg_value && $second_arg_value) {
|
|
|
|
$this->codebase->classlikes->addClassAlias(
|
|
|
|
$first_arg_value,
|
|
|
|
$second_arg_value
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->file_storage->classlike_aliases[strtolower($second_arg_value)] = $first_arg_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
/**
|
|
|
|
* @return false|null
|
|
|
|
*/
|
|
|
|
private function registerClassLike(PhpParser\Node\Stmt\ClassLike $node)
|
|
|
|
{
|
|
|
|
$class_location = new CodeLocation($this->file_scanner, $node, null, true);
|
|
|
|
|
|
|
|
$storage = null;
|
|
|
|
|
2019-01-20 17:10:12 +01:00
|
|
|
$class_name = null;
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
if ($node->name === null) {
|
|
|
|
if (!$node instanceof PhpParser\Node\Stmt\Class_) {
|
|
|
|
throw new \LogicException('Anonymous classes are always classes');
|
|
|
|
}
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
$fq_classlike_name = ClassAnalyzer::getAnonymousClassName($node, $this->file_path);
|
2018-07-22 04:24:33 +02:00
|
|
|
} else {
|
|
|
|
$fq_classlike_name =
|
|
|
|
($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $node->name->name;
|
|
|
|
|
2019-01-20 17:10:12 +01:00
|
|
|
$class_name = $node->name->name;
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
if ($this->codebase->classlike_storage_provider->has($fq_classlike_name)) {
|
|
|
|
$duplicate_storage = $this->codebase->classlike_storage_provider->get($fq_classlike_name);
|
|
|
|
|
|
|
|
if (!$this->codebase->register_stub_files) {
|
|
|
|
if (!$duplicate_storage->location
|
|
|
|
|| $duplicate_storage->location->file_path !== $this->file_path
|
|
|
|
|| $class_location->getHash() !== $duplicate_storage->location->getHash()
|
|
|
|
) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new DuplicateClass(
|
|
|
|
'Class ' . $fq_classlike_name . ' has already been defined'
|
|
|
|
. ($duplicate_storage->location
|
|
|
|
? ' in ' . $duplicate_storage->location->file_path
|
|
|
|
: ''),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
|
2018-09-04 20:34:14 +02:00
|
|
|
$duplicate_storage->has_visitor_issues = true;
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} elseif (!$duplicate_storage->location
|
|
|
|
|| $duplicate_storage->location->file_path !== $this->file_path
|
|
|
|
|| $class_location->getHash() !== $duplicate_storage->location->getHash()
|
|
|
|
) {
|
|
|
|
// we're overwriting some methods
|
|
|
|
$storage = $duplicate_storage;
|
2019-01-10 22:59:44 +01:00
|
|
|
$this->codebase->classlike_storage_provider->makeNew(strtolower($fq_classlike_name));
|
2019-01-24 21:03:13 +01:00
|
|
|
$storage->populated = false;
|
2019-01-26 22:58:49 +01:00
|
|
|
$storage->class_implements = []; // we do this because reflection reports
|
|
|
|
$storage->parent_interfaces = [];
|
2019-01-24 21:03:13 +01:00
|
|
|
|
|
|
|
foreach ($storage->dependent_classlikes as $dependent_name_lc => $_) {
|
|
|
|
$dependent_storage = $this->codebase->classlike_storage_provider->get($dependent_name_lc);
|
|
|
|
$dependent_storage->populated = false;
|
|
|
|
$this->codebase->classlike_storage_provider->makeNew($dependent_name_lc);
|
|
|
|
}
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$fq_classlike_name_lc = strtolower($fq_classlike_name);
|
|
|
|
|
|
|
|
$this->file_storage->classlikes_in_file[$fq_classlike_name_lc] = $fq_classlike_name;
|
|
|
|
|
|
|
|
$this->fq_classlike_names[] = $fq_classlike_name;
|
|
|
|
|
|
|
|
if (!$storage) {
|
2019-01-10 22:59:44 +01:00
|
|
|
$storage = $this->codebase->classlike_storage_provider->create($fq_classlike_name);
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:10:12 +01:00
|
|
|
if ($class_name
|
|
|
|
&& isset($this->aliases->uses[strtolower($class_name)])
|
2019-01-20 17:29:25 +01:00
|
|
|
&& $this->aliases->uses[strtolower($class_name)] !== $fq_classlike_name
|
2019-01-20 17:10:12 +01:00
|
|
|
) {
|
|
|
|
IssueBuffer::add(
|
|
|
|
new \Psalm\Issue\ParseError(
|
|
|
|
'Class name ' . $class_name . ' clashes with a use statement alias',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$storage->has_visitor_issues = true;
|
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
}
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
$storage->location = $class_location;
|
|
|
|
$storage->user_defined = !$this->codebase->register_stub_files;
|
|
|
|
$storage->stubbed = $this->codebase->register_stub_files;
|
|
|
|
|
|
|
|
$doc_comment = $node->getDocComment();
|
|
|
|
|
|
|
|
$this->classlike_storages[] = $storage;
|
|
|
|
|
2019-01-10 22:59:44 +01:00
|
|
|
if ($node instanceof PhpParser\Node\Stmt\Class_) {
|
|
|
|
$storage->abstract = (bool)$node->isAbstract();
|
|
|
|
$storage->final = (bool)$node->isFinal();
|
|
|
|
|
|
|
|
$this->codebase->classlikes->addFullyQualifiedClassName($fq_classlike_name, $this->file_path);
|
|
|
|
|
|
|
|
if ($node->extends) {
|
|
|
|
$parent_fqcln = ClassLikeAnalyzer::getFQCLNFromNameObject($node->extends, $this->aliases);
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning(
|
|
|
|
$parent_fqcln,
|
|
|
|
$this->file_path,
|
|
|
|
$this->scan_deep
|
|
|
|
);
|
|
|
|
$parent_fqcln_lc = strtolower($parent_fqcln);
|
2019-03-08 23:35:09 +01:00
|
|
|
$storage->parent_classes[$parent_fqcln_lc] = $parent_fqcln;
|
2019-01-10 22:59:44 +01:00
|
|
|
$this->file_storage->required_classes[strtolower($parent_fqcln)] = $parent_fqcln;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($node->implements as $interface) {
|
|
|
|
$interface_fqcln = ClassLikeAnalyzer::getFQCLNFromNameObject($interface, $this->aliases);
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($interface_fqcln, $this->file_path);
|
|
|
|
$storage->class_implements[strtolower($interface_fqcln)] = $interface_fqcln;
|
|
|
|
$this->file_storage->required_interfaces[strtolower($interface_fqcln)] = $interface_fqcln;
|
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Interface_) {
|
|
|
|
$storage->is_interface = true;
|
|
|
|
$this->codebase->classlikes->addFullyQualifiedInterfaceName($fq_classlike_name, $this->file_path);
|
|
|
|
|
|
|
|
foreach ($node->extends as $interface) {
|
|
|
|
$interface_fqcln = ClassLikeAnalyzer::getFQCLNFromNameObject($interface, $this->aliases);
|
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($interface_fqcln, $this->file_path);
|
|
|
|
$storage->parent_interfaces[strtolower($interface_fqcln)] = $interface_fqcln;
|
|
|
|
$this->file_storage->required_interfaces[strtolower($interface_fqcln)] = $interface_fqcln;
|
|
|
|
}
|
|
|
|
} elseif ($node instanceof PhpParser\Node\Stmt\Trait_) {
|
|
|
|
$storage->is_trait = true;
|
|
|
|
$this->file_storage->has_trait = true;
|
|
|
|
$this->codebase->classlikes->addFullyQualifiedTraitName($fq_classlike_name, $this->file_path);
|
|
|
|
$this->codebase->classlikes->addTraitNode(
|
|
|
|
$fq_classlike_name,
|
|
|
|
$node,
|
|
|
|
$this->aliases
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
if ($doc_comment) {
|
|
|
|
$docblock_info = null;
|
|
|
|
try {
|
2018-11-06 03:57:36 +01:00
|
|
|
$docblock_info = CommentAnalyzer::extractClassLikeDocblockInfo(
|
2019-03-19 02:05:37 +01:00
|
|
|
$node,
|
2018-07-22 04:24:33 +02:00
|
|
|
(string)$doc_comment,
|
|
|
|
$doc_comment->getLine()
|
|
|
|
);
|
|
|
|
} catch (DocblockParseException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info) {
|
2018-12-18 05:29:27 +01:00
|
|
|
if ($docblock_info->templates) {
|
2018-07-22 04:24:33 +02:00
|
|
|
$storage->template_types = [];
|
|
|
|
|
2019-05-06 22:38:08 +02:00
|
|
|
foreach ($docblock_info->templates as $i => $template_map) {
|
|
|
|
$template_name = $template_map[0];
|
|
|
|
|
|
|
|
if ($template_map[1] !== null && $template_map[2] !== null) {
|
|
|
|
if (trim($template_map[2])) {
|
2019-01-10 22:59:44 +01:00
|
|
|
try {
|
|
|
|
$template_type = Type::parseTokens(
|
2019-01-10 18:13:49 +01:00
|
|
|
Type::fixUpLocalType(
|
2019-05-06 22:38:08 +02:00
|
|
|
$template_map[2],
|
2019-01-10 18:13:49 +01:00
|
|
|
$this->aliases,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
|
|
|
)
|
2019-01-10 22:59:44 +01:00
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for '
|
|
|
|
. implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->template_types[$template_name] = [
|
2019-03-22 20:59:10 +01:00
|
|
|
$fq_classlike_name => [$template_type]
|
2019-01-10 18:13:49 +01:00
|
|
|
];
|
2019-01-08 21:11:57 +01:00
|
|
|
} else {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'Template missing as type',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
2018-07-22 04:24:33 +02:00
|
|
|
} else {
|
2019-03-22 20:59:10 +01:00
|
|
|
$storage->template_types[$template_name][$fq_classlike_name] = [Type::getMixed()];
|
2019-05-06 22:38:08 +02:00
|
|
|
$storage->template_covariants[$i] = $template_map[3];
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->class_template_types = $storage->template_types;
|
2019-01-10 23:58:32 +01:00
|
|
|
}
|
2018-07-22 04:24:33 +02:00
|
|
|
|
2019-01-10 23:58:32 +01:00
|
|
|
foreach ($docblock_info->template_extends as $extended_class_name) {
|
2019-01-28 03:00:27 +01:00
|
|
|
$this->extendTemplatedType($storage, $node, $extended_class_name);
|
|
|
|
}
|
2019-01-10 22:59:44 +01:00
|
|
|
|
2019-01-28 03:00:27 +01:00
|
|
|
foreach ($docblock_info->template_implements as $implemented_class_name) {
|
|
|
|
$this->implementTemplatedType($storage, $node, $implemented_class_name);
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info->properties) {
|
|
|
|
foreach ($docblock_info->properties as $property) {
|
|
|
|
$pseudo_property_type_tokens = Type::fixUpLocalType(
|
|
|
|
$property['type'],
|
|
|
|
$this->aliases,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
|
|
|
);
|
|
|
|
|
2018-11-02 04:04:00 +01:00
|
|
|
try {
|
|
|
|
$pseudo_property_type = Type::parseTokens($pseudo_property_type_tokens);
|
|
|
|
$pseudo_property_type->setFromDocblock();
|
2018-11-12 19:01:16 +01:00
|
|
|
$pseudo_property_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
2018-07-22 04:24:33 +02:00
|
|
|
|
2018-11-02 04:04:00 +01:00
|
|
|
if ($property['tag'] !== 'property-read') {
|
|
|
|
$storage->pseudo_property_set_types[$property['name']] = $pseudo_property_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($property['tag'] !== 'property-write') {
|
|
|
|
$storage->pseudo_property_get_types[$property['name']] = $pseudo_property_type;
|
|
|
|
}
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-07-22 04:24:33 +02:00
|
|
|
|
2018-11-02 04:04:00 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->deprecated = $docblock_info->deprecated;
|
2018-12-02 00:37:49 +01:00
|
|
|
$storage->internal = $docblock_info->internal;
|
2018-07-22 04:24:33 +02:00
|
|
|
|
|
|
|
$storage->sealed_properties = $docblock_info->sealed_properties;
|
|
|
|
$storage->sealed_methods = $docblock_info->sealed_methods;
|
|
|
|
|
2018-11-25 17:11:33 +01:00
|
|
|
$storage->override_property_visibility = $docblock_info->override_property_visibility;
|
|
|
|
$storage->override_method_visibility = $docblock_info->override_method_visibility;
|
2018-11-25 00:31:00 +01:00
|
|
|
|
2018-07-22 04:24:33 +02:00
|
|
|
$storage->suppressed_issues = $docblock_info->suppressed_issues;
|
|
|
|
|
|
|
|
foreach ($docblock_info->methods as $method) {
|
2018-11-30 21:13:25 +01:00
|
|
|
/** @var MethodStorage */
|
|
|
|
$pseudo_method_storage = $this->registerFunctionLike($method, true);
|
|
|
|
|
2019-01-18 17:37:52 +01:00
|
|
|
if ($pseudo_method_storage->is_static) {
|
|
|
|
$storage->pseudo_static_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
|
|
|
} else {
|
|
|
|
$storage->pseudo_methods[strtolower($method->name->name)] = $pseudo_method_storage;
|
|
|
|
}
|
2018-07-22 04:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($node->stmts as $node_stmt) {
|
|
|
|
if ($node_stmt instanceof PhpParser\Node\Stmt\ClassConst) {
|
|
|
|
$this->visitClassConstDeclaration($node_stmt, $storage, $fq_classlike_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($node->stmts as $node_stmt) {
|
|
|
|
if ($node_stmt instanceof PhpParser\Node\Stmt\Property) {
|
|
|
|
$this->visitPropertyDeclaration($node_stmt, $this->config, $storage, $fq_classlike_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:00:27 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function extendTemplatedType(
|
|
|
|
ClassLikeStorage $storage,
|
|
|
|
PhpParser\Node\Stmt\ClassLike $node,
|
|
|
|
string $extended_class_name
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
$extended_union_type = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$extended_class_name,
|
|
|
|
$this->aliases,
|
|
|
|
$this->class_template_types,
|
|
|
|
$this->type_aliases
|
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2019-01-28 03:00:27 +01:00
|
|
|
$this->class_template_types
|
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$extended_union_type->isSingle()) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-extends cannot be a union type',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($extended_union_type->getTypes() as $atomic_type) {
|
|
|
|
if (!$atomic_type instanceof Type\Atomic\TGenericObject) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-extends has invalid class ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$generic_class_lc = strtolower($atomic_type->value);
|
|
|
|
|
|
|
|
if (!isset($storage->parent_classes[$generic_class_lc])
|
|
|
|
&& !isset($storage->parent_interfaces[$generic_class_lc])
|
|
|
|
) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-extends must include the name of an extended class,'
|
|
|
|
. ' got ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$extended_type_parameters = [];
|
|
|
|
|
|
|
|
$storage->template_type_extends_count = count($atomic_type->type_params);
|
|
|
|
|
|
|
|
foreach ($atomic_type->type_params as $type_param) {
|
2019-03-16 16:15:25 +01:00
|
|
|
$extended_type_parameters[] = $type_param;
|
2019-01-28 03:00:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($extended_type_parameters) {
|
|
|
|
$storage->template_type_extends[$generic_class_lc] = $extended_type_parameters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function implementTemplatedType(
|
|
|
|
ClassLikeStorage $storage,
|
|
|
|
PhpParser\Node\Stmt\ClassLike $node,
|
|
|
|
string $implemented_class_name
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
$implemented_union_type = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$implemented_class_name,
|
|
|
|
$this->aliases,
|
|
|
|
$this->class_template_types,
|
|
|
|
$this->type_aliases
|
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2019-01-28 03:00:27 +01:00
|
|
|
$this->class_template_types
|
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$implemented_union_type->isSingle()) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-implements cannot be a union type',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($implemented_union_type->getTypes() as $atomic_type) {
|
|
|
|
if (!$atomic_type instanceof Type\Atomic\TGenericObject) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-implements has invalid class ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$generic_class_lc = strtolower($atomic_type->value);
|
|
|
|
|
|
|
|
if (!isset($storage->class_implements[$generic_class_lc])) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-implements must include the name of an implemented class,'
|
|
|
|
. ' got ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$implemented_type_parameters = [];
|
|
|
|
|
2019-01-28 05:12:40 +01:00
|
|
|
$storage->template_type_implements_count[$generic_class_lc] = count($atomic_type->type_params);
|
2019-01-28 03:00:27 +01:00
|
|
|
|
|
|
|
foreach ($atomic_type->type_params as $type_param) {
|
2019-03-16 16:15:25 +01:00
|
|
|
$implemented_type_parameters[] = $type_param;
|
2019-01-28 03:00:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($implemented_type_parameters) {
|
|
|
|
$storage->template_type_extends[$generic_class_lc] = $implemented_type_parameters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 05:12:40 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function useTemplatedType(
|
|
|
|
ClassLikeStorage $storage,
|
|
|
|
PhpParser\Node\Stmt\TraitUse $node,
|
|
|
|
string $used_class_name
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
$used_union_type = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$used_class_name,
|
|
|
|
$this->aliases,
|
|
|
|
$this->class_template_types,
|
|
|
|
$this->type_aliases
|
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2019-01-28 05:12:40 +01:00
|
|
|
$this->class_template_types
|
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$used_union_type->isSingle()) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-use cannot be a union type',
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($used_union_type->getTypes() as $atomic_type) {
|
|
|
|
if (!$atomic_type instanceof Type\Atomic\TGenericObject) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-use has invalid class ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$generic_class_lc = strtolower($atomic_type->value);
|
|
|
|
|
|
|
|
if (!isset($storage->used_traits[$generic_class_lc])) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'@template-use must include the name of an used class,'
|
|
|
|
. ' got ' . $atomic_type->getId(),
|
|
|
|
new CodeLocation($this->file_scanner, $node, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$used_type_parameters = [];
|
|
|
|
|
|
|
|
$storage->template_type_uses_count[$generic_class_lc] = count($atomic_type->type_params);
|
|
|
|
|
|
|
|
foreach ($atomic_type->type_params as $type_param) {
|
2019-03-16 16:15:25 +01:00
|
|
|
$used_type_parameters[] = $type_param;
|
2019-01-28 05:12:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($used_type_parameters) {
|
|
|
|
$storage->template_type_extends[$generic_class_lc] = $used_type_parameters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
|
|
|
* @param PhpParser\Node\FunctionLike $stmt
|
2018-04-22 04:13:10 +02:00
|
|
|
* @param bool $fake_method in the case of @method annotations we do something a little strange
|
2017-07-25 22:11:02 +02:00
|
|
|
*
|
2019-01-02 17:18:22 +01:00
|
|
|
* @return FunctionLikeStorage|false
|
2017-07-25 22:11:02 +02:00
|
|
|
*/
|
2018-04-22 04:13:10 +02:00
|
|
|
private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_method = false)
|
2017-07-25 22:11:02 +02:00
|
|
|
{
|
|
|
|
$class_storage = null;
|
|
|
|
|
2018-06-14 23:20:02 +02:00
|
|
|
if ($fake_method && $stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
|
2018-04-22 04:13:10 +02:00
|
|
|
$cased_function_id = '@method ' . $stmt->name->name;
|
|
|
|
|
2018-11-30 21:13:25 +01:00
|
|
|
$storage = new MethodStorage();
|
2019-01-28 05:12:40 +01:00
|
|
|
$storage->defining_fqcln = '';
|
2019-01-18 17:37:52 +01:00
|
|
|
$storage->is_static = (bool) $stmt->isStatic();
|
2018-04-22 04:13:10 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\Function_) {
|
2018-04-17 18:16:25 +02:00
|
|
|
$cased_function_id =
|
|
|
|
($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $stmt->name->name;
|
2017-07-25 22:11:02 +02:00
|
|
|
$function_id = strtolower($cased_function_id);
|
|
|
|
|
2019-01-06 23:24:46 +01:00
|
|
|
$storage = new FunctionLikeStorage();
|
|
|
|
|
2019-01-06 22:40:44 +01:00
|
|
|
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
|
|
|
|
if (isset($this->file_storage->functions[$function_id])) {
|
2018-06-30 21:29:37 +02:00
|
|
|
$this->codebase->functions->addGlobalFunction(
|
|
|
|
$function_id,
|
|
|
|
$this->file_storage->functions[$function_id]
|
|
|
|
);
|
2019-01-06 22:40:44 +01:00
|
|
|
|
|
|
|
return $this->file_storage->functions[$function_id];
|
2018-06-30 21:29:37 +02:00
|
|
|
}
|
2019-01-06 22:40:44 +01:00
|
|
|
} else {
|
|
|
|
if (isset($this->file_storage->functions[$function_id])) {
|
|
|
|
$duplicate_function_storage = $this->file_storage->functions[$function_id];
|
|
|
|
|
2019-01-20 17:10:12 +01:00
|
|
|
if ($duplicate_function_storage->location
|
|
|
|
&& $duplicate_function_storage->location->getLineNumber() === $stmt->getLine()
|
|
|
|
) {
|
|
|
|
return $this->file_storage->functions[$function_id];
|
|
|
|
}
|
|
|
|
|
2019-01-06 22:40:44 +01:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new DuplicateFunction(
|
|
|
|
'Method ' . $function_id . ' has already been defined'
|
|
|
|
. ($duplicate_function_storage->location
|
|
|
|
? ' in ' . $duplicate_function_storage->location->file_path
|
|
|
|
: ''),
|
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
// fall through
|
|
|
|
}
|
2018-06-30 21:29:37 +02:00
|
|
|
|
2019-01-06 22:40:44 +01:00
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
|
|
|
|
$duplicate_function_storage->has_visitor_issues = true;
|
|
|
|
|
|
|
|
return $this->file_storage->functions[$function_id];
|
|
|
|
} elseif (isset($this->config->getPredefinedFunctions()[$function_id])) {
|
2019-04-10 00:09:57 +02:00
|
|
|
/** @psalm-suppress TypeCoercion */
|
2019-01-06 23:24:46 +01:00
|
|
|
$reflection_function = new \ReflectionFunction($function_id);
|
2019-01-06 23:03:13 +01:00
|
|
|
|
2019-01-06 23:24:46 +01:00
|
|
|
if ($reflection_function->getFileName() !== $this->file_path) {
|
2019-01-06 23:03:13 +01:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new DuplicateFunction(
|
|
|
|
'Method ' . $function_id . ' has already been defined as a core function',
|
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
// fall through
|
|
|
|
}
|
2019-01-06 22:40:44 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-29 21:28:45 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 21:29:37 +02:00
|
|
|
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
|
|
|
|
$this->codebase->functions->addGlobalFunction($function_id, $storage);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2018-06-29 21:28:45 +02:00
|
|
|
|
|
|
|
$this->file_storage->functions[$function_id] = $storage;
|
|
|
|
$this->file_storage->declaring_function_ids[$function_id] = strtolower($this->file_path);
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->fq_classlike_names) {
|
|
|
|
throw new \LogicException('$this->fq_classlike_names should not be null');
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$fq_classlike_name = $this->fq_classlike_names[count($this->fq_classlike_names) - 1];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
$function_id = $fq_classlike_name . '::' . strtolower($stmt->name->name);
|
|
|
|
$cased_function_id = $fq_classlike_name . '::' . $stmt->name->name;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->classlike_storages) {
|
|
|
|
throw new \UnexpectedValueException('$class_storages cannot be empty for ' . $function_id);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$class_storage = $this->classlike_storages[count($this->classlike_storages) - 1];
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-06-30 21:29:37 +02:00
|
|
|
$storage = null;
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if (isset($class_storage->methods[strtolower($stmt->name->name)])) {
|
2018-06-30 21:29:37 +02:00
|
|
|
if (!$this->codebase->register_stub_files) {
|
2019-01-02 17:18:22 +01:00
|
|
|
$duplicate_method_storage = $class_storage->methods[strtolower($stmt->name->name)];
|
|
|
|
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new DuplicateMethod(
|
|
|
|
'Method ' . $function_id . ' has already been defined'
|
|
|
|
. ($duplicate_method_storage->location
|
|
|
|
? ' in ' . $duplicate_method_storage->location->file_path
|
|
|
|
: ''),
|
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
// fall through
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->file_storage->has_visitor_issues = true;
|
|
|
|
|
|
|
|
$duplicate_method_storage->has_visitor_issues = true;
|
|
|
|
|
|
|
|
return false;
|
2018-06-30 21:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$storage = $class_storage->methods[strtolower($stmt->name->name)];
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 21:29:37 +02:00
|
|
|
if (!$storage) {
|
|
|
|
$storage = $class_storage->methods[strtolower($stmt->name->name)] = new MethodStorage();
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-01-28 05:12:40 +01:00
|
|
|
$storage->defining_fqcln = $fq_classlike_name;
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$class_name_parts = explode('\\', $fq_classlike_name);
|
|
|
|
$class_name = array_pop($class_name_parts);
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if (strtolower($stmt->name->name) === strtolower($class_name) &&
|
2017-07-25 22:11:02 +02:00
|
|
|
!isset($class_storage->methods['__construct']) &&
|
|
|
|
strpos($fq_classlike_name, '\\') === false
|
|
|
|
) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setDeclaringMethodId(
|
2017-07-29 21:05:06 +02:00
|
|
|
$fq_classlike_name . '::__construct',
|
|
|
|
$function_id
|
|
|
|
);
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->methods->setAppearingMethodId(
|
2017-07-29 21:05:06 +02:00
|
|
|
$fq_classlike_name . '::__construct',
|
|
|
|
$function_id
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
$class_storage->declaring_method_ids[strtolower($stmt->name->name)] = $function_id;
|
|
|
|
$class_storage->appearing_method_ids[strtolower($stmt->name->name)] = $function_id;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if (!$stmt->isPrivate() || $stmt->name->name === '__construct' || $class_storage->is_trait) {
|
|
|
|
$class_storage->inheritable_method_ids[strtolower($stmt->name->name)] = $function_id;
|
2017-11-09 03:27:23 +01:00
|
|
|
}
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if (!isset($class_storage->overridden_method_ids[strtolower($stmt->name->name)])) {
|
|
|
|
$class_storage->overridden_method_ids[strtolower($stmt->name->name)] = [];
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-17 05:19:55 +01:00
|
|
|
$storage->is_static = (bool) $stmt->isStatic();
|
|
|
|
$storage->abstract = (bool) $stmt->isAbstract();
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-11-30 05:46:56 +01:00
|
|
|
$storage->final = $class_storage->final || $stmt->isFinal();
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($stmt->isPrivate()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->visibility = ClassLikeAnalyzer::VISIBILITY_PRIVATE;
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt->isProtected()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->visibility = ClassLikeAnalyzer::VISIBILITY_PROTECTED;
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2018-11-06 03:57:36 +01:00
|
|
|
$storage->visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-25 10:21:54 +02:00
|
|
|
$function_id = $cased_function_id = $this->file_path
|
|
|
|
. ':' . $stmt->getLine()
|
|
|
|
. ':' . (int) $stmt->getAttribute('startFilePos') . ':-:closure';
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
$storage = $this->file_storage->functions[$function_id] = new FunctionLikeStorage();
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$this->functionlike_storages[] = $storage;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-06-29 21:28:45 +02:00
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
|
2018-04-17 18:16:25 +02:00
|
|
|
$storage->cased_name = $stmt->name->name;
|
2018-06-29 21:28:45 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\Function_) {
|
|
|
|
$storage->cased_name =
|
|
|
|
($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $stmt->name->name;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 22:07:48 +02:00
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod || $stmt instanceof PhpParser\Node\Stmt\Function_) {
|
|
|
|
$storage->location = new CodeLocation($this->file_scanner, $stmt->name, null, true);
|
|
|
|
} else {
|
|
|
|
$storage->location = new CodeLocation($this->file_scanner, $stmt, null, true);
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-04-17 17:12:18 +02:00
|
|
|
$storage->stmt_location = new CodeLocation($this->file_scanner, $stmt);
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$required_param_count = 0;
|
|
|
|
$i = 0;
|
|
|
|
$has_optional_param = false;
|
|
|
|
|
2017-09-02 17:18:56 +02:00
|
|
|
$existing_params = [];
|
2018-06-30 21:29:37 +02:00
|
|
|
$storage->params = [];
|
2017-09-02 17:18:56 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/** @var PhpParser\Node\Param $param */
|
|
|
|
foreach ($stmt->getParams() as $param) {
|
2018-06-03 16:05:50 +02:00
|
|
|
if ($param->var instanceof PhpParser\Node\Expr\Error) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
'Param' . ((int) $i + 1) . ' of ' . $cased_function_id . ' has invalid syntax',
|
|
|
|
new CodeLocation($this->file_scanner, $param, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
2018-06-04 04:13:19 +02:00
|
|
|
}
|
2018-06-03 16:05:50 +02:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
|
2018-06-04 04:13:19 +02:00
|
|
|
++$i;
|
2018-06-03 16:05:50 +02:00
|
|
|
|
2018-06-04 04:13:19 +02:00
|
|
|
continue;
|
2018-06-03 16:05:50 +02:00
|
|
|
}
|
|
|
|
|
2019-03-19 02:05:37 +01:00
|
|
|
$param_array = $this->getTranslatedFunctionParam($param, $stmt, $fake_method);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-02-23 21:39:33 +01:00
|
|
|
if (isset($existing_params['$' . $param_array->name])) {
|
2017-07-25 22:11:02 +02:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new DuplicateParam(
|
2018-04-17 18:16:25 +02:00
|
|
|
'Duplicate param $' . $param_array->name . ' in docblock for ' . $cased_function_id,
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $param, null, true)
|
2017-07-25 22:11:02 +02:00
|
|
|
)
|
|
|
|
)) {
|
2018-11-01 22:03:08 +01:00
|
|
|
}
|
2018-05-29 16:13:26 +02:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
2018-06-03 16:05:50 +02:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
++$i;
|
|
|
|
|
|
|
|
continue;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-02-23 21:39:33 +01:00
|
|
|
$existing_params['$' . $param_array->name] = $i;
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->param_types[$param_array->name] = $param_array->type;
|
|
|
|
$storage->params[] = $param_array;
|
|
|
|
|
2019-03-02 21:26:18 +01:00
|
|
|
if (!$param_array->is_optional && !$param_array->is_variadic) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$required_param_count = $i + 1;
|
|
|
|
|
2018-06-03 16:05:50 +02:00
|
|
|
if (!$param->variadic
|
|
|
|
&& $has_optional_param
|
|
|
|
&& is_string($param->var->name)
|
|
|
|
) {
|
2017-07-25 22:11:02 +02:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new MisplacedRequiredParam(
|
2018-04-17 18:16:25 +02:00
|
|
|
'Required param $' . $param->var->name . ' should come before any optional params in ' .
|
2017-07-25 22:11:02 +02:00
|
|
|
$cased_function_id,
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $param, null, true)
|
2017-07-25 22:11:02 +02:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
$storage->has_visitor_issues = true;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$has_optional_param = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++$i;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->required_param_count = $required_param_count;
|
|
|
|
|
2017-09-21 22:31:19 +02:00
|
|
|
if (($stmt instanceof PhpParser\Node\Stmt\Function_
|
|
|
|
|| $stmt instanceof PhpParser\Node\Stmt\ClassMethod)
|
2018-04-17 18:16:25 +02:00
|
|
|
&& strpos($stmt->name->name, 'assert') === 0
|
2017-09-21 22:31:19 +02:00
|
|
|
&& $stmt->stmts
|
|
|
|
) {
|
2017-09-21 21:36:26 +02:00
|
|
|
$var_assertions = [];
|
|
|
|
|
|
|
|
foreach ($stmt->stmts as $function_stmt) {
|
2018-02-23 21:39:33 +01:00
|
|
|
if ($function_stmt instanceof PhpParser\Node\Stmt\If_) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$final_actions = \Psalm\Internal\Analyzer\ScopeAnalyzer::getFinalControlActions(
|
2018-02-23 21:39:33 +01:00
|
|
|
$function_stmt->stmts,
|
2018-07-13 05:26:08 +02:00
|
|
|
$this->config->exit_functions,
|
2018-02-23 21:39:33 +01:00
|
|
|
false,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
if ($final_actions !== [\Psalm\Internal\Analyzer\ScopeAnalyzer::ACTION_END]) {
|
2018-11-14 19:53:57 +01:00
|
|
|
$var_assertions = [];
|
|
|
|
break;
|
2018-02-23 21:39:33 +01:00
|
|
|
}
|
|
|
|
|
2018-05-07 07:26:06 +02:00
|
|
|
$if_clauses = \Psalm\Type\Algebra::getFormula(
|
2018-02-23 21:39:33 +01:00
|
|
|
$function_stmt->cond,
|
|
|
|
$this->fq_classlike_names
|
|
|
|
? $this->fq_classlike_names[count($this->fq_classlike_names) - 1]
|
|
|
|
: null,
|
2018-11-06 03:57:36 +01:00
|
|
|
$this->file_scanner,
|
|
|
|
null
|
2018-02-23 21:39:33 +01:00
|
|
|
);
|
|
|
|
|
2018-05-07 07:26:06 +02:00
|
|
|
$negated_formula = \Psalm\Type\Algebra::negateFormula($if_clauses);
|
2017-09-21 21:36:26 +02:00
|
|
|
|
2018-05-07 07:26:06 +02:00
|
|
|
$rules = \Psalm\Type\Algebra::getTruthsFromFormula($negated_formula);
|
2018-02-23 21:39:33 +01:00
|
|
|
|
2018-11-30 05:25:30 +01:00
|
|
|
if (!$rules) {
|
|
|
|
$var_assertions = [];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:39:33 +01:00
|
|
|
foreach ($rules as $var_id => $rule) {
|
2018-05-13 01:38:43 +02:00
|
|
|
foreach ($rule as $rule_part) {
|
|
|
|
if (count($rule_part) > 1) {
|
|
|
|
continue 2;
|
|
|
|
}
|
2018-02-25 17:30:45 +01:00
|
|
|
}
|
|
|
|
|
2018-02-23 21:39:33 +01:00
|
|
|
if (isset($existing_params[$var_id])) {
|
|
|
|
$param_offset = $existing_params[$var_id];
|
|
|
|
|
|
|
|
$var_assertions[] = new \Psalm\Storage\Assertion(
|
|
|
|
$param_offset,
|
|
|
|
$rule
|
|
|
|
);
|
|
|
|
} elseif (strpos($var_id, '$this->') === 0) {
|
|
|
|
$var_assertions[] = new \Psalm\Storage\Assertion(
|
|
|
|
$var_id,
|
|
|
|
$rule
|
|
|
|
);
|
2017-09-21 21:36:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-14 19:53:57 +01:00
|
|
|
} else {
|
|
|
|
$var_assertions = [];
|
|
|
|
break;
|
2017-09-21 21:36:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->assertions = $var_assertions;
|
|
|
|
}
|
|
|
|
|
2018-03-17 14:22:28 +01:00
|
|
|
if (!$this->scan_deep
|
|
|
|
&& ($stmt instanceof PhpParser\Node\Stmt\Function_
|
|
|
|
|| $stmt instanceof PhpParser\Node\Stmt\ClassMethod
|
|
|
|
|| $stmt instanceof PhpParser\Node\Expr\Closure)
|
|
|
|
&& $stmt->stmts
|
|
|
|
) {
|
|
|
|
// pick up func_get_args that would otherwise be missed
|
|
|
|
foreach ($stmt->stmts as $function_stmt) {
|
2018-04-17 18:16:25 +02:00
|
|
|
if ($function_stmt instanceof PhpParser\Node\Stmt\Expression
|
|
|
|
&& $function_stmt->expr instanceof PhpParser\Node\Expr\Assign
|
|
|
|
&& ($function_stmt->expr->expr instanceof PhpParser\Node\Expr\FuncCall)
|
|
|
|
&& ($function_stmt->expr->expr->name instanceof PhpParser\Node\Name)
|
2018-03-17 14:22:28 +01:00
|
|
|
) {
|
2018-04-17 18:16:25 +02:00
|
|
|
$function_id = implode('\\', $function_stmt->expr->expr->name->parts);
|
2018-03-17 14:22:28 +01:00
|
|
|
|
|
|
|
if ($function_id === 'func_get_arg'
|
|
|
|
|| $function_id === 'func_get_args'
|
|
|
|
|| $function_id === 'func_num_args'
|
|
|
|
) {
|
|
|
|
$storage->variadic = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
$parser_return_type = $stmt->getReturnType();
|
|
|
|
|
|
|
|
if ($parser_return_type) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$suffix = '';
|
|
|
|
|
2019-03-08 05:19:17 +01:00
|
|
|
$original_type = $parser_return_type;
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($parser_return_type instanceof PhpParser\Node\NullableType) {
|
|
|
|
$suffix = '|null';
|
|
|
|
$parser_return_type = $parser_return_type->type;
|
|
|
|
}
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
if ($parser_return_type instanceof PhpParser\Node\Identifier) {
|
|
|
|
$return_type_string = $parser_return_type->name . $suffix;
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2018-11-06 03:57:36 +01:00
|
|
|
$return_type_fq_classlike_name = ClassLikeAnalyzer::getFQCLNFromNameObject(
|
2017-07-25 22:11:02 +02:00
|
|
|
$parser_return_type,
|
|
|
|
$this->aliases
|
|
|
|
);
|
|
|
|
|
|
|
|
$return_type_string = $return_type_fq_classlike_name . $suffix;
|
|
|
|
}
|
|
|
|
|
2019-02-07 18:25:57 +01:00
|
|
|
$storage->return_type = Type::parseString(
|
|
|
|
$return_type_string,
|
|
|
|
[$this->php_major_version, $this->php_minor_version]
|
|
|
|
);
|
2018-10-17 20:10:16 +02:00
|
|
|
$storage->return_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->return_type_location = new CodeLocation(
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner,
|
2019-03-08 05:19:17 +01:00
|
|
|
$original_type
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
|
|
|
|
2018-01-12 05:18:13 +01:00
|
|
|
if ($stmt->returnsByRef()) {
|
|
|
|
$storage->return_type->by_ref = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->signature_return_type = $storage->return_type;
|
|
|
|
$storage->signature_return_type_location = $storage->return_type_location;
|
|
|
|
}
|
|
|
|
|
2018-01-13 07:25:13 +01:00
|
|
|
if ($stmt->returnsByRef()) {
|
|
|
|
$storage->returns_by_ref = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$doc_comment = $stmt->getDocComment();
|
|
|
|
|
|
|
|
if (!$doc_comment) {
|
2018-04-22 04:13:10 +02:00
|
|
|
return $storage;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-11-06 03:57:36 +01:00
|
|
|
$docblock_info = CommentAnalyzer::extractFunctionDocblockInfo(
|
|
|
|
(string)$doc_comment,
|
|
|
|
$doc_comment->getLine()
|
|
|
|
);
|
2017-11-15 03:43:31 +01:00
|
|
|
} catch (IncorrectDocblockException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new MissingDocblockType(
|
|
|
|
$e->getMessage() . ' in docblock for ' . $cased_function_id,
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
2017-11-15 03:43:31 +01:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2017-11-28 06:46:41 +01:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
2017-11-28 06:46:41 +01:00
|
|
|
$docblock_info = null;
|
2017-07-25 22:11:02 +02:00
|
|
|
} catch (DocblockParseException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . $cased_function_id,
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
2017-07-25 22:11:02 +02:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2017-11-28 06:46:41 +01:00
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
|
2017-11-28 06:46:41 +01:00
|
|
|
$docblock_info = null;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$docblock_info) {
|
2018-04-22 04:13:10 +02:00
|
|
|
return $storage;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info->deprecated) {
|
|
|
|
$storage->deprecated = true;
|
|
|
|
}
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
if ($docblock_info->internal) {
|
|
|
|
$storage->internal = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($docblock_info->variadic) {
|
|
|
|
$storage->variadic = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info->ignore_nullable_return && $storage->return_type) {
|
|
|
|
$storage->return_type->ignore_nullable_issues = true;
|
|
|
|
}
|
|
|
|
|
2018-01-25 00:52:58 +01:00
|
|
|
if ($docblock_info->ignore_falsable_return && $storage->return_type) {
|
|
|
|
$storage->return_type->ignore_falsable_issues = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->suppressed_issues = $docblock_info->suppress;
|
|
|
|
|
2019-03-24 21:17:14 +01:00
|
|
|
if ($this->config->check_for_throws_docblock ||
|
|
|
|
$this->config->check_for_throws_in_global_scope
|
|
|
|
) {
|
2018-06-22 07:13:49 +02:00
|
|
|
foreach ($docblock_info->throws as $throw_class) {
|
|
|
|
$exception_fqcln = Type::getFQCLNFromString(
|
|
|
|
$throw_class,
|
|
|
|
$this->aliases
|
|
|
|
);
|
|
|
|
|
2018-11-25 22:14:50 +01:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($exception_fqcln, $this->file_path);
|
2018-11-29 07:46:12 +01:00
|
|
|
$this->file_storage->referenced_classlikes[strtolower($exception_fqcln)] = $exception_fqcln;
|
2018-11-25 22:14:50 +01:00
|
|
|
|
2018-06-22 07:13:49 +02:00
|
|
|
$storage->throws[$exception_fqcln] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if (!$this->config->use_docblock_types) {
|
2018-04-22 04:13:10 +02:00
|
|
|
return $storage;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 17:01:24 +01:00
|
|
|
if ($storage instanceof MethodStorage && $docblock_info->inheritdoc) {
|
|
|
|
$storage->inheritdoc = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$template_types = $class_storage && $class_storage->template_types ? $class_storage->template_types : null;
|
|
|
|
|
2018-12-18 05:29:27 +01:00
|
|
|
if ($docblock_info->templates) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->template_types = [];
|
|
|
|
|
2019-05-06 22:38:08 +02:00
|
|
|
foreach ($docblock_info->templates as $i => $template_map) {
|
|
|
|
$template_name = $template_map[0];
|
|
|
|
|
|
|
|
if ($template_map[1] !== null && $template_map[2] !== null) {
|
2019-02-05 23:39:11 +01:00
|
|
|
if (trim($template_map[2])) {
|
|
|
|
$template_type = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$template_map[2],
|
|
|
|
$this->aliases,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
|
|
|
)
|
|
|
|
);
|
2019-01-08 21:11:57 +01:00
|
|
|
} else {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
2019-05-06 22:38:08 +02:00
|
|
|
'Template ' . $template_name . ' missing as type',
|
2019-01-08 21:11:57 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2019-02-05 23:39:11 +01:00
|
|
|
|
|
|
|
$template_type = Type::getMixed();
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2019-02-05 23:39:11 +01:00
|
|
|
$template_type = Type::getMixed();
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2019-02-05 23:39:11 +01:00
|
|
|
|
2019-05-06 22:38:08 +02:00
|
|
|
if (isset($template_types[$template_name])) {
|
2019-03-01 05:43:55 +01:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
2019-05-06 22:38:08 +02:00
|
|
|
'Duplicate template param ' . $template_name . ' in docblock for '
|
2019-03-01 05:43:55 +01:00
|
|
|
. $cased_function_id,
|
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
2019-03-01 06:06:35 +01:00
|
|
|
} else {
|
2019-05-06 22:38:08 +02:00
|
|
|
$storage->template_types[$template_name] = [
|
2019-03-22 20:59:10 +01:00
|
|
|
'' => [$template_type]
|
2019-03-01 06:06:35 +01:00
|
|
|
];
|
2019-05-06 22:38:08 +02:00
|
|
|
|
|
|
|
$storage->template_covariants[$i] = $template_map[3];
|
2019-03-01 05:43:55 +01:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$template_types = array_merge($template_types ?: [], $storage->template_types);
|
|
|
|
|
|
|
|
$this->function_template_types = $template_types;
|
|
|
|
}
|
|
|
|
|
2018-05-28 21:07:42 +02:00
|
|
|
if ($docblock_info->assertions) {
|
|
|
|
$storage->assertions = [];
|
|
|
|
|
|
|
|
foreach ($docblock_info->assertions as $assertion) {
|
2019-01-12 17:40:19 +01:00
|
|
|
$assertion_type = $assertion['type'];
|
|
|
|
$prefix = '';
|
|
|
|
if ($assertion_type[0] === '!') {
|
|
|
|
$prefix = '!';
|
|
|
|
$assertion_type = substr($assertion_type, 1);
|
|
|
|
}
|
|
|
|
if ($assertion_type[0] === '~') {
|
|
|
|
$prefix .= '~';
|
|
|
|
$assertion_type = substr($assertion_type, 1);
|
|
|
|
}
|
|
|
|
if ($assertion_type[0] === '=') {
|
|
|
|
$prefix .= '=';
|
|
|
|
$assertion_type = substr($assertion_type, 1);
|
|
|
|
}
|
|
|
|
|
2019-01-13 20:06:30 +01:00
|
|
|
if ($assertion_type !== 'falsy'
|
|
|
|
&& !isset($template_types[$assertion_type])
|
|
|
|
&& !isset(Type::PSALM_RESERVED_WORDS[$assertion_type])
|
|
|
|
) {
|
2019-01-12 17:40:19 +01:00
|
|
|
$assertion_type = Type::getFQCLNFromString($assertion_type, $this->aliases);
|
|
|
|
}
|
|
|
|
|
2018-05-28 21:07:42 +02:00
|
|
|
foreach ($storage->params as $i => $param) {
|
|
|
|
if ($param->name === $assertion['param_name']) {
|
|
|
|
$storage->assertions[] = new \Psalm\Storage\Assertion(
|
|
|
|
$i,
|
2019-01-12 17:40:19 +01:00
|
|
|
[[$prefix . $assertion_type]]
|
2018-05-28 21:07:42 +02:00
|
|
|
);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->assertions[] = new \Psalm\Storage\Assertion(
|
2018-11-14 21:40:56 +01:00
|
|
|
'$' . $assertion['param_name'],
|
2019-01-12 17:40:19 +01:00
|
|
|
[[$prefix . $assertion_type]]
|
2018-05-28 21:07:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info->if_true_assertions) {
|
|
|
|
$storage->assertions = [];
|
|
|
|
|
|
|
|
foreach ($docblock_info->if_true_assertions as $assertion) {
|
|
|
|
foreach ($storage->params as $i => $param) {
|
|
|
|
if ($param->name === $assertion['param_name']) {
|
|
|
|
$storage->if_true_assertions[] = new \Psalm\Storage\Assertion(
|
|
|
|
$i,
|
|
|
|
[[$assertion['type']]]
|
|
|
|
);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->if_true_assertions[] = new \Psalm\Storage\Assertion(
|
2018-11-14 21:40:56 +01:00
|
|
|
'$' . $assertion['param_name'],
|
2018-05-28 21:07:42 +02:00
|
|
|
[[$assertion['type']]]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_info->if_false_assertions) {
|
|
|
|
$storage->assertions = [];
|
|
|
|
|
|
|
|
foreach ($docblock_info->if_false_assertions as $assertion) {
|
|
|
|
foreach ($storage->params as $i => $param) {
|
|
|
|
if ($param->name === $assertion['param_name']) {
|
|
|
|
$storage->if_false_assertions[] = new \Psalm\Storage\Assertion(
|
|
|
|
$i,
|
|
|
|
[[$assertion['type']]]
|
|
|
|
);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->if_false_assertions[] = new \Psalm\Storage\Assertion(
|
2018-11-14 21:40:56 +01:00
|
|
|
'$' . $assertion['param_name'],
|
2018-05-28 21:07:42 +02:00
|
|
|
[[$assertion['type']]]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($docblock_info->return_type) {
|
2018-01-09 21:44:31 +01:00
|
|
|
if (!$storage->return_type || $docblock_info->return_type !== $storage->return_type->getId()) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->has_template_return_type =
|
|
|
|
$template_types !== null &&
|
|
|
|
count(
|
|
|
|
array_intersect(
|
|
|
|
Type::tokenize($docblock_info->return_type),
|
|
|
|
array_keys($template_types)
|
|
|
|
)
|
|
|
|
) > 0;
|
|
|
|
|
|
|
|
$docblock_return_type = $docblock_info->return_type;
|
|
|
|
|
|
|
|
if (!$storage->return_type_location) {
|
2018-01-02 02:04:03 +01:00
|
|
|
$storage->return_type_location = new CodeLocation(
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner,
|
2018-01-02 02:04:03 +01:00
|
|
|
$stmt,
|
|
|
|
null,
|
|
|
|
false,
|
2019-03-19 02:05:37 +01:00
|
|
|
!$fake_method
|
|
|
|
? CodeLocation::FUNCTION_PHPDOC_RETURN_TYPE
|
|
|
|
: CodeLocation::FUNCTION_PHPDOC_METHOD,
|
2018-01-02 02:04:03 +01:00
|
|
|
$docblock_info->return_type
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_return_type) {
|
|
|
|
try {
|
2018-05-20 23:19:53 +02:00
|
|
|
$fixed_type_tokens = Type::fixUpLocalType(
|
2018-03-27 14:07:44 +02:00
|
|
|
$docblock_return_type,
|
|
|
|
$this->aliases,
|
2018-07-15 23:23:17 +02:00
|
|
|
$this->function_template_types + $this->class_template_types,
|
|
|
|
$this->type_aliases
|
2018-03-27 14:07:44 +02:00
|
|
|
);
|
|
|
|
|
2018-05-20 23:19:53 +02:00
|
|
|
$storage->return_type = Type::parseTokens(
|
|
|
|
$fixed_type_tokens,
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2018-04-20 16:52:23 +02:00
|
|
|
$this->function_template_types + $this->class_template_types
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->return_type->setFromDocblock();
|
2018-01-07 22:11:51 +01:00
|
|
|
|
|
|
|
if ($storage->signature_return_type) {
|
2018-02-05 22:57:33 +01:00
|
|
|
$all_typehint_types_match = true;
|
2018-02-01 05:27:25 +01:00
|
|
|
$signature_return_atomic_types = $storage->signature_return_type->getTypes();
|
|
|
|
|
2018-01-09 21:05:48 +01:00
|
|
|
foreach ($storage->return_type->getTypes() as $key => $type) {
|
2018-02-01 05:27:25 +01:00
|
|
|
if (isset($signature_return_atomic_types[$key])) {
|
2018-01-07 22:11:51 +01:00
|
|
|
$type->from_docblock = false;
|
2018-01-08 23:17:49 +01:00
|
|
|
} else {
|
2018-02-05 22:57:33 +01:00
|
|
|
$all_typehint_types_match = false;
|
2018-01-08 23:17:49 +01:00
|
|
|
}
|
2018-02-01 05:27:25 +01:00
|
|
|
}
|
2018-01-08 23:17:49 +01:00
|
|
|
|
2018-02-05 22:57:33 +01:00
|
|
|
if ($all_typehint_types_match) {
|
2018-02-01 05:27:25 +01:00
|
|
|
$storage->return_type->from_docblock = false;
|
2018-01-07 22:11:51 +01:00
|
|
|
}
|
2018-05-29 15:44:38 +02:00
|
|
|
|
|
|
|
if ($storage->signature_return_type->isNullable()
|
|
|
|
&& !$storage->return_type->isNullable()
|
|
|
|
) {
|
|
|
|
$storage->return_type->addType(new Type\Atomic\TNull());
|
|
|
|
}
|
2018-01-07 22:11:51 +01:00
|
|
|
}
|
|
|
|
|
2018-02-19 06:27:39 +01:00
|
|
|
$storage->return_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
2017-10-22 07:04:35 +02:00
|
|
|
} catch (TypeParseTreeException $e) {
|
2017-07-25 22:11:02 +02:00
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . $cased_function_id,
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
2017-07-25 22:11:02 +02:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($storage->return_type && $docblock_info->ignore_nullable_return) {
|
|
|
|
$storage->return_type->ignore_nullable_issues = true;
|
|
|
|
}
|
|
|
|
|
2018-01-25 00:52:58 +01:00
|
|
|
if ($storage->return_type && $docblock_info->ignore_falsable_return) {
|
|
|
|
$storage->return_type->ignore_falsable_issues = true;
|
|
|
|
}
|
|
|
|
|
2018-01-13 07:25:13 +01:00
|
|
|
if ($stmt->returnsByRef() && $storage->return_type) {
|
2018-01-12 05:18:13 +01:00
|
|
|
$storage->return_type->by_ref = true;
|
|
|
|
}
|
|
|
|
|
2019-03-19 02:05:37 +01:00
|
|
|
if ($docblock_info->return_type_line_number && !$fake_method) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage->return_type_location->setCommentLine($docblock_info->return_type_line_number);
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 05:39:24 +02:00
|
|
|
|
|
|
|
$storage->return_type_description = $docblock_info->return_type_description;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-08 15:31:21 +02:00
|
|
|
foreach ($docblock_info->globals as $global) {
|
|
|
|
try {
|
|
|
|
$storage->global_types[$global['name']] = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$global['type'],
|
2018-07-15 23:23:17 +02:00
|
|
|
$this->aliases,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
2018-06-08 15:31:21 +02:00
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null
|
2018-06-08 15:31:21 +02:00
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . $cased_function_id,
|
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
|
2018-06-08 15:31:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($docblock_info->params) {
|
|
|
|
$this->improveParamsFromDocblock(
|
|
|
|
$storage,
|
|
|
|
$docblock_info->params,
|
2019-03-19 02:05:37 +01:00
|
|
|
$stmt,
|
|
|
|
$fake_method
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
|
|
|
}
|
2018-04-22 04:13:10 +02:00
|
|
|
|
2019-03-25 16:25:43 +01:00
|
|
|
if ($storage instanceof MethodStorage) {
|
|
|
|
$storage->has_docblock_param_types = (bool) array_filter(
|
|
|
|
$storage->params,
|
|
|
|
/** @return bool */
|
|
|
|
function (FunctionLikeParameter $p) {
|
|
|
|
return $p->type !== null && $p->has_docblock_type;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-19 19:32:43 +01:00
|
|
|
foreach ($docblock_info->params_out as $docblock_param_out) {
|
|
|
|
$param_name = substr($docblock_param_out['name'], 1);
|
|
|
|
|
|
|
|
foreach ($storage->params as $i => $param_storage) {
|
|
|
|
if ($param_storage->name === $param_name) {
|
|
|
|
$out_type = Type::parseTokens(
|
|
|
|
Type::fixUpLocalType(
|
|
|
|
$docblock_param_out['type'],
|
|
|
|
$this->aliases,
|
|
|
|
$this->function_template_types + $this->class_template_types,
|
|
|
|
$this->type_aliases
|
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2019-01-19 19:32:43 +01:00
|
|
|
$this->function_template_types + $this->class_template_types
|
|
|
|
);
|
|
|
|
|
|
|
|
$out_type->queueClassLikesForScanning(
|
|
|
|
$this->codebase,
|
|
|
|
$this->file_storage,
|
|
|
|
$storage->template_types ?: []
|
|
|
|
);
|
|
|
|
|
|
|
|
$storage->param_out_types[$i] = $out_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 06:15:53 +01:00
|
|
|
if ($docblock_info->template_typeofs) {
|
|
|
|
foreach ($docblock_info->template_typeofs as $template_typeof) {
|
2019-05-13 02:49:37 +02:00
|
|
|
foreach ($storage->params as $param) {
|
2019-01-05 06:15:53 +01:00
|
|
|
if ($param->name === $template_typeof['param_name']) {
|
|
|
|
$param_type_nullable = $param->type && $param->type->isNullable();
|
|
|
|
|
2019-03-22 20:59:10 +01:00
|
|
|
$template_type = null;
|
|
|
|
$template_class = null;
|
2019-01-05 16:32:39 +01:00
|
|
|
|
2019-03-22 20:59:10 +01:00
|
|
|
if (isset($template_types[$template_typeof['template_type']])) {
|
|
|
|
foreach ($template_types[$template_typeof['template_type']] as $class => $map) {
|
|
|
|
$template_type = $map[0];
|
|
|
|
$template_class = $class;
|
|
|
|
}
|
|
|
|
}
|
2019-01-13 20:29:04 +01:00
|
|
|
|
2019-01-20 04:45:58 +01:00
|
|
|
$template_atomic_type = null;
|
|
|
|
|
|
|
|
if ($template_type) {
|
|
|
|
foreach ($template_type->getTypes() as $tat) {
|
|
|
|
if ($tat instanceof Type\Atomic\TNamedObject) {
|
|
|
|
$template_atomic_type = $tat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 06:15:53 +01:00
|
|
|
$param->type = new Type\Union([
|
2019-02-22 03:40:06 +01:00
|
|
|
new Type\Atomic\TTemplateParamClass(
|
2019-01-05 06:15:53 +01:00
|
|
|
$template_typeof['template_type'],
|
2019-01-05 16:32:39 +01:00
|
|
|
$template_type && !$template_type->isMixed()
|
|
|
|
? (string)$template_type
|
|
|
|
: 'object',
|
2019-01-20 04:45:58 +01:00
|
|
|
$template_atomic_type,
|
2019-01-13 20:29:04 +01:00
|
|
|
$template_class
|
2019-01-05 06:15:53 +01:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($param_type_nullable) {
|
|
|
|
$param->type->addType(new Type\Atomic\TNull);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-22 04:13:10 +02:00
|
|
|
return $storage;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param PhpParser\Node\Param $param
|
|
|
|
*
|
|
|
|
* @return FunctionLikeParameter
|
|
|
|
*/
|
2019-03-19 02:05:37 +01:00
|
|
|
public function getTranslatedFunctionParam(
|
|
|
|
PhpParser\Node\Param $param,
|
|
|
|
PhpParser\Node\FunctionLike $stmt,
|
|
|
|
bool $fake_method
|
|
|
|
) : FunctionLikeParameter {
|
2017-07-25 22:11:02 +02:00
|
|
|
$param_type = null;
|
|
|
|
|
|
|
|
$is_nullable = $param->default !== null &&
|
|
|
|
$param->default instanceof PhpParser\Node\Expr\ConstFetch &&
|
|
|
|
$param->default->name instanceof PhpParser\Node\Name &&
|
|
|
|
strtolower($param->default->name->parts[0]) === 'null';
|
|
|
|
|
|
|
|
$param_typehint = $param->type;
|
|
|
|
|
|
|
|
if ($param_typehint instanceof PhpParser\Node\NullableType) {
|
|
|
|
$is_nullable = true;
|
|
|
|
$param_typehint = $param_typehint->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($param_typehint) {
|
2018-04-17 18:16:25 +02:00
|
|
|
if ($param_typehint instanceof PhpParser\Node\Identifier) {
|
|
|
|
$param_type_string = $param_typehint->name;
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($param_typehint instanceof PhpParser\Node\Name\FullyQualified) {
|
|
|
|
$param_type_string = (string)$param_typehint;
|
2019-05-03 17:55:27 +02:00
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($param_type_string, $this->file_path);
|
2019-05-03 17:55:27 +02:00
|
|
|
$this->file_storage->referenced_classlikes[strtolower($param_type_string)] = $param_type_string;
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2019-03-17 16:31:04 +01:00
|
|
|
if ($this->classlike_storages
|
|
|
|
&& strtolower($param_typehint->parts[0]) === 'self'
|
|
|
|
&& !end($this->classlike_storages)->is_trait
|
|
|
|
) {
|
|
|
|
$param_type_string = $this->fq_classlike_names[count($this->fq_classlike_names) - 1];
|
|
|
|
} else {
|
|
|
|
$param_type_string = ClassLikeAnalyzer::getFQCLNFromNameObject($param_typehint, $this->aliases);
|
|
|
|
}
|
2018-04-17 18:16:25 +02:00
|
|
|
|
2017-11-15 03:56:29 +01:00
|
|
|
if (!in_array(strtolower($param_type_string), ['self', 'static', 'parent'], true)) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->codebase->scanner->queueClassLikeForScanning($param_type_string, $this->file_path);
|
2018-02-23 04:22:31 +01:00
|
|
|
$this->file_storage->referenced_classlikes[strtolower($param_type_string)] = $param_type_string;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($param_type_string) {
|
2019-02-07 18:25:57 +01:00
|
|
|
$param_type = Type::parseString(
|
|
|
|
$param_type_string,
|
|
|
|
[$this->php_major_version, $this->php_minor_version],
|
|
|
|
[]
|
|
|
|
);
|
2018-08-28 18:37:25 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($is_nullable) {
|
2018-08-28 18:37:25 +02:00
|
|
|
$param_type->addType(new Type\Atomic\TNull);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2019-04-09 19:58:49 +02:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$is_optional = $param->default !== null;
|
|
|
|
|
2018-06-03 16:05:50 +02:00
|
|
|
if ($param->var instanceof PhpParser\Node\Expr\Error || !is_string($param->var->name)) {
|
2018-04-17 18:16:25 +02:00
|
|
|
throw new \UnexpectedValueException('Not expecting param name to be non-string');
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
return new FunctionLikeParameter(
|
2018-04-17 18:16:25 +02:00
|
|
|
$param->var->name,
|
2017-07-25 22:11:02 +02:00
|
|
|
$param->byRef,
|
2017-09-02 17:18:56 +02:00
|
|
|
$param_type,
|
2019-03-19 02:05:37 +01:00
|
|
|
new CodeLocation(
|
|
|
|
$this->file_scanner,
|
|
|
|
$fake_method ? $stmt : $param,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
!$fake_method
|
|
|
|
? CodeLocation::FUNCTION_PARAM_VAR
|
|
|
|
: CodeLocation::FUNCTION_PHPDOC_METHOD
|
|
|
|
),
|
2017-12-30 03:28:21 +01:00
|
|
|
$param_typehint
|
2019-03-19 02:05:37 +01:00
|
|
|
? new CodeLocation(
|
|
|
|
$this->file_scanner,
|
|
|
|
$fake_method ? $stmt : $param,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
CodeLocation::FUNCTION_PARAM_TYPE
|
|
|
|
)
|
2017-12-30 03:28:21 +01:00
|
|
|
: null,
|
2017-07-25 22:11:02 +02:00
|
|
|
$is_optional,
|
|
|
|
$is_nullable,
|
2018-06-07 18:23:10 +02:00
|
|
|
$param->variadic,
|
2018-11-06 03:57:36 +01:00
|
|
|
$param->default ? StatementsAnalyzer::getSimpleType($this->codebase, $param->default, $this->aliases) : null
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param FunctionLikeStorage $storage
|
2018-02-18 23:55:11 +01:00
|
|
|
* @param array<int, array{type:string,name:string,line_number:int}> $docblock_params
|
2017-07-25 22:11:02 +02:00
|
|
|
* @param PhpParser\Node\FunctionLike $function
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-01-21 19:38:51 +01:00
|
|
|
private function improveParamsFromDocblock(
|
2017-07-25 22:11:02 +02:00
|
|
|
FunctionLikeStorage $storage,
|
|
|
|
array $docblock_params,
|
2019-03-19 02:05:37 +01:00
|
|
|
PhpParser\Node\FunctionLike $function,
|
|
|
|
bool $fake_method
|
2017-07-25 22:11:02 +02:00
|
|
|
) {
|
2017-08-14 21:46:01 +02:00
|
|
|
$base = $this->fq_classlike_names
|
|
|
|
? $this->fq_classlike_names[count($this->fq_classlike_names) - 1] . '::'
|
|
|
|
: '';
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
$cased_method_id = $base . $storage->cased_name;
|
|
|
|
|
2019-02-23 17:02:04 +01:00
|
|
|
$unused_docblock_params = [];
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
foreach ($docblock_params as $docblock_param) {
|
|
|
|
$param_name = $docblock_param['name'];
|
|
|
|
$docblock_param_variadic = false;
|
|
|
|
|
|
|
|
if (substr($param_name, 0, 3) === '...') {
|
|
|
|
$docblock_param_variadic = true;
|
|
|
|
$param_name = substr($param_name, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
$param_name = substr($param_name, 1);
|
|
|
|
|
|
|
|
$storage_param = null;
|
|
|
|
|
|
|
|
foreach ($storage->params as $function_signature_param) {
|
|
|
|
if ($function_signature_param->name === $param_name) {
|
|
|
|
$storage_param = $function_signature_param;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 02:05:37 +01:00
|
|
|
$docblock_type_location = new CodeLocation(
|
2019-02-23 17:02:04 +01:00
|
|
|
$this->file_scanner,
|
|
|
|
$function,
|
|
|
|
null,
|
2019-03-19 02:05:37 +01:00
|
|
|
!$fake_method,
|
|
|
|
!$fake_method
|
|
|
|
? CodeLocation::FUNCTION_PHPDOC_PARAM_TYPE
|
|
|
|
: CodeLocation::FUNCTION_PHPDOC_METHOD,
|
|
|
|
$fake_method ? null : $docblock_param['type']
|
2019-02-23 17:02:04 +01:00
|
|
|
);
|
|
|
|
|
2019-03-19 02:05:37 +01:00
|
|
|
if (!$fake_method) {
|
|
|
|
$docblock_type_location->setCommentLine($docblock_param['line_number']);
|
|
|
|
}
|
2019-02-23 17:02:04 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($storage_param === null) {
|
2019-02-27 20:17:11 +01:00
|
|
|
$param_location = new CodeLocation(
|
|
|
|
$this->file_scanner,
|
|
|
|
$function,
|
|
|
|
null,
|
|
|
|
true,
|
2019-02-27 22:00:44 +01:00
|
|
|
CodeLocation::FUNCTION_PARAM_VAR
|
2019-02-27 20:17:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$param_location->setCommentLine($docblock_param['line_number']);
|
|
|
|
$unused_docblock_params[$param_name] = $param_location;
|
2019-02-23 17:02:04 +01:00
|
|
|
|
2018-12-01 01:21:14 +01:00
|
|
|
if (!$docblock_param_variadic || $storage->params || $this->scan_deep) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage_param = new FunctionLikeParameter(
|
|
|
|
$param_name,
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
$storage->params[] = $storage_param;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-10-22 07:04:35 +02:00
|
|
|
try {
|
2018-05-20 23:19:53 +02:00
|
|
|
$new_param_type = Type::parseTokens(
|
2018-02-04 18:23:32 +01:00
|
|
|
Type::fixUpLocalType(
|
2017-10-22 07:04:35 +02:00
|
|
|
$docblock_param['type'],
|
|
|
|
$this->aliases,
|
2018-07-15 23:23:17 +02:00
|
|
|
$this->function_template_types + $this->class_template_types,
|
|
|
|
$this->type_aliases
|
2018-04-20 16:52:23 +02:00
|
|
|
),
|
2019-02-07 18:25:57 +01:00
|
|
|
null,
|
2018-04-20 16:52:23 +02:00
|
|
|
$this->function_template_types + $this->class_template_types
|
2017-10-22 07:04:35 +02:00
|
|
|
);
|
|
|
|
} catch (TypeParseTreeException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
|
|
|
$e->getMessage() . ' in docblock for ' . $cased_method_id,
|
2019-03-19 02:05:37 +01:00
|
|
|
$docblock_type_location
|
2017-10-22 07:04:35 +02:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
|
|
|
|
2018-11-01 22:03:08 +01:00
|
|
|
$storage->has_docblock_issues = true;
|
|
|
|
|
2017-10-22 07:04:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-01-19 18:46:39 +01:00
|
|
|
$storage_param->has_docblock_type = true;
|
2018-04-14 19:41:25 +02:00
|
|
|
$new_param_type->setFromDocblock();
|
|
|
|
|
2017-07-27 22:12:16 +02:00
|
|
|
$new_param_type->queueClassLikesForScanning(
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->codebase,
|
2018-02-19 06:27:39 +01:00
|
|
|
$this->file_storage,
|
2017-07-27 22:12:16 +02:00
|
|
|
$storage->template_types ?: []
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-04-09 19:58:49 +02:00
|
|
|
if (!$docblock_param_variadic && $storage_param->is_variadic && $new_param_type->hasArray()) {
|
|
|
|
/** @var Type\Atomic\TArray|Type\Atomic\ObjectLike */
|
|
|
|
$array_type = $new_param_type->getTypes()['array'];
|
|
|
|
|
|
|
|
if ($array_type instanceof Type\Atomic\ObjectLike) {
|
|
|
|
$new_param_type = $array_type->getGenericValueType();
|
|
|
|
} else {
|
|
|
|
$new_param_type = $array_type->type_params[1];
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$existing_param_type_nullable = $storage_param->is_nullable;
|
|
|
|
|
2018-12-08 19:18:55 +01:00
|
|
|
if (!$storage_param->type || $storage_param->type->hasMixed() || $storage->template_types) {
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($existing_param_type_nullable && !$new_param_type->isNullable()) {
|
2018-01-09 21:05:48 +01:00
|
|
|
$new_param_type->addType(new Type\Atomic\TNull());
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 18:23:10 +02:00
|
|
|
if ($this->config->add_param_default_to_docblock_type
|
|
|
|
&& $storage_param->default_type
|
2018-12-08 19:18:55 +01:00
|
|
|
&& !$storage_param->default_type->hasMixed()
|
|
|
|
&& (!$storage_param->type || !$storage_param->type->hasMixed())
|
2018-06-07 18:23:10 +02:00
|
|
|
) {
|
|
|
|
$new_param_type = Type::combineUnionTypes($new_param_type, $storage_param->default_type);
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$storage_param->type = $new_param_type;
|
2019-03-19 02:05:37 +01:00
|
|
|
$storage_param->type_location = $docblock_type_location;
|
2017-07-25 22:11:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-01 05:27:25 +01:00
|
|
|
$storage_param_atomic_types = $storage_param->type->getTypes();
|
|
|
|
|
|
|
|
$all_types_match = true;
|
2018-02-05 22:57:33 +01:00
|
|
|
$all_typehint_types_match = true;
|
2018-02-01 05:27:25 +01:00
|
|
|
|
|
|
|
foreach ($new_param_type->getTypes() as $key => $type) {
|
|
|
|
if (isset($storage_param_atomic_types[$key])) {
|
|
|
|
if ($storage_param_atomic_types[$key]->getId() !== $type->getId()) {
|
|
|
|
$all_types_match = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$type->from_docblock = false;
|
2019-01-05 06:15:53 +01:00
|
|
|
|
|
|
|
if ($storage_param_atomic_types[$key] instanceof Type\Atomic\TArray
|
|
|
|
&& $type instanceof Type\Atomic\TArray
|
|
|
|
&& $type->type_params[0]->hasArrayKey()
|
|
|
|
) {
|
|
|
|
$type->type_params[0]->from_docblock = false;
|
|
|
|
}
|
2018-02-01 05:27:25 +01:00
|
|
|
} else {
|
|
|
|
$all_types_match = false;
|
2018-02-05 22:57:33 +01:00
|
|
|
$all_typehint_types_match = false;
|
2018-02-01 05:27:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($all_types_match) {
|
2017-07-25 22:11:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-05 22:57:33 +01:00
|
|
|
if ($all_typehint_types_match) {
|
|
|
|
$new_param_type->from_docblock = false;
|
|
|
|
}
|
|
|
|
|
2018-01-05 06:19:35 +01:00
|
|
|
if ($existing_param_type_nullable && !$new_param_type->isNullable()) {
|
2018-01-09 21:05:48 +01:00
|
|
|
$new_param_type->addType(new Type\Atomic\TNull());
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-01-05 06:19:35 +01:00
|
|
|
$storage_param->type = $new_param_type;
|
2019-03-19 02:05:37 +01:00
|
|
|
$storage_param->type_location = $docblock_type_location;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2019-02-23 17:02:04 +01:00
|
|
|
|
2019-02-23 17:39:00 +01:00
|
|
|
$params_without_docblock_type = array_filter(
|
2019-02-23 17:02:04 +01:00
|
|
|
$storage->params,
|
|
|
|
function (FunctionLikeParameter $p) : bool {
|
2019-02-23 17:39:00 +01:00
|
|
|
return !$p->has_docblock_type && (!$p->type || $p->type->hasArray());
|
2019-02-23 17:02:04 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-02-23 17:39:00 +01:00
|
|
|
if ($params_without_docblock_type) {
|
2019-02-27 22:00:44 +01:00
|
|
|
$storage->unused_docblock_params = $unused_docblock_params;
|
2019-02-23 17:02:04 +01:00
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param PhpParser\Node\Stmt\Property $stmt
|
|
|
|
* @param Config $config
|
2018-05-10 20:12:50 +02:00
|
|
|
* @param string $fq_classlike_name
|
2017-07-25 22:11:02 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function visitPropertyDeclaration(
|
|
|
|
PhpParser\Node\Stmt\Property $stmt,
|
2018-01-21 18:44:46 +01:00
|
|
|
Config $config,
|
2018-05-10 20:12:50 +02:00
|
|
|
ClassLikeStorage $storage,
|
|
|
|
$fq_classlike_name
|
2017-07-25 22:11:02 +02:00
|
|
|
) {
|
2017-08-14 21:46:01 +02:00
|
|
|
if (!$this->fq_classlike_names) {
|
|
|
|
throw new \LogicException('$this->fq_classlike_names should not be empty');
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$comment = $stmt->getDocComment();
|
|
|
|
$var_comment = null;
|
2017-07-29 21:05:06 +02:00
|
|
|
|
2017-12-27 12:27:59 +01:00
|
|
|
$property_is_initialized = false;
|
|
|
|
|
2018-01-21 18:44:46 +01:00
|
|
|
$existing_constants = $storage->protected_class_constants
|
|
|
|
+ $storage->private_class_constants
|
|
|
|
+ $storage->public_class_constants;
|
|
|
|
|
2018-01-13 06:32:20 +01:00
|
|
|
if ($comment && $comment->getText() && ($config->use_docblock_types || $config->use_docblock_property_types)) {
|
2017-12-27 12:27:59 +01:00
|
|
|
if (preg_match('/[ \t\*]+@psalm-suppress[ \t]+PropertyNotSetInConstructor/', (string)$comment)) {
|
|
|
|
$property_is_initialized = true;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
try {
|
|
|
|
$property_type_line_number = $comment->getLine();
|
2018-11-06 03:57:36 +01:00
|
|
|
$var_comments = CommentAnalyzer::getTypeFromComment(
|
2017-07-25 22:11:02 +02:00
|
|
|
$comment->getText(),
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner,
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->aliases,
|
|
|
|
$this->function_template_types + $this->class_template_types,
|
2018-07-15 23:23:17 +02:00
|
|
|
$property_type_line_number,
|
|
|
|
null,
|
|
|
|
$this->type_aliases
|
2017-07-25 22:11:02 +02:00
|
|
|
);
|
2018-02-08 05:33:31 +01:00
|
|
|
|
|
|
|
$var_comment = array_pop($var_comments);
|
2017-11-15 03:43:31 +01:00
|
|
|
} catch (IncorrectDocblockException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new MissingDocblockType(
|
|
|
|
$e->getMessage(),
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
2017-11-15 03:43:31 +01:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
2017-07-25 22:11:02 +02:00
|
|
|
} catch (DocblockParseException $e) {
|
|
|
|
if (IssueBuffer::accepts(
|
|
|
|
new InvalidDocblock(
|
2017-11-15 03:43:31 +01:00
|
|
|
$e->getMessage(),
|
2018-01-21 18:44:46 +01:00
|
|
|
new CodeLocation($this->file_scanner, $stmt, null, true)
|
2017-07-25 22:11:02 +02:00
|
|
|
)
|
|
|
|
)) {
|
|
|
|
}
|
2018-11-01 22:03:08 +01:00
|
|
|
|
|
|
|
$storage->has_docblock_issues = true;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
$signature_type = null;
|
|
|
|
$signature_type_location = null;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
/** @var null|PhpParser\Node\Identifier|PhpParser\Node\Name|PhpParser\Node\NullableType */
|
|
|
|
$parser_property_type = isset($stmt->type) ? $stmt->type : null;
|
|
|
|
|
|
|
|
if ($parser_property_type) {
|
|
|
|
$suffix = '';
|
|
|
|
|
|
|
|
if ($parser_property_type instanceof PhpParser\Node\NullableType) {
|
|
|
|
$suffix = '|null';
|
|
|
|
$parser_property_type = $parser_property_type->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($parser_property_type instanceof PhpParser\Node\Identifier) {
|
|
|
|
$property_type_string = $parser_property_type->name . $suffix;
|
|
|
|
} else {
|
|
|
|
$property_type_fq_classlike_name = ClassLikeAnalyzer::getFQCLNFromNameObject(
|
|
|
|
$parser_property_type,
|
|
|
|
$this->aliases
|
|
|
|
);
|
|
|
|
|
|
|
|
$property_type_string = $property_type_fq_classlike_name . $suffix;
|
|
|
|
}
|
|
|
|
|
2019-02-07 18:25:57 +01:00
|
|
|
$signature_type = Type::parseString(
|
|
|
|
$property_type_string,
|
|
|
|
[$this->php_major_version, $this->php_minor_version]
|
|
|
|
);
|
2019-01-11 23:21:50 +01:00
|
|
|
$signature_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
|
|
|
|
|
|
|
$signature_type_location = new CodeLocation(
|
|
|
|
$this->file_scanner,
|
|
|
|
$parser_property_type,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
CodeLocation::FUNCTION_RETURN_TYPE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$doc_var_group_type = $var_comment ? $var_comment->type : null;
|
|
|
|
|
|
|
|
if ($doc_var_group_type) {
|
|
|
|
$doc_var_group_type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
|
|
|
$doc_var_group_type->setFromDocblock();
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($stmt->props as $property) {
|
2019-01-11 23:21:50 +01:00
|
|
|
$doc_var_location = null;
|
|
|
|
|
|
|
|
$property_storage = $storage->properties[$property->name->name] = new PropertyStorage();
|
|
|
|
$property_storage->is_static = (bool)$stmt->isStatic();
|
|
|
|
$property_storage->type = $signature_type;
|
|
|
|
$property_storage->signature_type = $signature_type;
|
|
|
|
$property_storage->signature_type_location = $signature_type_location;
|
|
|
|
$property_storage->type_location = $signature_type_location;
|
|
|
|
$property_storage->location = new CodeLocation($this->file_scanner, $property->name);
|
2019-04-17 17:12:18 +02:00
|
|
|
$property_storage->stmt_location = new CodeLocation($this->file_scanner, $stmt);
|
2019-01-11 23:21:50 +01:00
|
|
|
$property_storage->has_default = $property->default ? true : false;
|
|
|
|
$property_storage->deprecated = $var_comment ? $var_comment->deprecated : false;
|
|
|
|
$property_storage->internal = $var_comment ? $var_comment->internal : false;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
if (!$signature_type && !$doc_var_group_type) {
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($property->default) {
|
2019-01-11 23:21:50 +01:00
|
|
|
$property_storage->suggested_type = StatementsAnalyzer::getSimpleType(
|
2018-06-28 03:53:25 +02:00
|
|
|
$this->codebase,
|
2018-05-10 20:12:50 +02:00
|
|
|
$property->default,
|
2018-06-28 03:53:25 +02:00
|
|
|
$this->aliases,
|
|
|
|
null,
|
2018-05-10 20:12:50 +02:00
|
|
|
$existing_constants,
|
|
|
|
$fq_classlike_name
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2018-01-13 06:32:20 +01:00
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
$property_storage->type = null;
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2018-01-02 02:04:03 +01:00
|
|
|
if ($var_comment && $var_comment->line_number) {
|
2019-01-11 23:21:50 +01:00
|
|
|
$doc_var_location = new CodeLocation(
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_scanner,
|
2018-01-02 02:04:03 +01:00
|
|
|
$stmt,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
CodeLocation::VAR_TYPE,
|
|
|
|
$var_comment->original_type
|
|
|
|
);
|
2019-01-11 23:21:50 +01:00
|
|
|
$doc_var_location->setCommentLine($var_comment->line_number);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
if ($doc_var_group_type) {
|
|
|
|
$property_storage->type = count($stmt->props) === 1
|
|
|
|
? $doc_var_group_type
|
|
|
|
: clone $doc_var_group_type;
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2019-01-11 23:21:50 +01:00
|
|
|
if ($property_storage->type
|
|
|
|
&& $property_storage->type !== $property_storage->signature_type
|
|
|
|
&& (!$property_storage->signature_type
|
|
|
|
|| $doc_var_group_type !== $property_storage->signature_type->getId())
|
|
|
|
) {
|
|
|
|
if (!$property_storage->signature_type) {
|
|
|
|
$property_storage->type_location = $doc_var_location;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($property_storage->signature_type) {
|
|
|
|
$all_typehint_types_match = true;
|
|
|
|
$signature_atomic_types = $property_storage->signature_type->getTypes();
|
|
|
|
|
|
|
|
foreach ($property_storage->type->getTypes() as $key => $type) {
|
|
|
|
if (isset($signature_atomic_types[$key])) {
|
|
|
|
$type->from_docblock = false;
|
|
|
|
} else {
|
|
|
|
$all_typehint_types_match = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($all_typehint_types_match) {
|
|
|
|
$property_storage->type->from_docblock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($property_storage->signature_type->isNullable()
|
|
|
|
&& !$property_storage->type->isNullable()
|
|
|
|
) {
|
|
|
|
$property_storage->type->addType(new Type\Atomic\TNull());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$property_storage->type->queueClassLikesForScanning($this->codebase, $this->file_storage);
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
|
|
|
if ($stmt->isPublic()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$property_storage->visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt->isProtected()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$property_storage->visibility = ClassLikeAnalyzer::VISIBILITY_PROTECTED;
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt->isPrivate()) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$property_storage->visibility = ClassLikeAnalyzer::VISIBILITY_PRIVATE;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 21:46:01 +02:00
|
|
|
$fq_classlike_name = $this->fq_classlike_names[count($this->fq_classlike_names) - 1];
|
|
|
|
|
2018-04-17 18:16:25 +02:00
|
|
|
$property_id = $fq_classlike_name . '::$' . $property->name->name;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-07-22 01:56:26 +02:00
|
|
|
$storage->declaring_property_ids[$property->name->name] = $fq_classlike_name;
|
2018-04-17 18:16:25 +02:00
|
|
|
$storage->appearing_property_ids[$property->name->name] = $property_id;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-12-27 12:27:59 +01:00
|
|
|
if ($property_is_initialized) {
|
2018-04-17 18:16:25 +02:00
|
|
|
$storage->initialized_properties[$property->name->name] = true;
|
2017-12-27 12:27:59 +01:00
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if (!$stmt->isPrivate()) {
|
2018-04-17 18:16:25 +02:00
|
|
|
$storage->inheritable_property_ids[$property->name->name] = $property_id;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param PhpParser\Node\Stmt\ClassConst $stmt
|
2018-05-10 20:12:50 +02:00
|
|
|
* @param string $fq_classlike_name
|
2017-07-25 22:11:02 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-05-10 20:12:50 +02:00
|
|
|
private function visitClassConstDeclaration(
|
|
|
|
PhpParser\Node\Stmt\ClassConst $stmt,
|
|
|
|
ClassLikeStorage $storage,
|
|
|
|
$fq_classlike_name
|
|
|
|
) {
|
2017-07-25 22:11:02 +02:00
|
|
|
$existing_constants = $storage->protected_class_constants
|
|
|
|
+ $storage->private_class_constants
|
|
|
|
+ $storage->public_class_constants;
|
|
|
|
|
2018-08-10 19:25:25 +02:00
|
|
|
$comment = $stmt->getDocComment();
|
|
|
|
$deprecated = false;
|
|
|
|
$config = $this->config;
|
|
|
|
|
|
|
|
if ($comment && $comment->getText() && ($config->use_docblock_types || $config->use_docblock_property_types)) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$comments = DocComment::parse($comment->getText(), 0);
|
2018-08-10 19:25:25 +02:00
|
|
|
|
|
|
|
if (isset($comments['specials']['deprecated'])) {
|
|
|
|
$deprecated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
foreach ($stmt->consts as $const) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$const_type = StatementsAnalyzer::getSimpleType(
|
2018-06-28 03:53:25 +02:00
|
|
|
$this->codebase,
|
2017-07-25 22:11:02 +02:00
|
|
|
$const->value,
|
2018-06-28 03:53:25 +02:00
|
|
|
$this->aliases,
|
|
|
|
null,
|
2018-05-10 20:12:50 +02:00
|
|
|
$existing_constants,
|
|
|
|
$fq_classlike_name
|
2018-06-28 03:53:25 +02:00
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-06-28 03:53:25 +02:00
|
|
|
if ($const_type) {
|
|
|
|
$existing_constants[$const->name->name] = $const_type;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-06-28 03:53:25 +02:00
|
|
|
if ($stmt->isProtected()) {
|
|
|
|
$storage->protected_class_constants[$const->name->name] = $const_type;
|
|
|
|
} elseif ($stmt->isPrivate()) {
|
|
|
|
$storage->private_class_constants[$const->name->name] = $const_type;
|
|
|
|
} else {
|
|
|
|
$storage->public_class_constants[$const->name->name] = $const_type;
|
|
|
|
}
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
$storage->class_constant_locations[$const->name->name] = new CodeLocation(
|
|
|
|
$this->file_scanner,
|
|
|
|
$const->name
|
|
|
|
);
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2018-06-28 03:53:25 +02:00
|
|
|
if ($stmt->isProtected()) {
|
|
|
|
$storage->protected_class_constant_nodes[$const->name->name] = $const->value;
|
|
|
|
} elseif ($stmt->isPrivate()) {
|
|
|
|
$storage->private_class_constant_nodes[$const->name->name] = $const->value;
|
|
|
|
} else {
|
|
|
|
$storage->public_class_constant_nodes[$const->name->name] = $const->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->aliases = $this->aliases;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2018-08-10 19:25:25 +02:00
|
|
|
|
|
|
|
if ($deprecated) {
|
|
|
|
$storage->deprecated_constants[$const->name->name] = true;
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param PhpParser\Node\Expr\Include_ $stmt
|
|
|
|
*
|
2018-03-07 17:16:56 +01:00
|
|
|
* @return void
|
2017-07-25 22:11:02 +02:00
|
|
|
*/
|
|
|
|
public function visitInclude(PhpParser\Node\Expr\Include_ $stmt)
|
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
|
|
|
|
if (!$config->allow_includes) {
|
|
|
|
throw new FileIncludeException(
|
|
|
|
'File includes are not allowed per your Psalm config - check the allowFileIncludes flag.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($stmt->expr instanceof PhpParser\Node\Scalar\String_) {
|
|
|
|
$path_to_file = $stmt->expr->value;
|
|
|
|
|
|
|
|
// attempts to resolve using get_include_path dirs
|
2018-11-06 03:57:36 +01:00
|
|
|
$include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($this->file_path));
|
2017-07-25 22:11:02 +02:00
|
|
|
$path_to_file = $include_path ? $include_path : $path_to_file;
|
|
|
|
|
2018-11-18 23:06:11 +01:00
|
|
|
if (DIRECTORY_SEPARATOR === '/') {
|
|
|
|
$is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR;
|
|
|
|
} else {
|
|
|
|
$is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $path_to_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_path_relative) {
|
2018-11-18 22:53:46 +01:00
|
|
|
$path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-11-18 22:53:46 +01:00
|
|
|
$path_to_file = IncludeAnalyzer::getPathTo($stmt->expr, $this->file_path, $this->config);
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($path_to_file) {
|
2018-11-18 23:18:05 +01:00
|
|
|
$path_to_file = IncludeAnalyzer::normalizeFilePath($path_to_file);
|
2018-10-01 19:50:55 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($this->file_path === $path_to_file) {
|
2018-03-07 17:16:56 +01:00
|
|
|
return;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
if ($this->codebase->fileExists($path_to_file)) {
|
2018-05-23 05:38:27 +02:00
|
|
|
if ($this->scan_deep) {
|
|
|
|
$this->codebase->scanner->addFileToDeepScan($path_to_file);
|
|
|
|
} else {
|
|
|
|
$this->codebase->scanner->addFileToShallowScan($path_to_file);
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-05-30 18:23:53 +02:00
|
|
|
$this->file_storage->required_file_paths[strtolower($path_to_file)] = $path_to_file;
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-03-07 17:16:56 +01:00
|
|
|
return;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-07 17:16:56 +01:00
|
|
|
return;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2018-02-23 21:39:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilePath()
|
|
|
|
{
|
|
|
|
return $this->file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
|
|
|
return $this->file_scanner->getFileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function getRootFilePath()
|
2018-02-23 21:39:33 +01:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return $this->file_scanner->getRootFilePath();
|
2018-02-23 21:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function getRootFileName()
|
2018-02-23 21:39:33 +01:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return $this->file_scanner->getRootFileName();
|
2018-02-23 21:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Aliases
|
|
|
|
*/
|
|
|
|
public function getAliases()
|
|
|
|
{
|
|
|
|
return $this->aliases;
|
|
|
|
}
|
2018-09-24 19:08:23 +02:00
|
|
|
|
|
|
|
public function afterTraverse(array $nodes)
|
|
|
|
{
|
|
|
|
$this->file_storage->type_aliases = $this->type_aliases;
|
|
|
|
}
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|