mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
make tests work in PHP < 8.2
This commit is contained in:
parent
1ff8518888
commit
9e463bbe75
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Psalm\Internal\Analyzer\Statements\Expression\Call;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PhpParser;
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Codebase;
|
||||
@ -1267,10 +1268,15 @@ final class ArgumentsAnalyzer
|
||||
$codebase = $statements_analyzer->getCodebase();
|
||||
$declaring_property_class = (string) $codebase->properties->getDeclaringClassForProperty(
|
||||
$property_id,
|
||||
false, # what does this do? @todo
|
||||
true,
|
||||
$statements_analyzer,
|
||||
);
|
||||
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
|
||||
|
||||
try {
|
||||
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
|
||||
} catch (InvalidArgumentException $_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($declaring_class_storage->properties[$prop_name])) {
|
||||
$property_storage = $declaring_class_storage->properties[$prop_name];
|
||||
@ -1310,7 +1316,7 @@ final class ArgumentsAnalyzer
|
||||
if ($arg->value instanceof PhpParser\Node\Expr\PropertyFetch
|
||||
&& $arg->value->name instanceof PhpParser\Node\Identifier) {
|
||||
$prop_name = $arg->value->name->name;
|
||||
if ($statements_analyzer->getFQCLN()) {
|
||||
if (!empty($statements_analyzer->getFQCLN())) {
|
||||
$fq_class_name = $statements_analyzer->getFQCLN();
|
||||
|
||||
self::handleByRefReadonlyArg(
|
||||
|
@ -112,6 +112,8 @@ class TKeyedArray extends Atomic
|
||||
if ($cloned->is_list) {
|
||||
$last_k = -1;
|
||||
$had_possibly_undefined = false;
|
||||
|
||||
/** @psalm-suppress InaccessibleProperty */
|
||||
ksort($cloned->properties);
|
||||
foreach ($cloned->properties as $k => $v) {
|
||||
if (is_string($k) || $last_k !== ($k-1) || ($had_possibly_undefined && !$v->possibly_undefined)) {
|
||||
|
@ -768,63 +768,75 @@ class ImmutableAnnotationTest extends TestCase
|
||||
'code' => '<?php
|
||||
namespace World;
|
||||
|
||||
final readonly class Foo
|
||||
{
|
||||
public array $values;
|
||||
final class Foo
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
public array $values;
|
||||
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
public function bar(): mixed
|
||||
{
|
||||
return reset($this->values);
|
||||
}
|
||||
}',
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function bar()
|
||||
{
|
||||
return reset($this->values);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'InaccessibleProperty',
|
||||
],
|
||||
'readonlyByRef' => [
|
||||
'code' => '<?php
|
||||
namespace World;
|
||||
|
||||
final readonly class Foo
|
||||
{
|
||||
public array $values;
|
||||
final class Foo
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
public array $values;
|
||||
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
|
||||
$x = new Foo([]);
|
||||
reset($x->values);',
|
||||
$x = new Foo([]);
|
||||
reset($x->values);',
|
||||
'error_message' => 'InaccessibleProperty',
|
||||
],
|
||||
'readonlyByRefCustomFunction' => [
|
||||
'code' => '<?php
|
||||
namespace World;
|
||||
|
||||
final readonly class Foo
|
||||
{
|
||||
public array $values;
|
||||
final class Foo
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
public array $values;
|
||||
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $a
|
||||
* @param array $b
|
||||
* @return void
|
||||
*/
|
||||
function bar($a, &$b) {}
|
||||
/**
|
||||
* @param string $a
|
||||
* @param array $b
|
||||
* @return void
|
||||
*/
|
||||
function bar($a, &$b) {}
|
||||
|
||||
$x = new Foo([]);
|
||||
bar("hello", $x->values);',
|
||||
$x = new Foo([]);
|
||||
bar("hello", $x->values);',
|
||||
'error_message' => 'InaccessibleProperty',
|
||||
],
|
||||
'preventUnset' => [
|
||||
|
Loading…
Reference in New Issue
Block a user