Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vimeo/psalm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.5.0
Choose a base ref
...
head repository: vimeo/psalm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.6.0
Choose a head ref
  • 7 commits
  • 9 files changed
  • 3 contributors

Commits on Jan 23, 2023

  1. HEAD in all caps

    buismaarten authored Jan 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2065f62 View commit details
  2. Check $this in static closures

    Fixes #9148
    Fixes #2813
    weirdan committed Jan 23, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    weirdan Bruce Weirdan
    Copy the full SHA
    70f2fb7 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    weirdan Bruce Weirdan
    Copy the full SHA
    bfce3a4 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a5014c5 View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f0df119 View commit details
  6. Copy the full SHA
    68842a5 View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e784128 View commit details
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClosureAnalyzer.php
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ public static function analyzeExpression(

$codebase = $statements_analyzer->getCodebase();

if (!$statements_analyzer->isStatic()) {
if (!$statements_analyzer->isStatic() && !$closure_analyzer->isStatic()) {
if ($context->collect_mutations &&
$context->self &&
$codebase->classExtends(
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
@@ -217,7 +217,9 @@ public function analyze(
$this->suppressed_issues += $appearing_class_storage->suppressed_issues;
}

if ($storage instanceof MethodStorage && $storage->is_static) {
if (($storage instanceof MethodStorage || $storage instanceof FunctionStorage)
&& $storage->is_static
) {
$this->is_static = true;
}

2 changes: 1 addition & 1 deletion src/Psalm/Internal/LanguageServer/Client/TextDocument.php
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public function xcontent(TextDocumentIdentifier $textDocument): Promise
/**
* @return Generator<int, Promise<object>, object, TextDocumentItem>
*/
static function () use ($textDocument) {
function () use ($textDocument) {
/** @var Promise<object> */
$promise = $this->handler->request(
'textDocument/xcontent',
4 changes: 2 additions & 2 deletions src/Psalm/Internal/LanguageServer/ClientHandler.php
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public function request(string $method, $params): Promise
/**
* @return Generator<int, Promise, mixed, Promise<mixed>>
*/
static function () use ($id, $method, $params): Generator {
function () use ($id, $method, $params): Generator {
yield $this->protocolWriter->write(
new Message(
new Request($id, $method, (object) $params),
@@ -58,7 +58,7 @@ static function () use ($id, $method, $params): Generator {
$deferred = new Deferred();

$listener =
static function (Message $msg) use ($id, $deferred, &$listener): void {
function (Message $msg) use ($id, $deferred, &$listener): void {
error_log('request handler');
/**
* @psalm-suppress UndefinedPropertyFetch
Original file line number Diff line number Diff line change
@@ -1120,6 +1120,8 @@ private function createStorageForFunctionLike(

$storage = $this->storage = $this->file_storage->functions[$function_id] = new FunctionStorage();

$storage->is_static = $stmt->static;

if ($stmt instanceof PhpParser\Node\Expr\Closure) {
foreach ($stmt->uses as $closure_use) {
if ($closure_use->byRef && is_string($closure_use->var->name)) {
3 changes: 1 addition & 2 deletions src/Psalm/Plugin/Shepherd.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@
use const PHP_URL_HOST;
use const PHP_URL_SCHEME;
use const STDERR;
use const STDOUT;

final class Shepherd implements AfterAnalysisInterface
{
@@ -120,7 +119,7 @@ public static function afterAnalysis(
if ($response_status_code >= 200 && $response_status_code < 300) {
$shepherd_host = parse_url($codebase->config->shepherd_endpoint, PHP_URL_HOST);

fwrite(STDOUT, "🐑 results sent to $shepherd_host 🐑" . PHP_EOL);
fwrite(STDERR, "🐑 results sent to $shepherd_host 🐑" . PHP_EOL);
return;
}

2 changes: 1 addition & 1 deletion src/Psalm/SourceControl/Git/GitInfo.php
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ final class GitInfo extends SourceControlInfo
* Constructor.
*
* @param string $branch branch name
* @param CommitInfo $head hEAD commit
* @param CommitInfo $head HEAD commit
* @param RemoteInfo[] $remotes remote repositories
*/
public function __construct(string $branch, CommitInfo $head, array $remotes)
6 changes: 6 additions & 0 deletions src/Psalm/Storage/FunctionStorage.php
Original file line number Diff line number Diff line change
@@ -6,4 +6,10 @@ final class FunctionStorage extends FunctionLikeStorage
{
/** @var array<string, bool> */
public $byref_uses = [];

/**
* @var bool
* @todo lift this property to FunctionLikeStorage in Psalm 6
*/
public $is_static = false;
}
28 changes: 28 additions & 0 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
@@ -1368,6 +1368,34 @@ public static function __callStatic(string $name, array $args): mixed {
'ignored_issues' => [],
'php_version' => '8.1',
],
'thisInStaticClosure' => [
'code' => '<?php
class C {
public string $a = "zzz";
public function f(): void {
$f = static function (): void {
echo $this->a;
};
$f();
}
}
',
'error_message' => 'InvalidScope',
],
'thisInStaticArrowFunction' => [
'code' => '<?php
class C {
public int $a = 1;
public function f(): int {
$f = static fn(): int => $this->a;
return $f();;
}
}
',
'error_message' => 'InvalidScope',
'ignored_issues' => [],
'php_version' => '7.4',
],
];
}
}