Skip to content

Commit

Permalink
Simplify access to class reflections in InClassNode rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-briller authored and ondrejmirtes committed Jul 7, 2023
1 parent e8455a1 commit dabbd59
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 32 deletions.
5 changes: 1 addition & 4 deletions src/Rules/Classes/DuplicateDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
$classReflection = $scope->getClassReflection();
if ($classReflection === null) {
throw new ShouldNotHappenException();
}
$classReflection = $node->getClassReflection();

$errors = [];

Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Classes/MixinRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();
$mixinTags = $classReflection->getMixinTags();
$errors = [];
foreach ($mixinTags as $mixinTag) {
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/ClassAncestorsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function processNode(Node $node, Scope $scope): array
if (!$originalNode instanceof Node\Stmt\Class_) {
return [];
}
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();
if ($classReflection->isAnonymous()) {
return [];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/ClassTemplateTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();
if (!$classReflection->isClass()) {
return [];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/EnumAncestorsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function processNode(Node $node, Scope $scope): array
if (!$originalNode instanceof Node\Stmt\Enum_) {
return [];
}
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();

$enumName = $classReflection->getName();
$escapedEnumName = SprintfHelper::escapeFormatString($enumName);
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/EnumTemplateTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();
if (!$classReflection->isEnum()) {
return [];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/InterfaceAncestorsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public function processNode(Node $node, Scope $scope): array
if (!$originalNode instanceof Node\Stmt\Interface_) {
return [];
}
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();

$interfaceName = $classReflection->getName();
$escapedInterfaceName = SprintfHelper::escapeFormatString($interfaceName);
Expand Down
5 changes: 1 addition & 4 deletions src/Rules/Generics/InterfaceTemplateTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
return [];
}
$classReflection = $scope->getClassReflection();
$classReflection = $node->getClassReflection();
if (!$classReflection->isInterface()) {
return [];
}
Expand Down

0 comments on commit dabbd59

Please sign in to comment.