Skip to content

Commit

Permalink
Fixing review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
olsavmic committed Jun 17, 2022
1 parent e9da297 commit 8ed8cbc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 70 deletions.
18 changes: 4 additions & 14 deletions src/Dependency/ExportedNode/ExportedAttributeArgumentNode.php
Expand Up @@ -4,15 +4,12 @@

use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use ReturnTypeWillChange;

class ExportedAttributeArgumentNode implements ExportedNode, JsonSerializable
{

public function __construct(
private ?string $name,
private string $value,
private bool $byRef,
)
public function __construct(private string $value)
{
}

Expand All @@ -22,9 +19,7 @@ public function equals(ExportedNode $node): bool
return false;
}

return $this->name === $node->name
&& $this->value === $node->value
&& $this->byRef === $node->byRef;
return $this->value === $node->value;
}

/**
Expand All @@ -34,23 +29,20 @@ public function equals(ExportedNode $node): bool
public static function __set_state(array $properties): ExportedNode
{
return new self(
$properties['name'],
$properties['value'],
$properties['byRef'],
);
}

/**
* @return mixed
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return [
'type' => self::class,
'data' => [
'name' => $this->name,
'value' => $this->value,
'byRef' => $this->byRef,
],
];
}
Expand All @@ -62,9 +54,7 @@ public function jsonSerialize()
public static function decode(array $data): ExportedNode
{
return new self(
$data['name'],
$data['value'],
$data['byRef'],
);
}

Expand Down
33 changes: 21 additions & 12 deletions src/Dependency/ExportedNode/ExportedAttributeNode.php
Expand Up @@ -5,14 +5,14 @@
use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use PHPStan\ShouldNotHappenException;
use function array_map;
use ReturnTypeWillChange;
use function count;

class ExportedAttributeNode implements ExportedNode, JsonSerializable
{

/**
* @param ExportedAttributeArgumentNode[] $args
* @param array<int|string, ExportedAttributeArgumentNode> $args
*/
public function __construct(
private string $name,
Expand All @@ -27,18 +27,21 @@ public function equals(ExportedNode $node): bool
return false;
}

if ($this->name !== $node->name) {
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)) {
foreach ($this->args as $argName => $arg) {
if (!isset($node->args[$argName]) || !$arg->equals($node->args[$argName])) {
return false;
}
}

return $this->name === $node->name;
return true;
}

/**
Expand All @@ -56,6 +59,7 @@ public static function __set_state(array $properties): ExportedNode
/**
* @return mixed
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return [
Expand All @@ -73,14 +77,19 @@ public function jsonSerialize()
*/
public static function decode(array $data): ExportedNode
{
$args = [];

foreach ($data['args'] as $argName => $argData) {
if ($argData['type'] !== ExportedAttributeArgumentNode::class) {
throw new ShouldNotHappenException();
}

$args[$argName] = ExportedAttributeArgumentNode::decode($argData['data']);
}

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']),
$args,
);
}

Expand Down
11 changes: 5 additions & 6 deletions src/Dependency/ExportedNode/ExportedClassConstantNode.php
Expand Up @@ -33,9 +33,8 @@ public function equals(ExportedNode $node): bool
return false;
}

foreach ($this->attributes as $i => $ourAttribute) {
$theirAttribute = $node->attributes[$i];
if (!$ourAttribute->equals($theirAttribute)) {
foreach ($this->attributes as $i => $attribute) {
if (!$attribute->equals($node->attributes[$i])) {
return false;
}
}
Expand Down Expand Up @@ -66,11 +65,11 @@ public static function decode(array $data): ExportedNode
return new self(
$data['name'],
$data['value'],
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Dependency/ExportedNode/ExportedClassNode.php
Expand Up @@ -161,11 +161,11 @@ public static function decode(array $data): ExportedNode

return $nodeType::decode($node['data']);
}, $data['statements']),
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
12 changes: 5 additions & 7 deletions src/Dependency/ExportedNode/ExportedEnumNode.php
Expand Up @@ -63,11 +63,9 @@ public function equals(ExportedNode $node): bool
}

