mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 09:19:40 +01:00
commit
af8033adf0
@ -1399,7 +1399,7 @@ class Codebase
|
|||||||
if ($offset - $end_pos === 1) {
|
if ($offset - $end_pos === 1) {
|
||||||
$candidate_gap = substr($file_contents, $end_pos, 1);
|
$candidate_gap = substr($file_contents, $end_pos, 1);
|
||||||
|
|
||||||
if ($candidate_gap == '[') {
|
if ($candidate_gap === '[') {
|
||||||
$gap = $candidate_gap;
|
$gap = $candidate_gap;
|
||||||
$recent_type = $possible_type;
|
$recent_type = $possible_type;
|
||||||
|
|
||||||
|
@ -1257,7 +1257,7 @@ class Config
|
|||||||
|
|
||||||
self::requirePath($plugin_class_path);
|
self::requirePath($plugin_class_path);
|
||||||
} else {
|
} else {
|
||||||
if (!class_exists($plugin_class_name, true)) {
|
if (!class_exists($plugin_class_name)) {
|
||||||
throw new \UnexpectedValueException($plugin_class_name . ' is not a known class');
|
throw new \UnexpectedValueException($plugin_class_name . ' is not a known class');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2240,7 +2240,7 @@ class Config
|
|||||||
|
|
||||||
public function addUniversalObjectCrate(string $class): void
|
public function addUniversalObjectCrate(string $class): void
|
||||||
{
|
{
|
||||||
if (!class_exists($class, true)) {
|
if (!class_exists($class)) {
|
||||||
throw new \UnexpectedValueException($class . ' is not a known class');
|
throw new \UnexpectedValueException($class . ' is not a known class');
|
||||||
}
|
}
|
||||||
$this->universal_object_crates[] = $class;
|
$this->universal_object_crates[] = $class;
|
||||||
|
@ -138,12 +138,7 @@ class IssueHandler
|
|||||||
{
|
{
|
||||||
return array_filter(
|
return array_filter(
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $file_name): string {
|
||||||
* @param string $file_name
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function ($file_name) {
|
|
||||||
return substr($file_name, 0, -4);
|
return substr($file_name, 0, -4);
|
||||||
},
|
},
|
||||||
scandir(dirname(__DIR__) . '/Issue', SCANDIR_SORT_NONE)
|
scandir(dirname(__DIR__) . '/Issue', SCANDIR_SORT_NONE)
|
||||||
|
@ -393,7 +393,7 @@ class ReturnTypeAnalyzer
|
|||||||
$parent_class,
|
$parent_class,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
$function_like_storage instanceof MethodStorage && $function_like_storage->final
|
($function_like_storage instanceof MethodStorage && $function_like_storage->final)
|
||||||
|| ($classlike_storage && $classlike_storage->final)
|
|| ($classlike_storage && $classlike_storage->final)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -281,10 +281,7 @@ class TryAnalyzer
|
|||||||
|
|
||||||
$catch_context->vars_in_scope[$catch_var_id] = new Union(
|
$catch_context->vars_in_scope[$catch_var_id] = new Union(
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject {
|
||||||
* @param string $fq_catch_class
|
|
||||||
*/
|
|
||||||
function ($fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject {
|
|
||||||
$catch_class_type = new TNamedObject($fq_catch_class);
|
$catch_class_type = new TNamedObject($fq_catch_class);
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION, '7.0.0dev', '>=')
|
if (version_compare(PHP_VERSION, '7.0.0dev', '>=')
|
||||||
|
@ -713,7 +713,7 @@ class FunctionCallReturnTypeFetcher
|
|||||||
$next = $pattern[$i + 1] ?? null;
|
$next = $pattern[$i + 1] ?? null;
|
||||||
|
|
||||||
if ($current === '\\') {
|
if ($current === '\\') {
|
||||||
if ($next == null
|
if ($next === null
|
||||||
|| $next === 'x'
|
|| $next === 'x'
|
||||||
|| $next === 'u'
|
|| $next === 'u'
|
||||||
) {
|
) {
|
||||||
|
@ -126,7 +126,7 @@ class MissingMethodCallHandler
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} elseif ($all_intersection_return_type == null) {
|
} elseif ($all_intersection_return_type === null) {
|
||||||
ArgumentsAnalyzer::analyze(
|
ArgumentsAnalyzer::analyze(
|
||||||
$statements_analyzer,
|
$statements_analyzer,
|
||||||
$stmt->args,
|
$stmt->args,
|
||||||
|
@ -131,23 +131,15 @@ class Clause
|
|||||||
{
|
{
|
||||||
$clause_strings = array_map(
|
$clause_strings = array_map(
|
||||||
/**
|
/**
|
||||||
* @param string $var_id
|
|
||||||
* @param non-empty-list<string> $values
|
* @param non-empty-list<string> $values
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
function ($var_id, $values): string {
|
function (string $var_id, array $values): string {
|
||||||
if ($var_id[0] === '*') {
|
if ($var_id[0] === '*') {
|
||||||
$var_id = '<expr>';
|
$var_id = '<expr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$var_id_clauses = array_map(
|
$var_id_clauses = array_map(
|
||||||
/**
|
function (string $value) use ($var_id): string {
|
||||||
* @param string $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function ($value) use ($var_id): string {
|
|
||||||
if ($value === 'falsy') {
|
if ($value === 'falsy') {
|
||||||
return '!' . $var_id;
|
return '!' . $var_id;
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,7 @@ final class LanguageServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $arg) use ($valid_long_options): void {
|
||||||
* @param string $arg
|
|
||||||
*/
|
|
||||||
function ($arg) use ($valid_long_options): void {
|
|
||||||
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
||||||
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
||||||
|
|
||||||
|
@ -416,10 +416,7 @@ final class Psalm
|
|||||||
private static function validateCliArguments(array $args): void
|
private static function validateCliArguments(array $args): void
|
||||||
{
|
{
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $arg): void {
|
||||||
* @param string $arg
|
|
||||||
*/
|
|
||||||
function ($arg): void {
|
|
||||||
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
||||||
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
||||||
|
|
||||||
@ -456,7 +453,7 @@ final class Psalm
|
|||||||
/**
|
/**
|
||||||
* @param array<string,string|false|list<mixed>> $options
|
* @param array<string,string|false|list<mixed>> $options
|
||||||
*/
|
*/
|
||||||
private static function setMemoryLimit($options): void
|
private static function setMemoryLimit(array $options): void
|
||||||
{
|
{
|
||||||
if (!array_key_exists('use-ini-defaults', $options)) {
|
if (!array_key_exists('use-ini-defaults', $options)) {
|
||||||
ini_set('display_errors', 'stderr');
|
ini_set('display_errors', 'stderr');
|
||||||
|
@ -427,13 +427,10 @@ HELP;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @param array<int,string> $args */
|
/** @param array<int,string> $args */
|
||||||
private static function validateCliArguments($args): void
|
private static function validateCliArguments(array $args): void
|
||||||
{
|
{
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $arg): void {
|
||||||
* @param string $arg
|
|
||||||
*/
|
|
||||||
function ($arg): void {
|
|
||||||
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
||||||
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
||||||
|
|
||||||
|
@ -71,10 +71,7 @@ final class Refactor
|
|||||||
$options = getopt(implode('', $valid_short_options), $valid_long_options);
|
$options = getopt(implode('', $valid_short_options), $valid_long_options);
|
||||||
|
|
||||||
array_map(
|
array_map(
|
||||||
/**
|
function (string $arg) use ($valid_long_options): void {
|
||||||
* @param string $arg
|
|
||||||
*/
|
|
||||||
function ($arg) use ($valid_long_options): void {
|
|
||||||
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
if (strpos($arg, '--') === 0 && $arg !== '--') {
|
||||||
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ class Reflection
|
|||||||
$storage->is_static = $method->isStatic();
|
$storage->is_static = $method->isStatic();
|
||||||
$storage->abstract = $method->isAbstract();
|
$storage->abstract = $method->isAbstract();
|
||||||
$storage->mutation_free = $storage->external_mutation_free
|
$storage->mutation_free = $storage->external_mutation_free
|
||||||
= $method_name_lc === '__construct' && $fq_class_name_lc === 'datetimezone';
|
= ($method_name_lc === '__construct' && $fq_class_name_lc === 'datetimezone');
|
||||||
|
|
||||||
$class_storage->declaring_method_ids[$method_name_lc] = new \Psalm\Internal\MethodIdentifier(
|
$class_storage->declaring_method_ids[$method_name_lc] = new \Psalm\Internal\MethodIdentifier(
|
||||||
$declaring_class->name,
|
$declaring_class->name,
|
||||||
|
@ -34,19 +34,12 @@ class ClassStatementsDiffer extends AstDiffer
|
|||||||
$diff_map = [];
|
$diff_map = [];
|
||||||
|
|
||||||
[$trace, $x, $y, $bc] = self::calculateTrace(
|
[$trace, $x, $y, $bc] = self::calculateTrace(
|
||||||
/**
|
|
||||||
* @param string $a_code
|
|
||||||
* @param string $b_code
|
|
||||||
* @param bool $body_change
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function (
|
function (
|
||||||
PhpParser\Node\Stmt $a,
|
PhpParser\Node\Stmt $a,
|
||||||
PhpParser\Node\Stmt $b,
|
PhpParser\Node\Stmt $b,
|
||||||
$a_code,
|
string $a_code,
|
||||||
$b_code,
|
string $b_code,
|
||||||
&$body_change = false
|
bool &$body_change = false
|
||||||
) use (&$diff_map): bool {
|
) use (&$diff_map): bool {
|
||||||
if (get_class($a) !== get_class($b)) {
|
if (get_class($a) !== get_class($b)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,17 +29,11 @@ class FileStatementsDiffer extends AstDiffer
|
|||||||
public static function diff(array $a, array $b, string $a_code, string $b_code): array
|
public static function diff(array $a, array $b, string $a_code, string $b_code): array
|
||||||
{
|
{
|
||||||
[$trace, $x, $y, $bc] = self::calculateTrace(
|
[$trace, $x, $y, $bc] = self::calculateTrace(
|
||||||
/**
|
|
||||||
* @param string $a_code
|
|
||||||
* @param string $b_code
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function (
|
function (
|
||||||
PhpParser\Node\Stmt $a,
|
PhpParser\Node\Stmt $a,
|
||||||
PhpParser\Node\Stmt $b,
|
PhpParser\Node\Stmt $b,
|
||||||
$a_code,
|
string $a_code,
|
||||||
$b_code,
|
string $b_code,
|
||||||
bool &$body_change = false
|
bool &$body_change = false
|
||||||
): bool {
|
): bool {
|
||||||
if (get_class($a) !== get_class($b)) {
|
if (get_class($a) !== get_class($b)) {
|
||||||
|
@ -29,17 +29,11 @@ class NamespaceStatementsDiffer extends AstDiffer
|
|||||||
public static function diff(string $name, array $a, array $b, string $a_code, string $b_code): array
|
public static function diff(string $name, array $a, array $b, string $a_code, string $b_code): array
|
||||||
{
|
{
|
||||||
[$trace, $x, $y, $bc] = self::calculateTrace(
|
[$trace, $x, $y, $bc] = self::calculateTrace(
|
||||||
/**
|
|
||||||
* @param string $a_code
|
|
||||||
* @param string $b_code
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function (
|
function (
|
||||||
PhpParser\Node\Stmt $a,
|
PhpParser\Node\Stmt $a,
|
||||||
PhpParser\Node\Stmt $b,
|
PhpParser\Node\Stmt $b,
|
||||||
$a_code,
|
string $a_code,
|
||||||
$b_code,
|
string $b_code,
|
||||||
bool &$body_change = false
|
bool &$body_change = false
|
||||||
): bool {
|
): bool {
|
||||||
if (get_class($a) !== get_class($b)) {
|
if (get_class($a) !== get_class($b)) {
|
||||||
|
@ -11,10 +11,7 @@ class NodeCounterVisitor extends PhpParser\NodeVisitorAbstract
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
public $count = 0;
|
public $count = 0;
|
||||||
|
|
||||||
/**
|
public function enterNode(PhpParser\Node $node): ?int
|
||||||
* @return null|int
|
|
||||||
*/
|
|
||||||
public function enterNode(PhpParser\Node $node)
|
|
||||||
{
|
{
|
||||||
$this->count++;
|
$this->count++;
|
||||||
|
|
||||||
|
@ -27,10 +27,7 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract
|
|||||||
$this->extra_offsets = $extra_offsets;
|
$this->extra_offsets = $extra_offsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function enterNode(PhpParser\Node $node): ?int
|
||||||
* @return null|int
|
|
||||||
*/
|
|
||||||
public function enterNode(PhpParser\Node $node)
|
|
||||||
{
|
{
|
||||||
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
||||||
$attrs = $node->getAttributes();
|
$attrs = $node->getAttributes();
|
||||||
|
@ -60,11 +60,9 @@ class PartialParserVisitor extends PhpParser\NodeVisitorAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $traverseChildren
|
|
||||||
*
|
|
||||||
* @return null|int|PhpParser\Node
|
* @return null|int|PhpParser\Node
|
||||||
*/
|
*/
|
||||||
public function enterNode(PhpParser\Node $node, &$traverseChildren = true)
|
public function enterNode(PhpParser\Node $node, bool &$traverseChildren = true)
|
||||||
{
|
{
|
||||||
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
|
||||||
$attrs = $node->getAttributes();
|
$attrs = $node->getAttributes();
|
||||||
|
@ -21,12 +21,7 @@ class TraitFinder extends PhpParser\NodeVisitorAbstract
|
|||||||
$this->fq_trait_name = $fq_trait_name;
|
$this->fq_trait_name = $fq_trait_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function enterNode(PhpParser\Node $node, bool &$traverseChildren = true): ?int
|
||||||
* @param bool $traverseChildren
|
|
||||||
*
|
|
||||||
* @return int|null
|
|
||||||
*/
|
|
||||||
public function enterNode(PhpParser\Node $node, &$traverseChildren = true)
|
|
||||||
{
|
{
|
||||||
if ($node instanceof PhpParser\Node\Stmt\Trait_) {
|
if ($node instanceof PhpParser\Node\Stmt\Trait_) {
|
||||||
/** @var ?string */
|
/** @var ?string */
|
||||||
|
@ -200,24 +200,14 @@ class StatementsProvider
|
|||||||
);
|
);
|
||||||
|
|
||||||
$unchanged_members = array_map(
|
$unchanged_members = array_map(
|
||||||
/**
|
function (int $_): bool {
|
||||||
* @param int $_
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function ($_): bool {
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
array_flip($unchanged_members)
|
array_flip($unchanged_members)
|
||||||
);
|
);
|
||||||
|
|
||||||
$unchanged_signature_members = array_map(
|
$unchanged_signature_members = array_map(
|
||||||
/**
|
function (int $_): bool {
|
||||||
* @param int $_
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function ($_): bool {
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
array_flip($unchanged_signature_members)
|
array_flip($unchanged_signature_members)
|
||||||
|
@ -81,7 +81,7 @@ class DocblockParser
|
|||||||
|
|
||||||
if (preg_match('/^[ \t]*\*?\s*@([\w\-\\\:]+)[\t ]*(.*)$/sm', $line, $matches, PREG_OFFSET_CAPTURE)) {
|
if (preg_match('/^[ \t]*\*?\s*@([\w\-\\\:]+)[\t ]*(.*)$/sm', $line, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
/** @var array<int, array{string, int}> $matches */
|
/** @var array<int, array{string, int}> $matches */
|
||||||
[$_, $type_info, $data_info] = $matches;
|
[, $type_info, $data_info] = $matches;
|
||||||
|
|
||||||
[$type] = $type_info;
|
[$type] = $type_info;
|
||||||
[$data, $data_offset] = $data_info;
|
[$data, $data_offset] = $data_info;
|
||||||
|
@ -15,7 +15,7 @@ class ClassConstantStorage
|
|||||||
/**
|
/**
|
||||||
* @var ClassLikeAnalyzer::VISIBILITY_*
|
* @var ClassLikeAnalyzer::VISIBILITY_*
|
||||||
*/
|
*/
|
||||||
public $visibility = 1;
|
public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ?CodeLocation
|
* @var ?CodeLocation
|
||||||
|
@ -17,7 +17,7 @@ class PropertyStorage
|
|||||||
/**
|
/**
|
||||||
* @var ClassLikeAnalyzer::VISIBILITY_*
|
* @var ClassLikeAnalyzer::VISIBILITY_*
|
||||||
*/
|
*/
|
||||||
public $visibility = 1;
|
public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var CodeLocation|null
|
* @var CodeLocation|null
|
||||||
|
@ -4,11 +4,9 @@ namespace Psalm;
|
|||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @deprecated Use {@see Webmozart\PathUtil\Path::isAbsolute}. No longer used by Psalm, going to be removed in Psalm 5
|
* @deprecated Use {@see Webmozart\PathUtil\Path::isAbsolute}. No longer used by Psalm, going to be removed in Psalm 5
|
||||||
*/
|
*/
|
||||||
function isAbsolutePath($path): bool
|
function isAbsolutePath(string $path): bool
|
||||||
{
|
{
|
||||||
return Path::isAbsolute($path);
|
return Path::isAbsolute($path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user