-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Expected node type PhpParser\Node\Stmt\Property, NULL occurred
- Loading branch information
1 parent
1e50372
commit e5f8e72
Showing
6 changed files
with
318 additions
and
156 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
120 changes: 120 additions & 0 deletions
120
src/Dependency/ExportedNode/ExportedClassConstantsNode.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,120 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
|
||
class ExportedClassConstantsNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
/** @var ExportedClassConstantNode[] */ | ||
private array $constants; | ||
|
||
private bool $public; | ||
|
||
private bool $private; | ||
|
||
private bool $final; | ||
|
||
private ?ExportedPhpDocNode $phpDoc; | ||
|
||
/** | ||
* @param ExportedClassConstantNode[] $constants | ||
*/ | ||
public function __construct(array $constants, bool $public, bool $private, bool $final, ?ExportedPhpDocNode $phpDoc) | ||
{ | ||
$this->constants = $constants; | ||
$this->public = $public; | ||
$this->private = $private; | ||
$this->final = $final; | ||
$this->phpDoc = $phpDoc; | ||
} | ||
|
||
public function equals(ExportedNode $node): bool | ||
{ | ||
if (!$node instanceof self) { | ||
return false; | ||
} | ||
|
||
if ($this->phpDoc === null) { | ||
if ($node->phpDoc !== null) { | ||
return false; | ||
} | ||
} elseif ($node->phpDoc !== null) { | ||
if (!$this->phpDoc->equals($node->phpDoc)) { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
|
||
if (count($this->constants) !== count($node->constants)) { | ||
return false; | ||
} | ||
|
||
foreach ($this->constants as $i => $constant) { | ||
if (!$constant->equals($node->constants[$i])) { | ||
return false; | ||
} | ||
} | ||
|
||
return $this->public === $node->public | ||
&& $this->private === $node->private | ||
&& $this->final === $node->final; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return self | ||
*/ | ||
public static function __set_state(array $properties): ExportedNode | ||
{ | ||
return new self( | ||
$properties['constants'], | ||
$properties['public'], | ||
$properties['private'], | ||
$properties['final'], | ||
$properties['phpDoc'] | ||
); | ||
} | ||
|
||
/** | ||
* @param mixed[] $data | ||
* @return self | ||
*/ | ||
public static function decode(array $data): ExportedNode | ||
{ | ||
return new self( | ||
array_map(static function (array $constantData): ExportedClassConstantNode { | ||
if ($constantData['type'] !== ExportedClassConstantNode::class) { | ||
throw new \PHPStan\ShouldNotHappenException(); | ||
} | ||
return ExportedClassConstantNode::decode($constantData['data']); | ||
}, $data['constants']), | ||
$data['public'], | ||
$data['private'], | ||
$data['final'], | ||
$data['phpDoc'] !== null ? ExportedPhpDocNode::decode($data['phpDoc']['data']) : null | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
#[\ReturnTypeWillChange] | ||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'type' => self::class, | ||
'data' => [ | ||
'constants' => $this->constants, | ||
'public' => $this->public, | ||
'private' => $this->private, | ||
'final' => $this->final, | ||
'phpDoc' => $this->phpDoc, | ||
], | ||
]; | ||
} | ||
|
||
} |
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
Oops, something went wrong.