-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8652 from VincentLanglet/improveSerializeSupport
serialize is not pure for array of object
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Psalm/Internal/TypeVisitor/CanContainObjectTypeVisitor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\TypeVisitor; | ||
|
||
use Psalm\Codebase; | ||
use Psalm\Internal\Type\Comparator\AtomicTypeComparator; | ||
use Psalm\Internal\Type\Comparator\UnionTypeComparator; | ||
use Psalm\Type\Atomic; | ||
use Psalm\Type\Atomic\TObject; | ||
use Psalm\Type\NodeVisitor; | ||
use Psalm\Type\TypeNode; | ||
use Psalm\Type\Union; | ||
|
||
class CanContainObjectTypeVisitor extends NodeVisitor | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $contains_object_type = false; | ||
|
||
/** | ||
* @var Codebase | ||
*/ | ||
private $codebase; | ||
|
||
public function __construct(Codebase $codebase) | ||
{ | ||
$this->codebase = $codebase; | ||
} | ||
|
||
protected function enterNode(TypeNode $type): ?int | ||
{ | ||
if ($type instanceof Union | ||
&& ( | ||
UnionTypeComparator::canBeContainedBy($this->codebase, new Union([new TObject()]), $type) | ||
&& UnionTypeComparator::canBeContainedBy($this->codebase, $type, new Union([new TObject()])) | ||
) | ||
|| | ||
$type instanceof Atomic | ||
&& ( | ||
AtomicTypeComparator::isContainedBy($this->codebase, new TObject(), $type) | ||
|| AtomicTypeComparator::isContainedBy($this->codebase, $type, new TObject()) | ||
) | ||
) { | ||
$this->contains_object_type = true; | ||
return NodeVisitor::STOP_TRAVERSAL; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function matches(): bool | ||
{ | ||
return $this->contains_object_type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters