1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00

Merge pull request #6577 from orklah/cleanup3

Cleanup
This commit is contained in:
orklah 2021-10-04 01:02:21 +02:00 committed by GitHub
commit af8033adf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 34 additions and 106 deletions

View File

@ -1399,7 +1399,7 @@ class Codebase
if ($offset - $end_pos === 1) {
$candidate_gap = substr($file_contents, $end_pos, 1);
if ($candidate_gap == '[') {
if ($candidate_gap === '[') {
$gap = $candidate_gap;
$recent_type = $possible_type;

View File

@ -1257,7 +1257,7 @@ class Config
self::requirePath($plugin_class_path);
} 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');
}
}
@ -2240,7 +2240,7 @@ class Config
public function addUniversalObjectCrate(string $class): void
{
if (!class_exists($class, true)) {
if (!class_exists($class)) {
throw new \UnexpectedValueException($class . ' is not a known class');
}
$this->universal_object_crates[] = $class;

View File

@ -138,12 +138,7 @@ class IssueHandler
{
return array_filter(
array_map(
/**
* @param string $file_name
*
* @return string
*/
function ($file_name) {
function (string $file_name): string {
return substr($file_name, 0, -4);
},
scandir(dirname(__DIR__) . '/Issue', SCANDIR_SORT_NONE)

View File

@ -393,7 +393,7 @@ class ReturnTypeAnalyzer
$parent_class,
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)
);

View File

@ -281,10 +281,7 @@ class TryAnalyzer
$catch_context->vars_in_scope[$catch_var_id] = new Union(
array_map(
/**
* @param string $fq_catch_class
*/
function ($fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject {
function (string $fq_catch_class) use ($codebase): \Psalm\Type\Atomic\TNamedObject {
$catch_class_type = new TNamedObject($fq_catch_class);
if (version_compare(PHP_VERSION, '7.0.0dev', '>=')

View File

@ -713,7 +713,7 @@ class FunctionCallReturnTypeFetcher
$next = $pattern[$i + 1] ?? null;
if ($current === '\\') {
if ($next == null
if ($next === null
|| $next === 'x'
|| $next === 'u'
) {

View File

@ -126,7 +126,7 @@ class MissingMethodCallHandler
return null;
}
} elseif ($all_intersection_return_type == null) {
} elseif ($all_intersection_return_type === null) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->args,

View File

@ -131,23 +131,15 @@ class Clause
{
$clause_strings = array_map(
/**
* @param string $var_id
* @param non-empty-list<string> $values
*
* @return string
*/
function ($var_id, $values): string {
function (string $var_id, array $values): string {
if ($var_id[0] === '*') {
$var_id = '<expr>';
}
$var_id_clauses = array_map(
/**
* @param string $value
*
* @return string
*/
function ($value) use ($var_id): string {
function (string $value) use ($var_id): string {
if ($value === 'falsy') {
return '!' . $var_id;
}

View File

@ -82,10 +82,7 @@ final class LanguageServer
}
array_map(
/**
* @param string $arg
*/
function ($arg) use ($valid_long_options): void {
function (string $arg) use ($valid_long_options): void {
if (strpos($arg, '--') === 0 && $arg !== '--') {
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));

View File

@ -416,10 +416,7 @@ final class Psalm
private static function validateCliArguments(array $args): void
{
array_map(
/**
* @param string $arg
*/
function ($arg): void {
function (string $arg): void {
if (strpos($arg, '--') === 0 && $arg !== '--') {
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));
@ -456,7 +453,7 @@ final class Psalm
/**
* @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)) {
ini_set('display_errors', 'stderr');

View File

@ -427,13 +427,10 @@ HELP;
}
/** @param array<int,string> $args */
private static function validateCliArguments($args): void
private static function validateCliArguments(array $args): void
{
array_map(
/**
* @param string $arg
*/
function ($arg): void {
function (string $arg): void {
if (strpos($arg, '--') === 0 && $arg !== '--') {
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));

View File

@ -71,10 +71,7 @@ final class Refactor
$options = getopt(implode('', $valid_short_options), $valid_long_options);
array_map(
/**
* @param string $arg
*/
function ($arg) use ($valid_long_options): void {
function (string $arg) use ($valid_long_options): void {
if (strpos($arg, '--') === 0 && $arg !== '--') {
$arg_name = preg_replace('/=.*$/', '', substr($arg, 2));

View File

@ -260,7 +260,7 @@ class Reflection
$storage->is_static = $method->isStatic();
$storage->abstract = $method->isAbstract();
$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(
$declaring_class->name,

View File

@ -34,19 +34,12 @@ class ClassStatementsDiffer extends AstDiffer
$diff_map = [];
[$trace, $x, $y, $bc] = self::calculateTrace(
/**
* @param string $a_code
* @param string $b_code
* @param bool $body_change
*
* @return bool
*/
function (
PhpParser\Node\Stmt $a,
PhpParser\Node\Stmt $b,
$a_code,
$b_code,
&$body_change = false
string $a_code,
string $b_code,
bool &$body_change = false
) use (&$diff_map): bool {
if (get_class($a) !== get_class($b)) {
return false;

View File

@ -29,17 +29,11 @@ class FileStatementsDiffer extends AstDiffer
public static function diff(array $a, array $b, string $a_code, string $b_code): array
{
[$trace, $x, $y, $bc] = self::calculateTrace(
/**
* @param string $a_code
* @param string $b_code
*
* @return bool
*/
function (
PhpParser\Node\Stmt $a,
PhpParser\Node\Stmt $b,
$a_code,
$b_code,
string $a_code,
string $b_code,
bool &$body_change = false
): bool {
if (get_class($a) !== get_class($b)) {

View File

@ -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
{
[$trace, $x, $y, $bc] = self::calculateTrace(
/**
* @param string $a_code
* @param string $b_code
*
* @return bool
*/
function (
PhpParser\Node\Stmt $a,
PhpParser\Node\Stmt $b,
$a_code,
$b_code,
string $a_code,
string $b_code,
bool &$body_change = false
): bool {
if (get_class($a) !== get_class($b)) {

View File

@ -11,10 +11,7 @@ class NodeCounterVisitor extends PhpParser\NodeVisitorAbstract
/** @var int */
public $count = 0;
/**
* @return null|int
*/
public function enterNode(PhpParser\Node $node)
public function enterNode(PhpParser\Node $node): ?int
{
$this->count++;

View File

@ -27,10 +27,7 @@ class OffsetShifterVisitor extends PhpParser\NodeVisitorAbstract
$this->extra_offsets = $extra_offsets;
}
/**
* @return null|int
*/
public function enterNode(PhpParser\Node $node)
public function enterNode(PhpParser\Node $node): ?int
{
/** @var array{startFilePos: int, endFilePos: int, startLine: int} */
$attrs = $node->getAttributes();

View File

@ -60,11 +60,9 @@ class PartialParserVisitor extends PhpParser\NodeVisitorAbstract
}
/**
* @param bool $traverseChildren
*
* @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} */
$attrs = $node->getAttributes();

View File

@ -21,12 +21,7 @@ class TraitFinder extends PhpParser\NodeVisitorAbstract
$this->fq_trait_name = $fq_trait_name;
}
/**
* @param bool $traverseChildren
*
* @return int|null
*/
public function enterNode(PhpParser\Node $node, &$traverseChildren = true)
public function enterNode(PhpParser\Node $node, bool &$traverseChildren = true): ?int
{
if ($node instanceof PhpParser\Node\Stmt\Trait_) {
/** @var ?string */

View File

@ -200,24 +200,14 @@ class StatementsProvider
);
$unchanged_members = array_map(
/**
* @param int $_
*
* @return bool
*/
function ($_): bool {
function (int $_): bool {
return true;
},
array_flip($unchanged_members)
);
$unchanged_signature_members = array_map(
/**
* @param int $_
*
* @return bool
*/
function ($_): bool {
function (int $_): bool {
return true;
},
array_flip($unchanged_signature_members)

View File

@ -81,7 +81,7 @@ class DocblockParser
if (preg_match('/^[ \t]*\*?\s*@([\w\-\\\:]+)[\t ]*(.*)$/sm', $line, $matches, PREG_OFFSET_CAPTURE)) {
/** @var array<int, array{string, int}> $matches */
[$_, $type_info, $data_info] = $matches;
[, $type_info, $data_info] = $matches;
[$type] = $type_info;
[$data, $data_offset] = $data_info;

View File

@ -15,7 +15,7 @@ class ClassConstantStorage
/**
* @var ClassLikeAnalyzer::VISIBILITY_*
*/
public $visibility = 1;
public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
/**
* @var ?CodeLocation

View File

@ -17,7 +17,7 @@ class PropertyStorage
/**
* @var ClassLikeAnalyzer::VISIBILITY_*
*/
public $visibility = 1;
public $visibility = ClassLikeAnalyzer::VISIBILITY_PUBLIC;
/**
* @var CodeLocation|null

View File

@ -4,11 +4,9 @@ namespace Psalm;
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
*/
function isAbsolutePath($path): bool
function isAbsolutePath(string $path): bool
{
return Path::isAbsolute($path);
}