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

Convertion of partials to full imports #7155

Merged
merged 18 commits into from Dec 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion dictionaries/InternalTaintSinkMap.php
@@ -1,9 +1,11 @@
<?php

use Psalm\Type\TaintKind;

// This maps internal function names to sink types that we don’t want to end up there

/**
* @var array<string, list<list<Type\TaintKind::*>>>
* @var array<string, list<list<TaintKind::*>>>
*/
return [
'exec' => [['shell']],
Expand Down
27 changes: 15 additions & 12 deletions examples/TemplateChecker.php
Expand Up @@ -3,19 +3,22 @@

use PhpParser;
use Psalm;
use Psalm\CodeLocation;
use Psalm\Codebase;
use Psalm\Context;
use Psalm\DocComment;
use Psalm\Internal\Analyzer\ClassAnalyzer;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Internal\Analyzer\ClassLikeNameOptions;
use Psalm\Internal\Analyzer\MethodAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\CodeLocation;
use Psalm\Context;
use Psalm\DocComment;
use Psalm\Node\Stmt\VirtualClass;
use Psalm\Node\Stmt\VirtualClassMethod;
use Psalm\Storage\MethodStorage;
use Psalm\Type;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Union;
use Psalm\Internal\MethodIdentifier;

class TemplateAnalyzer extends Psalm\Internal\Analyzer\FileAnalyzer
{
Expand Down Expand Up @@ -49,16 +52,16 @@ public function analyze(?Context $file_context = null, ?Context $global_context
}

/** @psalm-suppress ArgumentTypeCoercion */
$method_id = new \Psalm\Internal\MethodIdentifier(...explode('::', $matches[1]));
$method_id = new MethodIdentifier(...explode('::', $matches[1]));

$this_params = $this->checkMethod($method_id, $first_stmt, $codebase);

if ($this_params === false) {
return;
}

$this_params->vars_in_scope['$this'] = new Type\Union([
new Type\Atomic\TNamedObject(self::VIEW_CLASS),
$this_params->vars_in_scope['$this'] = new Union([
new TNamedObject(self::VIEW_CLASS),
]);
}
}
Expand All @@ -67,8 +70,8 @@ public function analyze(?Context $file_context = null, ?Context $global_context
$this_params = new Context();
$this_params->check_variables = false;
$this_params->self = self::VIEW_CLASS;
$this_params->vars_in_scope['$this'] = new Type\Union([
new Type\Atomic\TNamedObject(self::VIEW_CLASS),
$this_params->vars_in_scope['$this'] = new Union([
new TNamedObject(self::VIEW_CLASS),
]);
}

Expand All @@ -78,7 +81,7 @@ public function analyze(?Context $file_context = null, ?Context $global_context
/**
* @return Context|false
*/
private function checkMethod(\Psalm\Internal\MethodIdentifier $method_id, PhpParser\Node $stmt, Codebase $codebase)
private function checkMethod(MethodIdentifier $method_id, PhpParser\Node $stmt, Codebase $codebase)
{
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$this,
Expand All @@ -98,16 +101,16 @@ private function checkMethod(\Psalm\Internal\MethodIdentifier $method_id, PhpPar

$class_storage = $codebase->classlike_storage_provider->get($method_id->fq_class_name);

$this_context->vars_in_scope['$this'] = new Type\Union([new Type\Atomic\TNamedObject($class_storage->name)]);
$this_context->vars_in_scope['$this'] = new Union([new TNamedObject($class_storage->name)]);

$this->project_analyzer->getMethodMutations(
new \Psalm\Internal\MethodIdentifier($method_id->fq_class_name, '__construct'),
new MethodIdentifier($method_id->fq_class_name, '__construct'),
$this_context,
$this->getRootFilePath(),
$this->getRootFileName()
);

$this_context->vars_in_scope['$this'] = new Type\Union([new Type\Atomic\TNamedObject($class_storage->name)]);
$this_context->vars_in_scope['$this'] = new Union([new TNamedObject($class_storage->name)]);

// check the actual method
$this->project_analyzer->getMethodMutations(
Expand Down
8 changes: 6 additions & 2 deletions examples/plugins/FunctionCasingChecker.php
Expand Up @@ -12,6 +12,10 @@
use Psalm\Plugin\EventHandler\AfterMethodCallAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterFunctionCallAnalysisEvent;
use Psalm\Plugin\EventHandler\Event\AfterMethodCallAnalysisEvent;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Internal\Analyzer\FunctionLike\ReturnTypeAnalyzer;
use Psalm\Internal\MethodIdentifier;

use function explode;
use function strtolower;
use function end;
Expand All @@ -33,7 +37,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve

try {
/** @psalm-suppress ArgumentTypeCoercion */
$method_id = new \Psalm\Internal\MethodIdentifier(...explode('::', $declaring_method_id));
$method_id = new MethodIdentifier(...explode('::', $declaring_method_id));
$function_storage = $codebase->methods->getStorage($method_id);

if ($function_storage->cased_name === '__call') {
Expand Down Expand Up @@ -76,7 +80,7 @@ public static function afterFunctionCallAnalysis(AfterFunctionCallAnalysisEvent

try {
$function_storage = $codebase->functions->getStorage(
$statements_source instanceof \Psalm\Internal\Analyzer\StatementsAnalyzer
$statements_source instanceof StatementsAnalyzer
? $statements_source
: null,
strtolower($function_id)
Expand Down
9 changes: 6 additions & 3 deletions examples/plugins/composer-based/echo-checker/EchoChecker.php
Expand Up @@ -8,6 +8,9 @@
use Psalm\Issue\ArgumentTypeCoercion;
use Psalm\Plugin\EventHandler\AfterStatementAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterStatementAnalysisEvent;
use Psalm\Type\Atomic\TString;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\THtmlEscapedString;

class EchoChecker implements AfterStatementAnalysisInterface
{
Expand Down Expand Up @@ -43,9 +46,9 @@ public static function afterStatementAnalysis(AfterStatementAnalysisEvent $event
$types = $expr_type->getAtomicTypes();

foreach ($types as $type) {
if ($type instanceof \Psalm\Type\Atomic\TString
&& !$type instanceof \Psalm\Type\Atomic\TLiteralString
&& !$type instanceof \Psalm\Type\Atomic\THtmlEscapedString
if ($type instanceof TString
&& !$type instanceof TLiteralString
&& !$type instanceof THtmlEscapedString
) {
if (IssueBuffer::accepts(
new ArgumentTypeCoercion(
Expand Down
18 changes: 9 additions & 9 deletions psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@ac230dac5c64b1b4c7f4bd2d067fb7ae6176b6e8">
<files psalm-version="dev-master@76bb8bc65567d2bc600fd4925c812589917b6ab1">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$comment_block-&gt;tags['variablesfrom'][0]</code>
Expand Down Expand Up @@ -177,7 +177,7 @@
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php">
<DeprecatedClass occurrences="1">
<code>Type\Atomic\TEmpty::class</code>
<code>TEmpty::class</code>
</DeprecatedClass>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallReturnTypeFetcher.php">
Expand Down Expand Up @@ -226,7 +226,7 @@
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php">
<DeprecatedClass occurrences="3">
<code>Type\Atomic\TMixed|Type\Atomic\TTemplateParam|Type\Atomic\TEmpty</code>
<code>TMixed|TTemplateParam|TEmpty</code>
<code>new TEmpty</code>
<code>new TEmpty</code>
</DeprecatedClass>
Expand Down Expand Up @@ -260,8 +260,8 @@
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/UnsetAnalyzer.php">
<DeprecatedClass occurrences="2">
<code>new Type\Atomic\TEmpty</code>
<code>new Type\Atomic\TEmpty</code>
<code>new TEmpty</code>
<code>new TEmpty</code>
</DeprecatedClass>
</file>
<file src="src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php">
Expand All @@ -281,8 +281,8 @@
</file>
<file src="src/Psalm/Internal/Codebase/ConstantTypeResolver.php">
<DeprecatedClass occurrences="2">
<code>new Type\Atomic\TEmpty()</code>
<code>new Type\Atomic\TEmpty()</code>
<code>new TEmpty()</code>
<code>new TEmpty()</code>
</DeprecatedClass>
<DeprecatedMethod occurrences="2">
<code>Type::getEmpty()</code>
Expand Down Expand Up @@ -395,8 +395,8 @@
</file>
<file src="src/Psalm/Internal/Type/Comparator/ArrayTypeComparator.php">
<DeprecatedClass occurrences="2">
<code>new Type\Atomic\TEmpty()</code>
<code>new Type\Atomic\TEmpty()</code>
<code>new TEmpty()</code>
<code>new TEmpty()</code>
</DeprecatedClass>
</file>
<file src="src/Psalm/Internal/Type/NegatedAssertionReconciler.php">
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/CodeLocation.php
Expand Up @@ -5,6 +5,7 @@
use LogicException;
use PhpParser;
use Psalm\Internal\Analyzer\CommentAnalyzer;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use UnexpectedValueException;

use function explode;
Expand Down Expand Up @@ -148,7 +149,7 @@ private function calculateRealLocation(): void
$this->selection_start = $this->file_start;
$this->selection_end = $this->file_end + 1;

$project_analyzer = Internal\Analyzer\ProjectAnalyzer::getInstance();
$project_analyzer = ProjectAnalyzer::getInstance();

$codebase = $project_analyzer->getCodebase();

Expand Down