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 7ffe60e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 131 deletions.
71 changes: 0 additions & 71 deletions src/Dependency/ExportedNode/ExportedAttributeArgumentNode.php

This file was deleted.

24 changes: 11 additions & 13 deletions src/Dependency/ExportedNode/ExportedAttributeNode.php
Expand Up @@ -4,15 +4,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, string> $args argument name or index(string|int) => value expression (string)
*/
public function __construct(
private string $name,
Expand All @@ -27,18 +26,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 => $argValue) {
if (!isset($node->args[$argName]) || $argValue !== $node->args[$argName]) {
return false;
}
}

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

/**
Expand All @@ -56,6 +58,7 @@ public static function __set_state(array $properties): ExportedNode
/**
* @return mixed
*/
#[ReturnTypeWillChange]
public function jsonSerialize()
{
return [
Expand All @@ -75,12 +78,7 @@ 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']),
$data['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
9 changes: 2 additions & 7 deletions src/Dependency/ExportedNodeResolver.php
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Dependency\ExportedNode\ExportedAttributeArgumentNode;
use PHPStan\Dependency\ExportedNode\ExportedAttributeNode;
use PHPStan\Dependency\ExportedNode\ExportedClassConstantNode;
use PHPStan\Dependency\ExportedNode\ExportedClassConstantsNode;
Expand Down Expand Up @@ -411,12 +410,8 @@ 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,
$this->exprPrinter->printExpr($arg->value),
$arg->byRef,
);
foreach ($attribute->args as $i => $arg) {
$args[$arg->name->name ?? $i] = $this->exprPrinter->printExpr($arg->value);
}

$nodes[] = new ExportedAttributeNode(
Expand Down

0 comments on commit 7ffe60e

Please sign in to comment.