foreach ($this->attributes as $i => $attribute) {
if ($attribute->equals($node->attributes[$i])) {
continue;
if (!$attribute->equals($node->attributes[$i])) {
return false;
}

return false;
}

return $this->name === $node->name
Expand Down Expand Up @@ -126,11 +124,11 @@ public static function decode(array $data): ExportedNode

return $nodeType::decode($node['data']);
}, $data['statements']),
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Dependency/ExportedNode/ExportedFunctionNode.php
Expand Up @@ -60,9 +60,8 @@ public function equals(ExportedNode $node): bool
return false;
}

foreach ($this->attributes as $i => $ourAttribute) {
$theirAttribute = $node->attributes[$i];
if (!$ourAttribute->equals($theirAttribute)) {
foreach ($this->attributes as $i => $attribute) {
if (!$attribute->equals($node->attributes[$i])) {
return false;
}
}
Expand Down Expand Up @@ -124,11 +123,11 @@ public static function decode(array $data): ExportedNode
}
return ExportedParameterNode::decode($parameterData['data']);
}, $data['parameters']),
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Dependency/ExportedNode/ExportedMethodNode.php
Expand Up @@ -65,9 +65,8 @@ public function equals(ExportedNode $node): bool
return false;
}

foreach ($this->attributes as $i => $ourAttribute) {
$theirAttribute = $node->attributes[$i];
if (!$ourAttribute->equals($theirAttribute)) {
foreach ($this->attributes as $i => $attribute) {
if (!$attribute->equals($node->attributes[$i])) {
return false;
}
}
Expand Down Expand Up @@ -149,11 +148,11 @@ public static function decode(array $data): ExportedNode
}
return ExportedParameterNode::decode($parameterData['data']);
}, $data['parameters']),
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Dependency/ExportedNode/ExportedParameterNode.php
Expand Up @@ -36,9 +36,8 @@ public function equals(ExportedNode $node): bool
return false;
}

foreach ($this->attributes as $i => $ourAttribute) {
$theirAttribute = $node->attributes[$i];
if (!$ourAttribute->equals($theirAttribute)) {
foreach ($this->attributes as $i => $attribute) {
if (!$attribute->equals($node->attributes[$i])) {
return false;
}
}
Expand Down Expand Up @@ -97,11 +96,11 @@ public static function decode(array $data): ExportedNode
$data['byRef'],
$data['variadic'],
$data['hasDefault'],
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Dependency/ExportedNode/ExportedPropertiesNode.php
Expand Up @@ -61,9 +61,8 @@ public function equals(ExportedNode $node): bool
return false;
}

foreach ($this->attributes as $i => $ourAttribute) {
$theirAttribute = $node->attributes[$i];
if (!$ourAttribute->equals($theirAttribute)) {
foreach ($this->attributes as $i => $attribute) {
if (!$attribute->equals($node->attributes[$i])) {
return false;
}
}
Expand Down Expand Up @@ -107,11 +106,11 @@ public static function decode(array $data): ExportedNode
$data['private'],
$data['static'],
$data['readonly'],
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
array_map(static function (array $attributeData): ExportedAttributeNode {
if ($attributeData['type'] !== ExportedAttributeNode::class) {
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
return ExportedAttributeNode::decode($attributeData['data']);
}, $data['attributes']),
);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Dependency/ExportedNodeResolver.php
Expand Up @@ -411,11 +411,9 @@ private function exportAttributeNodes(array $attributeGroups): array
foreach ($attributeGroups as $attributeGroup) {
foreach ($attributeGroup->attrs as $attribute) {
$args = [];
foreach ($attribute->args as $arg) {
$args[] = new ExportedAttributeArgumentNode(
$arg->name !== null ? $arg->name->name : null,
foreach ($attribute->args as $i => $arg) {
$args[$arg->name->name ?? $i] = new ExportedAttributeArgumentNode(
$this->exprPrinter->printExpr($arg->value),
$arg->byRef,
);
}

Expand Down

0 comments on commit 8ed8cbc

Please sign in to comment.