Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olsavmic committed Jun 15, 2022
1 parent 03fc8fb commit fb19080
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 63 deletions.
15 changes: 5 additions & 10 deletions src/Dependency/ExportedNode/ExportedAttributeArgumentNode.php
Expand Up @@ -8,17 +8,12 @@
class ExportedAttributeArgumentNode implements ExportedNode, JsonSerializable
{

private ?string $name;

private string $value;

private bool $byRef;

public function __construct(?string $name, string $value, bool $byRef)
public function __construct(
private ?string $name,
private string $value,
private bool $byRef,
)
{
$this->name = $name;
$this->value = $value;
$this->byRef = $byRef;
}

public function equals(ExportedNode $node): bool
Expand Down
19 changes: 7 additions & 12 deletions src/Dependency/ExportedNode/ExportedAttributeNode.php
Expand Up @@ -4,25 +4,21 @@

use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use PHPStan\ShouldNotHappenException;
use function array_map;
use function count;

class ExportedAttributeNode implements ExportedNode, JsonSerializable
{

private string $name;

/** @var ExportedAttributeArgumentNode[] $args */
private array $args;

/**
* @param ExportedAttributeArgumentNode[] $args
*/
public function __construct(
string $name,
array $args
private string $name,
private array $args,
)
{
$this->name = $name;
$this->args = $args;
}

public function equals(ExportedNode $node): bool
Expand All @@ -42,7 +38,6 @@ public function equals(ExportedNode $node): bool
}
}


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

Expand Down Expand Up @@ -82,10 +77,10 @@ public static function decode(array $data): ExportedNode
$data['name'],
array_map(static function (array $parameterData): ExportedAttributeArgumentNode {
if ($parameterData['type'] !== ExportedAttributeArgumentNode::class) {
throw new \PHPStan\ShouldNotHappenException();
throw new ShouldNotHappenException();
}
return ExportedAttributeArgumentNode::decode($parameterData['data']);
}, $data['args'])
}, $data['args']),
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Dependency/ExportedNode/ExportedClassConstantNode.php
Expand Up @@ -4,7 +4,10 @@

use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use PHPStan\ShouldNotHappenException;
use ReturnTypeWillChange;
use function array_map;
use function count;

class ExportedClassConstantNode implements ExportedNode, JsonSerializable
{
Expand Down Expand Up @@ -65,7 +68,7 @@ public static function decode(array $data): ExportedNode
$data['value'],
array_map(static function (array $parameterData): ExportedAttributeNode {
if ($parameterData['type'] !== ExportedAttributeNode::class) {
throw new \PHPStan\ShouldNotHappenException();
throw new ShouldNotHappenException();
}
return ExportedAttributeNode::decode($parameterData['data']);
}, $data['attributes']),
Expand Down
2 changes: 2 additions & 0 deletions src/Dependency/ExportedNode/ExportedParameterNode.php
Expand Up @@ -5,6 +5,8 @@
use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use ReturnTypeWillChange;
use function array_map;
use function count;

class ExportedParameterNode implements ExportedNode, JsonSerializable
{
Expand Down
3 changes: 2 additions & 1 deletion src/Dependency/ExportedNode/ExportedPropertiesNode.php
Expand Up @@ -5,6 +5,7 @@
use JsonSerializable;
use PHPStan\Dependency\ExportedNode;
use ReturnTypeWillChange;
use function array_map;
use function count;

class ExportedPropertiesNode implements JsonSerializable, ExportedNode
Expand Down Expand Up @@ -87,7 +88,7 @@ public static function __set_state(array $properties): ExportedNode
$properties['private'],
$properties['static'],
$properties['readonly'],
$properties['attributes']
$properties['attributes'],
);
}

Expand Down
78 changes: 39 additions & 39 deletions src/Dependency/ExportedNodeResolver.php
Expand Up @@ -97,8 +97,8 @@ public function resolve(string $fileName, Node $node): ?ExportedNode
throw new ShouldNotHappenException();
}, $adaptations),
$this->exportClassStatements($node->stmts, $fileName, $className),
$this->exportAttributeNodes($node->attrGroups),
);
$this->exportAttributeNodes($node->attrGroups),
);
}

if ($node instanceof Node\Stmt\Interface_ && isset($node->namespacedName)) {
Expand Down Expand Up @@ -141,8 +141,8 @@ public function resolve(string $fileName, Node $node): ?ExportedNode
),
$implementsNames,
$this->exportClassStatements($node->stmts, $fileName, $enumName),
$this->exportAttributeNodes($node->attrGroups),
);
$this->exportAttributeNodes($node->attrGroups),
);
}

if ($node instanceof Node\Stmt\Trait_ && isset($node->namespacedName)) {
Expand All @@ -168,8 +168,8 @@ public function resolve(string $fileName, Node $node): ?ExportedNode
$node->byRef,
$this->printType($node->returnType),
$this->exportParameterNodes($node->params),
$this->exportAttributeNodes($node->attrGroups),
);
$this->exportAttributeNodes($node->attrGroups),
);
}

return null;
Expand Down Expand Up @@ -248,8 +248,8 @@ private function exportParameterNodes(array $params): array
$param->byRef,
$param->variadic,
$param->default !== null,
$this->exportAttributeNodes($param->attrGroups),
);
$this->exportAttributeNodes($param->attrGroups),
);
}

return $nodes;
Expand Down Expand Up @@ -324,7 +324,7 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
$node->isStatic(),
$this->printType($node->returnType),
$this->exportParameterNodes($node->params),
$this->exportAttributeNodes($node->attrGroups),
$this->exportAttributeNodes($node->attrGroups),
);
}
}
Expand All @@ -349,7 +349,7 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
$node->isPrivate(),
$node->isStatic(),
$node->isReadonly(),
$this->exportAttributeNodes($node->attrGroups),
$this->exportAttributeNodes($node->attrGroups),
);
}

Expand All @@ -365,8 +365,8 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
$constants[] = new ExportedClassConstantNode(
$const->name->toString(),
$this->exprPrinter->printExpr($const->value),
$this->exportAttributeNodes($node->attrGroups),
);
$this->exportAttributeNodes($node->attrGroups),
);
}

return new ExportedClassConstantsNode(
Expand Down Expand Up @@ -401,32 +401,32 @@ private function exportClassStatement(Node\Stmt $node, string $fileName, string
return null;
}

/**
* @param Node\AttributeGroup[] $attributeGroups
* @return ExportedAttributeNode[]
*/
private function exportAttributeNodes(array $attributeGroups): array
{
$nodes = [];
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,
);
}

$nodes[] = new ExportedAttributeNode(
$attribute->name->toString(),
$args,
);
}
}

return $nodes;
}
/**
* @param Node\AttributeGroup[] $attributeGroups
* @return ExportedAttributeNode[]
*/
private function exportAttributeNodes(array $attributeGroups): array
{
$nodes = [];
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,
);
}

$nodes[] = new ExportedAttributeNode(
$attribute->name->toString(),
$args,
);
}
}

return $nodes;
}

}

0 comments on commit fb19080

Please sign in to comment.