mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fixes
This commit is contained in:
parent
7b6e09afc9
commit
3b3afd5369
@ -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->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->rule[0]</code>
|
||||
<code>$assertion->rule[0]</code>
|
||||
<code>$assertion->rule[0]</code>
|
||||
@ -90,12 +90,6 @@
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[0]</code>
|
||||
<code>$expr->getArgs()[1]</code>
|
||||
<code>$expr->getArgs()[1]</code>
|
||||
<code>$get_debug_type_expr->getArgs()[0]</code>
|
||||
@ -220,16 +214,9 @@
|
||||
</PossiblyUndefinedIntArrayOffset>
|
||||
</file>
|
||||
<file src="src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php">
|
||||
<DocblockTypeContradiction occurrences="2">
|
||||
<code>!$this->is_accepting_new_requests</code>
|
||||
<code>$this->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->from_template_default</code>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -668,89 +668,91 @@ class VariableFetchAnalyzer
|
||||
$bool_string_helper = new Union([new TBool(), new TString()]);
|
||||
$bool_string_helper->possibly_undefined = true;
|
||||
|
||||
$detailed_type = new TKeyedArray([
|
||||
// https://www.php.net/manual/en/reserved.variables.server.php
|
||||
'PHP_SELF' => $non_empty_string_helper,
|
||||
'argv' => $argv_helper,
|
||||
'argc' => $argc_helper,
|
||||
'GATEWAY_INTERFACE' => $non_empty_string_helper,
|
||||
'SERVER_ADDR' => $non_empty_string_helper,
|
||||
'SERVER_NAME' => $non_empty_string_helper,
|
||||
'SERVER_SOFTWARE' => $non_empty_string_helper,
|
||||
'SERVER_PROTOCOL' => $non_empty_string_helper,
|
||||
'REQUEST_METHOD' => $non_empty_string_helper,
|
||||
'REQUEST_TIME' => $request_time_helper,
|
||||
'REQUEST_TIME_FLOAT' => $request_time_float_helper,
|
||||
'QUERY_STRING' => $string_helper,
|
||||
'DOCUMENT_ROOT' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_CHARSET' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_ENCODING' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_LANGUAGE' => $non_empty_string_helper,
|
||||
'HTTP_CONNECTION' => $non_empty_string_helper,
|
||||
'HTTP_HOST' => $non_empty_string_helper,
|
||||
'HTTP_REFERER' => $non_empty_string_helper,
|
||||
'HTTP_USER_AGENT' => $non_empty_string_helper,
|
||||
'HTTPS' => $string_helper,
|
||||
'REMOTE_ADDR' => $non_empty_string_helper,
|
||||
'REMOTE_HOST' => $non_empty_string_helper,
|
||||
'REMOTE_PORT' => $string_helper,
|
||||
'REMOTE_USER' => $non_empty_string_helper,
|
||||
'REDIRECT_REMOTE_USER' => $non_empty_string_helper,
|
||||
'SCRIPT_FILENAME' => $non_empty_string_helper,
|
||||
'SERVER_ADMIN' => $non_empty_string_helper,
|
||||
'SERVER_PORT' => $non_empty_string_helper,
|
||||
'SERVER_SIGNATURE' => $non_empty_string_helper,
|
||||
'PATH_TRANSLATED' => $non_empty_string_helper,
|
||||
'SCRIPT_NAME' => $non_empty_string_helper,
|
||||
'REQUEST_URI' => $non_empty_string_helper,
|
||||
'PHP_AUTH_DIGEST' => $non_empty_string_helper,
|
||||
'PHP_AUTH_USER' => $non_empty_string_helper,
|
||||
'PHP_AUTH_PW' => $non_empty_string_helper,
|
||||
'AUTH_TYPE' => $non_empty_string_helper,
|
||||
'PATH_INFO' => $non_empty_string_helper,
|
||||
'ORIG_PATH_INFO' => $non_empty_string_helper,
|
||||
// misc from RFC not included above already http://www.faqs.org/rfcs/rfc3875.html
|
||||
'CONTENT_LENGTH' => $string_helper,
|
||||
'CONTENT_TYPE' => $string_helper,
|
||||
// common, misc stuff
|
||||
'FCGI_ROLE' => $non_empty_string_helper,
|
||||
'HOME' => $non_empty_string_helper,
|
||||
'HTTP_CACHE_CONTROL' => $non_empty_string_helper,
|
||||
'HTTP_COOKIE' => $non_empty_string_helper,
|
||||
'HTTP_PRIORITY' => $non_empty_string_helper,
|
||||
'PATH' => $non_empty_string_helper,
|
||||
'REDIRECT_STATUS' => $non_empty_string_helper,
|
||||
'REQUEST_SCHEME' => $non_empty_string_helper,
|
||||
'USER' => $non_empty_string_helper,
|
||||
// common, misc headers
|
||||
'HTTP_UPGRADE_INSECURE_REQUESTS' => $non_empty_string_helper,
|
||||
'HTTP_X_FORWARDED_PROTO' => $non_empty_string_helper,
|
||||
'HTTP_CLIENT_IP' => $non_empty_string_helper,
|
||||
'HTTP_X_REAL_IP' => $non_empty_string_helper,
|
||||
'HTTP_X_FORWARDED_FOR' => $non_empty_string_helper,
|
||||
'HTTP_CF_CONNECTING_IP' => $non_empty_string_helper,
|
||||
'HTTP_CF_IPCOUNTRY' => $non_empty_string_helper,
|
||||
'HTTP_CF_VISITOR' => $non_empty_string_helper,
|
||||
'HTTP_CDN_LOOP' => $non_empty_string_helper,
|
||||
// common, misc browser headers
|
||||
'HTTP_DNT' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_DEST' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_USER' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_MODE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_SITE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA_PLATFORM' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA_MOBILE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA' => $non_empty_string_helper,
|
||||
// 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();
|
||||
|
||||
$detailed_type = new TKeyedArray(
|
||||
[
|
||||
// https://www.php.net/manual/en/reserved.variables.server.php
|
||||
'PHP_SELF' => $non_empty_string_helper,
|
||||
'argv' => $argv_helper,
|
||||
'argc' => $argc_helper,
|
||||
'GATEWAY_INTERFACE' => $non_empty_string_helper,
|
||||
'SERVER_ADDR' => $non_empty_string_helper,
|
||||
'SERVER_NAME' => $non_empty_string_helper,
|
||||
'SERVER_SOFTWARE' => $non_empty_string_helper,
|
||||
'SERVER_PROTOCOL' => $non_empty_string_helper,
|
||||
'REQUEST_METHOD' => $non_empty_string_helper,
|
||||
'REQUEST_TIME' => $request_time_helper,
|
||||
'REQUEST_TIME_FLOAT' => $request_time_float_helper,
|
||||
'QUERY_STRING' => $string_helper,
|
||||
'DOCUMENT_ROOT' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_CHARSET' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_ENCODING' => $non_empty_string_helper,
|
||||
'HTTP_ACCEPT_LANGUAGE' => $non_empty_string_helper,
|
||||
'HTTP_CONNECTION' => $non_empty_string_helper,
|
||||
'HTTP_HOST' => $non_empty_string_helper,
|
||||
'HTTP_REFERER' => $non_empty_string_helper,
|
||||
'HTTP_USER_AGENT' => $non_empty_string_helper,
|
||||
'HTTPS' => $string_helper,
|
||||
'REMOTE_ADDR' => $non_empty_string_helper,
|
||||
'REMOTE_HOST' => $non_empty_string_helper,
|
||||
'REMOTE_PORT' => $string_helper,
|
||||
'REMOTE_USER' => $non_empty_string_helper,
|
||||
'REDIRECT_REMOTE_USER' => $non_empty_string_helper,
|
||||
'SCRIPT_FILENAME' => $non_empty_string_helper,
|
||||
'SERVER_ADMIN' => $non_empty_string_helper,
|
||||
'SERVER_PORT' => $non_empty_string_helper,
|
||||
'SERVER_SIGNATURE' => $non_empty_string_helper,
|
||||
'PATH_TRANSLATED' => $non_empty_string_helper,
|
||||
'SCRIPT_NAME' => $non_empty_string_helper,
|
||||
'REQUEST_URI' => $non_empty_string_helper,
|
||||
'PHP_AUTH_DIGEST' => $non_empty_string_helper,
|
||||
'PHP_AUTH_USER' => $non_empty_string_helper,
|
||||
'PHP_AUTH_PW' => $non_empty_string_helper,
|
||||
'AUTH_TYPE' => $non_empty_string_helper,
|
||||
'PATH_INFO' => $non_empty_string_helper,
|
||||
'ORIG_PATH_INFO' => $non_empty_string_helper,
|
||||
// misc from RFC not included above already http://www.faqs.org/rfcs/rfc3875.html
|
||||
'CONTENT_LENGTH' => $string_helper,
|
||||
'CONTENT_TYPE' => $string_helper,
|
||||
// common, misc stuff
|
||||
'FCGI_ROLE' => $non_empty_string_helper,
|
||||
'HOME' => $non_empty_string_helper,
|
||||
'HTTP_CACHE_CONTROL' => $non_empty_string_helper,
|
||||
'HTTP_COOKIE' => $non_empty_string_helper,
|
||||
'HTTP_PRIORITY' => $non_empty_string_helper,
|
||||
'PATH' => $non_empty_string_helper,
|
||||
'REDIRECT_STATUS' => $non_empty_string_helper,
|
||||
'REQUEST_SCHEME' => $non_empty_string_helper,
|
||||
'USER' => $non_empty_string_helper,
|
||||
// common, misc headers
|
||||
'HTTP_UPGRADE_INSECURE_REQUESTS' => $non_empty_string_helper,
|
||||
'HTTP_X_FORWARDED_PROTO' => $non_empty_string_helper,
|
||||
'HTTP_CLIENT_IP' => $non_empty_string_helper,
|
||||
'HTTP_X_REAL_IP' => $non_empty_string_helper,
|
||||
'HTTP_X_FORWARDED_FOR' => $non_empty_string_helper,
|
||||
'HTTP_CF_CONNECTING_IP' => $non_empty_string_helper,
|
||||
'HTTP_CF_IPCOUNTRY' => $non_empty_string_helper,
|
||||
'HTTP_CF_VISITOR' => $non_empty_string_helper,
|
||||
'HTTP_CDN_LOOP' => $non_empty_string_helper,
|
||||
// common, misc browser headers
|
||||
'HTTP_DNT' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_DEST' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_USER' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_MODE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_FETCH_SITE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA_PLATFORM' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA_MOBILE' => $non_empty_string_helper,
|
||||
'HTTP_SEC_CH_UA' => $non_empty_string_helper,
|
||||
// phpunit
|
||||
'APP_DEBUG' => $bool_string_helper,
|
||||
'APP_ENV' => $string_helper,
|
||||
],
|
||||
null,
|
||||
false,
|
||||
Type::getNonEmptyString(),
|
||||
Type::getString()
|
||||
);
|
||||
|
||||
return new Union([$detailed_type]);
|
||||
}
|
||||
|
||||
|
30
src/Psalm/Internal/TypeVisitor/ContainsStaticVisitor.php
Normal file
30
src/Psalm/Internal/TypeVisitor/ContainsStaticVisitor.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user