1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00
This commit is contained in:
Daniil Gentili 2022-10-17 13:10:12 +02:00
parent 7b6e09afc9
commit 3b3afd5369
4 changed files with 123 additions and 110 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@afe85fad86536c3abe4f9495238a767ac60d5140">
<files psalm-version="dev-master@53e3889745852409b704e0035d93e0819d522912">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$comment_block-&gt;tags['variablesfrom'][0]</code>
@ -68,7 +68,7 @@
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php">
<PossiblyUndefinedIntArrayOffset occurrences="34">
<PossiblyUndefinedIntArrayOffset occurrences="28">
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
<code>$assertion-&gt;rule[0]</code>
@ -90,12 +90,6 @@
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[0]</code>
<code>$expr-&gt;getArgs()[1]</code>
<code>$expr-&gt;getArgs()[1]</code>
<code>$get_debug_type_expr-&gt;getArgs()[0]</code>
@ -220,16 +214,9 @@
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php">
<DocblockTypeContradiction occurrences="2">
<code>!$this-&gt;is_accepting_new_requests</code>
<code>$this-&gt;is_accepting_new_requests</code>
</DocblockTypeContradiction>
<PossiblyUndefinedIntArrayOffset occurrences="1">
<code>$parts[1]</code>
</PossiblyUndefinedIntArrayOffset>
<UnusedPsalmSuppress occurrences="1">
<code>TypeDoesNotContainType</code>
</UnusedPsalmSuppress>
</file>
<file src="src/Psalm/Internal/LanguageServer/Server/TextDocument.php">
<PossiblyUndefinedIntArrayOffset occurrences="1">
@ -306,11 +293,12 @@
</MoreSpecificReturnType>
</file>
<file src="src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php">
<ImpureMethodCall occurrences="4">
<ImpureMethodCall occurrences="5">
<code>get</code>
<code>get</code>
<code>get</code>
<code>getClassTemplateTypes</code>
<code>has</code>
</ImpureMethodCall>
<ImpurePropertyAssignment occurrences="1">
<code>$candidate_param_type-&gt;from_template_default</code>

View File

@ -21,6 +21,7 @@ use Psalm\Internal\Type\TemplateBound;
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
use Psalm\Internal\Type\TemplateResult;
use Psalm\Internal\Type\TypeExpander;
use Psalm\Internal\TypeVisitor\ContainsStaticVisitor;
use Psalm\Issue\AbstractMethodCall;
use Psalm\Issue\ImpureMethodCall;
use Psalm\IssueBuffer;
@ -630,16 +631,8 @@ class ExistingAtomicStaticCallAnalyzer
*/
private static function hasStaticInType(Type\TypeNode $type): bool
{
if ($type instanceof TNamedObject && ($type->value === 'static' || $type->is_static)) {
return true;
}
foreach ($type->getChildNodes() as $child_type) {
if (self::hasStaticInType($child_type)) {
return true;
}
}
return false;
$visitor = new ContainsStaticVisitor;
$visitor->traverse($type);
return $visitor->matches();
}
}

View File

@ -668,7 +668,8 @@ class VariableFetchAnalyzer
$bool_string_helper = new Union([new TBool(), new TString()]);
$bool_string_helper->possibly_undefined = true;
$detailed_type = new TKeyedArray([
$detailed_type = new TKeyedArray(
[
// https://www.php.net/manual/en/reserved.variables.server.php
'PHP_SELF' => $non_empty_string_helper,
'argv' => $argv_helper,
@ -745,11 +746,12 @@ class VariableFetchAnalyzer
// phpunit
'APP_DEBUG' => $bool_string_helper,
'APP_ENV' => $string_helper,
]);
// generic case for all other elements
$detailed_type->previous_key_type = Type::getNonEmptyString();
$detailed_type->previous_value_type = Type::getString();
],
null,
false,
Type::getNonEmptyString(),
Type::getString()
);
return new Union([$detailed_type]);
}

View File

@ -0,0 +1,30 @@
<?php
namespace Psalm\Internal\TypeVisitor;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\ImmutableTypeVisitor;
use Psalm\Type\TypeNode;
use Psalm\Type\TypeVisitor;
/**
* @internal
*/
class ContainsStaticVisitor extends ImmutableTypeVisitor
{
private bool $contains_static = false;
protected function enterNode(TypeNode $type): ?int
{
if ($type instanceof TNamedObject && ($type->value === 'static' || $type->is_static)) {
$this->contains_static = true;
return TypeVisitor::STOP_TRAVERSAL;
}
return null;
}
public function matches(): bool
{
return $this->contains_static;
}
}