Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExportedNodeResolver - Add support for attributes
- Loading branch information
Showing
9 changed files
with
281 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
use ReturnTypeWillChange; | ||
use function count; | ||
|
||
class ExportedAttributeNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
/** | ||
* @param array<int|string, string> $args argument name or index(string|int) => value expression (string) | ||
*/ | ||
public function __construct( | ||
private string $name, | ||
private array $args, | ||
) | ||
{ | ||
} | ||
|
||
public function equals(ExportedNode $node): bool | ||
{ | ||
if (!$node instanceof self) { | ||
return false; | ||
} | ||
|
||
if ($this->name !== $node->name) { | ||
return false; | ||
} | ||
|
||
if (count($this->args) !== count($node->args)) { | ||
return false; | ||
} | ||
|
||
foreach ($this->args as $argName => $argValue) { | ||
if (!isset($node->args[$argName]) || $argValue !== $node->args[$argName]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return self | ||
*/ | ||
public static function __set_state(array $properties): ExportedNode | ||
{ | ||
return new self( | ||
$properties['name'], | ||
$properties['args'], | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'type' => self::class, | ||
'data' => [ | ||
'name' => $this->name, | ||
'args' => $this->args, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param mixed[] $data | ||
* @return self | ||
*/ | ||
public static function decode(array $data): ExportedNode | ||
{ | ||
return new self( | ||
$data['name'], | ||
$data['args'], | ||
); | ||
} | ||
|
||
} |
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
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.