Skip to content

Commit 4785514

Browse files
committed
Merge branch '6.x'
2 parents 9b0b4bd + a6c7e23 commit 4785514

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

src/Psalm/Internal/Cli/Psalm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public static function run(array $argv): void
323323

324324
$show_info = self::initShowInfo($options);
325325

326-
$is_diff = self::initIsDiff($options);
326+
$is_diff = false; // self::initIsDiff($options);
327327

328328
$find_unused_code = self::shouldFindUnusedCode($options, $config);
329329

@@ -493,12 +493,12 @@ private static function initShowInfo(array $options): bool
493493
: false;
494494
}
495495

496-
private static function initIsDiff(array $options): bool
496+
/*private static function initIsDiff(array $options): bool
497497
{
498498
return !isset($options['no-diff'])
499499
&& !isset($options['set-baseline'])
500500
&& !isset($options['update-baseline']);
501-
}
501+
}*/
502502

503503
/**
504504
* @param array<int,string> $args

src/Psalm/Internal/Codebase/ClassLikes.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use function preg_quote;
6464
use function preg_replace;
6565
use function strlen;
66+
use function strpos;
6667
use function strrpos;
6768
use function strtolower;
6869
use function substr;
@@ -884,9 +885,15 @@ public function consolidateAnalyzedData(Methods $methods, ?Progress $progress, b
884885
&& $classlike_storage->stmt_location !== null
885886
&& isset($project_analyzer->getIssuesToFix()['ClassMustBeFinal'])
886887
) {
887-
$idx = $classlike_storage->stmt_location->getSelectionBounds()[0];
888+
$selection = $classlike_storage->stmt_location->getSnippet();
889+
$insert_pos = strpos($selection, "class");
890+
891+
if ($insert_pos === false) {
892+
$insert_pos = $classlike_storage->stmt_location->getSelectionBounds()[0];
893+
}
894+
888895
FileManipulationBuffer::add($classlike_storage->stmt_location->file_path, [
889-
new FileManipulation($idx, $idx, 'final ', true),
896+
new FileManipulation($insert_pos, $insert_pos, 'final ', true),
890897
]);
891898
}
892899
}

src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,12 @@ private function createStorageForFunctionLike(
11401140
}
11411141
}
11421142
}
1143+
} elseif ($stmt instanceof PhpParser\Node\PropertyHook) {
1144+
$function_id = $cased_function_id = strtolower($this->file_path)
1145+
. ':' . $stmt->getLine()
1146+
. ':' . (int)$stmt->getAttribute('startFilePos') . ':-:hook';
1147+
1148+
$storage = $this->storage = $this->file_storage->functions[$function_id] = new FunctionStorage();
11431149
} else {
11441150
throw new UnexpectedValueException("Unrecognized functionlike of type ".($stmt::class));
11451151
}

stubs/CoreImmutableClasses.phpstub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class DateTimeImmutable implements DateTimeInterface
9191
* @psalm-mutation-free
9292
* @return static
9393
*/
94-
public function setTimestamp(int $unixtimestamp) {}
94+
public function setTimestamp(int $timestamp) {}
9595

9696
/**
9797
* @psalm-mutation-free

stubs/Reflection.phpstub

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class ReflectionClass implements Reflector {
1313
public $name;
1414

1515
/**
16-
* @param T|class-string<T>|interface-string<T>|trait-string|enum-string<T> $argument
16+
* @param T|class-string<T>|interface-string<T>|trait-string|enum-string<T> $objectOrClass
1717
* @psalm-pure
18-
* @psalm-taint-sink callable $argument
18+
* @psalm-taint-sink callable $objectOrClass
1919
*/
20-
public function __construct($argument) {}
20+
public function __construct(object|string $objectOrClass) {}
2121

2222
/**
2323
* @return class-string<T>

tests/EndToEnd/PsalmEndToEndTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function testPsalmWithPHPVersionFromConfig(): void
176176
);
177177
}
178178

179+
/*
179180
public function testPsalmDiff(): void
180181
{
181182
copy(__DIR__ . '/../fixtures/DummyProjectWithErrors/diff_composer.lock', self::$tmpDir . '/composer.lock');
@@ -203,7 +204,7 @@ public function testPsalmDiff(): void
203204
$this->assertSame(2, $result['CODE']);
204205
205206
@unlink(self::$tmpDir . '/composer.lock');
206-
}
207+
}*/
207208

208209
public function testTainting(): void
209210
{

tests/Php84Test.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@ class Foo {}
6363
'ignored_issues' => ['UnusedVariable'],
6464
'php_version' => '8.4',
6565
],
66+
'propertyHook' => [
67+
'code' => '<?php
68+
class Foo {
69+
public int|null $test = null{
70+
get {
71+
return $this->test;
72+
}
73+
set(int $value) {
74+
$this->test = $value;
75+
}
76+
}
77+
}
78+
$property_hook = new Foo();
79+
$property_hook->test = 5;
80+
',
81+
'assertions' => [
82+
'$property_hook->test' => 'int',
83+
],
84+
'ignored_issues' => [],
85+
'php_version' => '8.4',
86+
],
6687
];
6788
}
6889

0 commit comments

Comments
 (0)