Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
366 additions
and
2 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/Dependency/ExportedNode/ExportedAttributeArgumentNode.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,71 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
|
||
class ExportedAttributeArgumentNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
public function __construct( | ||
private ?string $name, | ||
private string $value, | ||
private bool $byRef, | ||
) | ||
{ | ||
} | ||
|
||
public function equals(ExportedNode $node): bool | ||
{ | ||
if (!$node instanceof self) { | ||
return false; | ||
} | ||
|
||
return $this->name === $node->name | ||
&& $this->value === $node->value | ||
&& $this->byRef === $node->byRef; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return self | ||
*/ | ||
public static function __set_state(array $properties): ExportedNode | ||
{ | ||
return new self( | ||
$properties['name'], | ||
$properties['value'], | ||
$properties['byRef'], | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'type' => self::class, | ||
'data' => [ | ||
'name' => $this->name, | ||
'value' => $this->value, | ||
'byRef' => $this->byRef, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param mixed[] $data | ||
* @return self | ||
*/ | ||
public static function decode(array $data): ExportedNode | ||
{ | ||
return new self( | ||
$data['name'], | ||
$data['value'], | ||
$data['byRef'], | ||
); | ||
} | ||
|
||
} |
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,87 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
use PHPStan\ShouldNotHappenException; | ||
use function array_map; | ||
use function count; | ||
|
||
class ExportedAttributeNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
/** | ||
* @param ExportedAttributeArgumentNode[] $args | ||
*/ | ||
public function __construct( | ||
private string $name, | ||
private array $args, | ||
) | ||
{ | ||
} | ||
|
||
public function equals(ExportedNode $node): bool | ||
{ | ||
if (!$node instanceof self) { | ||
return false; | ||
} | ||
|
||
if (count($this->args) !== count($node->args)) { | ||
return false; | ||
} | ||
|
||
foreach ($this->args as $i => $ourAttribute) { | ||
$theirAttribute = $node->args[$i]; | ||
if (!$ourAttribute->equals($theirAttribute)) { | ||
return false; | ||
} | ||
} | ||
|
||
return $this->name === $node->name; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return self | ||
*/ | ||
public static function __set_state(array $properties): ExportedNode | ||
{ | ||
return new self( | ||
$properties['name'], | ||
$properties['args'], | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
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'], | ||
array_map(static function (array $parameterData): ExportedAttributeArgumentNode { | ||
if ($parameterData['type'] !== ExportedAttributeArgumentNode::class) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
return ExportedAttributeArgumentNode::decode($parameterData['data']); | ||
}, $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
Oops, something went wrong.