Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master from 5.x #10803

Merged
merged 16 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6857,7 +6857,7 @@
'ming_setswfcompression' => ['void', 'level'=>'int'],
'ming_useconstants' => ['void', 'use'=>'int'],
'ming_useswfversion' => ['void', 'version'=>'int'],
'mkdir' => ['bool', 'directory'=>'string', 'permissions='=>'int', 'recursive='=>'bool', 'context='=>'resource'],
'mkdir' => ['bool', 'directory'=>'string', 'permissions='=>'int', 'recursive='=>'bool', 'context='=>'null|resource'],
'mktime' => ['int|false', 'hour'=>'int', 'minute='=>'int|null', 'second='=>'int|null', 'month='=>'int|null', 'day='=>'int|null', 'year='=>'int|null'],
'money_format' => ['string', 'format'=>'string', 'value'=>'float'],
'Mongo::__construct' => ['void', 'server='=>'string', 'options='=>'array', 'driver_options='=>'array'],
Expand Down Expand Up @@ -12640,8 +12640,8 @@
'sqlsrv_close' => ['bool', 'conn'=>'?resource'],
'sqlsrv_commit' => ['bool', 'conn'=>'resource'],
'sqlsrv_configure' => ['bool', 'setting'=>'string', 'value'=>'mixed'],
'sqlsrv_connect' => ['resource|false', 'serverName'=>'string', 'connectionInfo='=>'array'],
'sqlsrv_errors' => ['?array', 'errorsAndOrWarnings='=>'int'],
'sqlsrv_connect' => ['resource|false', 'server_name'=>'string', 'connection_info='=>'array'],
'sqlsrv_errors' => ['?array', 'errors_and_or_warnings='=>'int'],
'sqlsrv_execute' => ['bool', 'stmt'=>'resource'],
'sqlsrv_fetch' => ['?bool', 'stmt'=>'resource', 'row='=>'int', 'offset='=>'int'],
'sqlsrv_fetch_array' => ['array|null|false', 'stmt'=>'resource', 'fetchType='=>'int', 'row='=>'int', 'offset='=>'int'],
Expand Down
4 changes: 4 additions & 0 deletions dictionaries/CallMap_73_delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
'old' => ['resource[]|resource|false', 'ldap'=>'resource|resource[]', 'base'=>'array|string', 'filter'=>'array|string', 'attributes='=>'array', 'attributes_only='=>'int', 'sizelimit='=>'int', 'timelimit='=>'int', 'deref='=>'int'],
'new' => ['resource[]|resource|false', 'ldap'=>'resource|resource[]', 'base'=>'array|string', 'filter'=>'array|string', 'attributes='=>'array', 'attributes_only='=>'int', 'sizelimit='=>'int', 'timelimit='=>'int', 'deref='=>'int', 'controls='=>'array'],
],
'mkdir' => [
'old' => ['bool', 'directory'=>'string', 'permissions='=>'int', 'recursive='=>'bool', 'context='=>'resource'],
'new' => ['bool', 'directory'=>'string', 'permissions='=>'int', 'recursive='=>'bool', 'context='=>'null|resource'],
],
],
'removed' => [
],
Expand Down
4 changes: 2 additions & 2 deletions dictionaries/CallMap_historical.php
Original file line number Diff line number Diff line change
Expand Up @@ -14070,8 +14070,8 @@
'sqlsrv_close' => ['bool', 'conn'=>'?resource'],
'sqlsrv_commit' => ['bool', 'conn'=>'resource'],
'sqlsrv_configure' => ['bool', 'setting'=>'string', 'value'=>'mixed'],
'sqlsrv_connect' => ['resource|false', 'serverName'=>'string', 'connectionInfo='=>'array'],
'sqlsrv_errors' => ['?array', 'errorsAndOrWarnings='=>'int'],
'sqlsrv_connect' => ['resource|false', 'server_name'=>'string', 'connection_info='=>'array'],
'sqlsrv_errors' => ['?array', 'errors_and_or_warnings='=>'int'],
'sqlsrv_execute' => ['bool', 'stmt'=>'resource'],
'sqlsrv_fetch' => ['?bool', 'stmt'=>'resource', 'row='=>'int', 'offset='=>'int'],
'sqlsrv_fetch_array' => ['array|null|false', 'stmt'=>'resource', 'fetchType='=>'int', 'row='=>'int', 'offset='=>'int'],
Expand Down
27 changes: 21 additions & 6 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct(PhpParser\Node\Stmt $class, SourceAnalyzer $source,
throw new UnexpectedValueException('Anonymous enums are not allowed');
}

