Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 17, 2022
1 parent 7b6e09a commit 3b3afd5
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 110 deletions.
20 changes: 4 additions & 16 deletions psalm-baseline.xml
@@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -630,16 +631,8 @@ private static function getMethodReturnType(
*/
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();
}
}
Expand Up @@ -668,89 +668,91 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_
$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]);
}

Expand Down
30 changes: 30 additions & 0 deletions src/Psalm/Internal/TypeVisitor/ContainsStaticVisitor.php
@@ -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;
}
}

0 comments on commit 3b3afd5

Please sign in to comment.