Skip to content

Commit

Permalink
Merge pull request #51 from magento-commerce/revert-49-add-enum
Browse files Browse the repository at this point in the history
Revert "Add enum to visitor"
  • Loading branch information
andimov committed Nov 21, 2023
2 parents 7f240cf + 2f0654c commit f3d2f95
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 98 deletions.
54 changes: 0 additions & 54 deletions dev/tests/Unit/ClassHierarchy/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,21 +479,6 @@ public function testIsTrait(string $type, bool $expected)
);
}

/**
* @dataProvider dataProviderIsEnum
* @param string $type
* @param bool $expected
*/
public function testIsEnum(string $type, bool $expected)
{
$entity = new Entity('myName', $type);

$this->assertEquals(
$expected,
$entity->isEnum()
);
}

/*
* Data providers
*/
Expand All @@ -518,10 +503,6 @@ public function dataProviderIsClass()
Entity::TYPE_TRAIT,
false,
],
'entity-is-enum-returns-false' => [
Entity::TYPE_ENUM,
false,
],
];
}

Expand All @@ -545,10 +526,6 @@ public function dataProviderIsInterface()
Entity::TYPE_TRAIT,
false,
],
'entity-is-enum-returns-false' => [
Entity::TYPE_ENUM,
false,
],
];
}

Expand All @@ -572,37 +549,6 @@ public function dataProviderIsTrait()
Entity::TYPE_TRAIT,
true,
],
'entity-is-enum-returns-false' => [
Entity::TYPE_ENUM,
false,
],
];
}

/**
* Provides test data for {@link EntityTest::testIsEnum()}
*
* @return array
*/
public function dataProviderIsEnum()
{
return [
'entity-is-class-returns-false' => [
Entity::TYPE_CLASS,
false,
],
'entity-is-interface-returns-false' => [
Entity::TYPE_INTERFACE,
false,
],
'entity-is-trait-returns-false' => [
Entity::TYPE_TRAIT,
false,
],
'entity-is-enum-returns-true' => [
Entity::TYPE_ENUM,
true,
],
];
}

Expand Down
16 changes: 0 additions & 16 deletions src/ClassHierarchy/DependencyGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,4 @@ public function findOrCreateTrait(string $fullyQualifiedName): Entity

return $trait;
}

/**
* @param string $fullyQualifiedName
* @return Entity
*/
public function findOrCreateEnum(string $fullyQualifiedName): Entity
{
$enum = $this->findEntityByName($fullyQualifiedName);

if (!$enum) {
$enum = $this->entityFactory->createEnum($fullyQualifiedName);
$this->addEntity($enum);
}

return $enum;
}
}
10 changes: 3 additions & 7 deletions src/ClassHierarchy/DependencyInspectionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Magento\SemanticVersionChecker\Helper\Node as NodeHelper;
use PhpParser\Node;
use PhpParser\Node\Stmt\Enum_ as EnumNode;
use PhpParser\Node\Stmt\Class_ as ClassNode;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -23,7 +22,7 @@
use PhpParser\NodeVisitorAbstract;

/**
* Implements a visitor for `class`, `interface`, `trait` and `enum` nodes that generates a dependency graph.
* Implements a visitor for `class`, `interface` and `trait` nodes that generates a dependency graph.
*/
class DependencyInspectionVisitor extends NodeVisitorAbstract
{
Expand Down Expand Up @@ -95,8 +94,8 @@ public function enterNode(Node $node)
}

/**
* Handles Class, Interface, Traits and Enum nodes. Sets currentClassLike entity and will populate extends,
* implements, and API information
* Handles Class, Interface, and Traits nodes. Sets currentClassLike entity and will populate extends, implements,
* and API information
*
* @param ClassLike $node
* @return int|null
Expand Down Expand Up @@ -136,9 +135,6 @@ private function handleClassLike(ClassLike $node)
case $node instanceof TraitNode:
$this->currentClassLike = $this->dependencyGraph->findOrCreateTrait((string)$namespacedName);
break;
case $node instanceof EnumNode:
$this->currentClassLike = $this->dependencyGraph->findOrCreateEnum((string)$namespacedName);
break;
}
$this->currentClassLike->setIsApi($this->nodeHelper->isApiNode($node));
return null;
Expand Down
13 changes: 1 addition & 12 deletions src/ClassHierarchy/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PhpParser\Node\Stmt\PropertyProperty;

/**
* Implements an entity that reflects a `class`, `interface`, `enum` or `trait` and its dependencies.
* Implements an entity that reflects a `class`, `interface` or `trait` and its dependencies.
*/
class Entity
{
Expand All @@ -24,7 +24,6 @@ class Entity
public const TYPE_CLASS = 'class';
public const TYPE_INTERFACE = 'interface';
public const TYPE_TRAIT = 'trait';
public const TYPE_ENUM = 'enum';
/**#@-*/

/**
Expand Down Expand Up @@ -328,16 +327,6 @@ public function isTrait(): bool
return $this->type === self::TYPE_TRAIT;
}

/**
* Reflects whether current entity reflects an `enum`.
*
* @return bool
*/
public function isEnum(): bool
{
return $this->type === self::TYPE_ENUM;
}

/*
* Private methods
*/
Expand Down
9 changes: 0 additions & 9 deletions src/ClassHierarchy/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,4 @@ public function createTrait(string $name): Entity
{
return new Entity($name, Entity::TYPE_TRAIT);
}

/**
* @param string $name
* @return Entity
*/
public function createEnum(string $name): Entity
{
return new Entity($name, Entity::TYPE_ENUM);
}
}

0 comments on commit f3d2f95

Please sign in to comment.