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
385 additions
and
19 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
|
||
class ExportedAttributeArgumentNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
private ?string $name; | ||
|
||
private string $value; | ||
|
||
private bool $byRef; | ||
|
||
public function __construct(?string $name, string $value, bool $byRef) | ||
{ | ||
$this->name = $name; | ||
$this->value = $value; | ||
$this->byRef = $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,92 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Dependency\ExportedNode; | ||
|
||
use JsonSerializable; | ||
use PHPStan\Dependency\ExportedNode; | ||
|
||
class ExportedAttributeNode implements ExportedNode, JsonSerializable | ||
{ | ||
|
||
private string $name; | ||
|
||
/** @var ExportedAttributeArgumentNode[] $args */ | ||
private array $args; | ||
|
||
/** | ||
* @param ExportedAttributeArgumentNode[] $args | ||
*/ | ||
public function __construct( | ||
string $name, | ||
array $args | ||
) | ||
{ | ||
$this->name = $name; | ||
$this->args = $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 \PHPStan\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.