$fq_class_name = self::getAnonymousClassName($class, $source->getFilePath());
$fq_class_name = self::getAnonymousClassName($class, $source->getAliases(), $source->getFilePath());
}

parent::__construct($class, $source, $fq_class_name);
Expand All @@ -139,10 +139,25 @@ public function __construct(PhpParser\Node\Stmt $class, SourceAnalyzer $source,
}

/** @return non-empty-string */
public static function getAnonymousClassName(PhpParser\Node\Stmt\Class_ $class, string $file_path): string
{
return preg_replace('/[^A-Za-z0-9]/', '_', $file_path)
. '_' . $class->getLine() . '_' . (int)$class->getAttribute('startFilePos');
public static function getAnonymousClassName(
PhpParser\Node\Stmt\Class_ $class,
Aliases $aliases,
string $file_path,
): string {
$class_name = preg_replace('/[^A-Za-z0-9]/', '_', $file_path)
. '_' . $class->getLine()
. '_' . (int)$class->getAttribute('startFilePos');

$fq_class_name = Type::getFQCLNFromString(
$class_name,
$aliases,
);

if ($fq_class_name === '') {
throw new LogicException('Invalid class name, should never happen');
}

return $fq_class_name;
}

public function analyze(
Expand Down Expand Up @@ -895,7 +910,7 @@ public static function addContextProperties(
$stmts,
static fn($stmt): bool => $stmt instanceof PhpParser\Node\Stmt\Property
&& isset($stmt->props[0]->name->name)
&& $stmt->props[0]->name->name === $property_name
&& $stmt->props[0]->name->name === $property_name,
);

$suppressed = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static function verifyReturnType(
if (count($inferred_return_type_parts) > 1) {
$inferred_return_type_parts = array_filter(
$inferred_return_type_parts,
static fn(Union $union_type): bool => !$union_type->isNever()
static fn(Union $union_type): bool => !$union_type->isNever(),
);
}
$inferred_return_type_parts = array_values($inferred_return_type_parts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function analyze(
$entry_clauses,
static fn(Clause $c): bool => count($c->possibilities) > 1
|| $c->wedge
|| !isset($changed_var_ids[array_key_first($c->possibilities)])
|| !isset($changed_var_ids[array_key_first($c->possibilities)]),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static function analyze(
$elseif_context_clauses = array_values(
array_filter(
$elseif_context_clauses,
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses, true)
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses, true),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static function analyze(
$if_context->clauses = array_values(
array_filter(
$if_context->clauses,
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses)
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function analyze(
$context_clauses = array_values(
array_filter(
$context_clauses,
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses, true)
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses, true),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static function analyze(
$negated_left_clauses = array_values(
array_filter(
$negated_left_clauses,
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses)
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public static function analyze(
$possibilities,
static fn(Possibilities $assertion): bool => !(is_string($assertion->var_id)
&& str_starts_with($assertion->var_id, '$this->')
)
),
);
}
$statements_analyzer->node_data->setIfTrueAssertions(
Expand All @@ -471,7 +471,7 @@ public static function analyze(
$possibilities,
static fn(Possibilities $assertion): bool => !(is_string($assertion->var_id)
&& str_starts_with($assertion->var_id, '$this->')
)
),
);
}
$statements_analyzer->node_data->setIfFalseAssertions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static function analyze(
if (count($possible_new_class_types) > 0) {
$class_type = array_reduce(
$possible_new_class_types,
static fn(?Union $type_1, Union $type_2): Union => Type::combineUnionTypes($type_1, $type_2, $codebase)
static fn(?Union $type_1, Union $type_2): Union => Type::combineUnionTypes($type_1, $type_2, $codebase),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ public static function analyze(
}
} elseif ($stmt->class instanceof PhpParser\Node\Stmt\Class_) {
$statements_analyzer->analyze([$stmt->class], $context);
$fq_class_name = ClassAnalyzer::getAnonymousClassName($stmt->class, $statements_analyzer->getFilePath());
$fq_class_name = ClassAnalyzer::getAnonymousClassName(
$stmt->class,
$statements_analyzer->getAliases(),
$statements_analyzer->getFilePath(),
);
} else {
self::analyzeConstructorExpression(
$statements_analyzer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private static function handleNamedCall(

$mixin_candidates_no_generic = array_filter(
$mixin_candidates,
static fn(Atomic $check): bool => !($check instanceof TGenericObject)
static fn(Atomic $check): bool => !($check instanceof TGenericObject),
);

// $mixin_candidates_no_generic will only be empty when there are TGenericObject entries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static function (Clause $c) use ($mixed_var_ids, $cond_object_id): Clause {
$ternary_context_clauses = array_values(
array_filter(
$ternary_context_clauses,
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses)
static fn(Clause $c): bool => !in_array($c->hash, $reconciled_expression_clauses),
),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static function (string $arg) use ($valid_long_options): void {
// we ignore the FQN because of a hack in scoper.inc that needs full path
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
static fn(): ?\Composer\Autoload\ClassLoader =>
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir)
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir),
);

if (array_key_exists('v', $options)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function run(array $argv): void
// we ignore the FQN because of a hack in scoper.inc that needs full path
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
static fn(): ?\Composer\Autoload\ClassLoader =>
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir)
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir),
);

$run_taint_analysis = self::shouldRunTaintAnalysis($options);
Expand Down Expand Up @@ -503,7 +503,7 @@ private static function generateConfig(string $current_dir, array &$args): void
&& $arg !== '--debug-emitted-issues'
&& !str_starts_with($arg, '--disable-extension=')
&& !str_starts_with($arg, '--root=')
&& !str_starts_with($arg, '--r=')
&& !str_starts_with($arg, '--r='),
));

$init_level = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/Psalter.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static function run(array $argv): void
// we ignore the FQN because of a hack in scoper.inc that needs full path
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
static fn(): ?\Composer\Autoload\ClassLoader =>
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir)
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir),
);
$ini_handler = new PsalmRestarter('PSALTER');
$ini_handler->disableExtensions([
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/Refactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static function (string $arg) use ($valid_long_options): void {
// we ignore the FQN because of a hack in scoper.inc that needs full path
// phpcs:ignore SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName
static fn(): ?\Composer\Autoload\ClassLoader =>
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir)
CliUtils::requireAutoloaders($current_dir, isset($options['r']), $vendor_dir),
);

// If Xdebug is enabled, restart without it
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/CliUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public static function checkRuntimeRequirements(): void

$missing_extensions = array_filter(
$required_extensions,
static fn(string $ext) => !extension_loaded($ext)
static fn(string $ext) => !extension_loaded($ext),
);

if ($missing_extensions) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ public function getConstantsForClass(string $class_name, int $visibility): array
$storage->constants,
static fn(ClassConstantStorage $constant): bool => $constant->type
&& ($constant->visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC
|| $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED)
|| $constant->visibility === ClassLikeAnalyzer::VISIBILITY_PROTECTED),
);
}

Expand Down Expand Up @@ -2396,7 +2396,7 @@ private function getConstantType(
fn(ClassConstantStorage $resolved_constant) => $this->filterConstantNameByVisibility(
$resolved_constant,
$visibility,
)
),
);

if ($filtered_constants_by_visibility === []) {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function requiresRestart($default): bool
{
$this->required = (bool) array_filter(
$this->disabled_extensions,
static fn(string $extension): bool => extension_loaded($extension)
static fn(string $extension): bool => extension_loaded($extension),
);

$opcache_loaded = extension_loaded('opcache') || extension_loaded('Zend OPcache');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool
throw new LogicException('Anonymous classes are always classes');
}

$fq_classlike_name = ClassAnalyzer::getAnonymousClassName($node, $this->file_path);
$fq_classlike_name = ClassAnalyzer::getAnonymousClassName($node, $this->aliases, $this->file_path);
} else {
$name_location = new CodeLocation($this->file_scanner, $node->name);

Expand Down Expand Up @@ -406,7 +406,7 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool

usort(
$docblock_info->templates,
static fn(array $l, array $r): int => $l[4] > $r[4] ? 1 : -1
static fn(array $l, array $r): int => $l[4] > $r[4] ? 1 : -1,
);

foreach ($docblock_info->templates as $i => $template_map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ private static function improveParamsFromDocblock(

$params_without_docblock_type = array_filter(
$storage->params,
static fn(FunctionLikeParameter $p): bool => !$p->has_docblock_type && (!$p->type || $p->type->hasArray())
static fn(FunctionLikeParameter $p): bool => !$p->has_docblock_type && (!$p->type || $p->type->hasArray()),
);

$storage->has_undertyped_native_parameters = $params_without_docblock_type !== [];
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Provider/FileReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getDeletedReferencedFiles(): array
if (self::$deleted_files === null) {
self::$deleted_files = array_filter(
array_keys(self::$file_references),
fn(string $file_name): bool => !$this->file_provider->fileExists($file_name)
fn(string $file_name): bool => !$this->file_provider->fileExists($file_name),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static function ($keyed_type) use ($statements_source, $context) {
},
$first_arg_array->properties,
),
static fn($keyed_type) => !$keyed_type->isNever()
static fn($keyed_type) => !$keyed_type->isNever(),
);

if (!$new_properties) {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/TypeExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private static function expandNamedObject(
if ($container_class_storage->template_types
&& array_filter(
$container_class_storage->template_types,
static fn($type_map): bool => !reset($type_map)->hasMixed()
static fn($type_map): bool => !reset($type_map)->hasMixed(),
)
) {
$return_type = new TGenericObject(
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public static function finish(
$file_issues,
static fn(IssueData $d1, IssueData $d2): int => [$d1->file_path, $d1->line_from, $d1->column_from]
<=>
[$d2->file_path, $d2->line_from, $d2->column_from]
[$d2->file_path, $d2->line_from, $d2->column_from],
);
self::$issues_data[$file_path] = $file_issues;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Type/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function isNamedObjectType(): bool
&& ($this->as->hasNamedObjectType()
|| array_filter(
$this->extra_types,
static fn($extra_type): bool => $extra_type->isNamedObjectType()
static fn($extra_type): bool => $extra_type->isNamedObjectType(),
)
)
);
Expand Down Expand Up @@ -536,7 +536,7 @@ public function hasTraversableInterface(Codebase $codebase): bool
$this->extra_types
&& array_filter(
$this->extra_types,
static fn(Atomic $a): bool => $a->hasTraversableInterface($codebase)
static fn(Atomic $a): bool => $a->hasTraversableInterface($codebase),
)
)
);
Expand All @@ -559,7 +559,7 @@ public function hasCountableInterface(Codebase $codebase): bool
$this->extra_types
&& array_filter(
$this->extra_types,
static fn(Atomic $a): bool => $a->hasCountableInterface($codebase)
static fn(Atomic $a): bool => $a->hasCountableInterface($codebase),
)
)
);
Expand Down Expand Up @@ -597,7 +597,7 @@ public function hasArrayAccessInterface(Codebase $codebase): bool
$this->extra_types
&& array_filter(
$this->extra_types,
static fn(Atomic $a): bool => $a->hasArrayAccessInterface($codebase)
static fn(Atomic $a): bool => $a->hasArrayAccessInterface($codebase),
)
)
);
Expand Down
Loading