1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Clean up immutable fix

This commit is contained in:
Brown 2020-09-03 15:32:14 -04:00
parent 8505ca2a23
commit 68ebef2a2e
4 changed files with 4 additions and 70 deletions

View File

@ -696,7 +696,6 @@ class InstancePropertyAssignmentAnalyzer
$property_id,
$property_storage,
$declaring_class_storage,
$assignment_value_type,
$context
);
@ -1069,7 +1068,6 @@ class InstancePropertyAssignmentAnalyzer
string $property_id,
\Psalm\Storage\PropertyStorage $property_storage,
\Psalm\Storage\ClassLikeStorage $declaring_class_storage,
?Type\Union $assignment_value_type,
Context $context
): void {
$codebase = $statements_analyzer->getCodebase();

View File

@ -942,7 +942,6 @@ class InstancePropertyFetchAnalyzer
$property_id,
$property_storage,
$declaring_class_storage,
null,
$context
);
}

View File

@ -1,66 +0,0 @@
<?php
namespace Psalm\Internal\TypeVisitor;
use PhpParser;
use Psalm\CodeLocation;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\IssueBuffer;
use Psalm\Issue\ImpurePropertyAssignment;
use Psalm\Type\NodeVisitor;
use Psalm\Type\Union;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\TypeNode;
class ImmutablePropertyAssignmentVisitor extends NodeVisitor
{
private $statements_analyzer;
private $stmt;
/** @var bool */
public $has_mutation = false;
public function __construct(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\PropertyFetch $stmt
) {
$this->statements_analyzer = $statements_analyzer;
$this->stmt = $stmt;
}
public function enterNode(TypeNode $type) : ?int
{
if ($type instanceof Union && $type->reference_free) {
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}
if ($type instanceof TClassString) {
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}
if ($type instanceof TNamedObject) {
$codebase = $this->statements_analyzer->getCodebase();
$object_storage = $codebase->classlike_storage_provider->get(
$type->value
);
if (!$object_storage->mutation_free) {
if (IssueBuffer::accepts(
new ImpurePropertyAssignment(
'Cannot store a reference to an externally-mutable object'
. ' inside an immutable object consider using __clone',
new CodeLocation($this->statements_analyzer, $this->stmt)
),
$this->statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
$this->has_mutation = true;
}
}
return null;
}
}

View File

@ -115,7 +115,7 @@ class ImmutableAnnotationAdditionTest extends FileManipulationTest
['MissingImmutableAnnotation'],
true,
],
'dontAddPureAnnotationWhenClassCanHoldMutableData' => [
'addPureAnnotationWhenClassCanHoldMutableData' => [
'<?php
class B {
public int $i = 5;
@ -147,6 +147,9 @@ class ImmutableAnnotationAdditionTest extends FileManipulationTest
public int $i = 5;
}
/**
* @psalm-immutable
*/
class A {
public B $b;