Skip to content

Commit

Permalink
minor cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Mar 28, 2019
1 parent 4fd39d3 commit 85385a0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Generator/ResolveInterfaces.php
Expand Up @@ -46,7 +46,7 @@ protected function compute(Registry $registry, Entity $entity)
}

$target = $relation->getTarget();
if ($registry->hasRole($target)) {
if ($registry->hasEntity($target)) {
// no need to resolve
continue;
}
Expand Down
34 changes: 17 additions & 17 deletions src/Registry.php
Expand Up @@ -61,7 +61,7 @@ public function register(Entity $entity): Registry
* @param string $role Entity role of class.
* @return bool
*/
public function hasRole(string $role): bool
public function hasEntity(string $role): bool
{
foreach ($this->entities as $entity) {
if ($entity->getRole() === $role || $entity->getClass() === $role) {
Expand All @@ -72,15 +72,6 @@ public function hasRole(string $role): bool
return false;
}

/**
* @param Entity $entity
* @return bool
*/
public function hasEntity(Entity $entity): bool
{
return array_search($entity, $this->entities, true) !== false;
}

/**
* Get entity by it's role.
*
Expand Down Expand Up @@ -118,7 +109,7 @@ public function getIterator()
*/
public function registerChild(Entity $parent, Entity $child)
{
if (!$this->hasEntity($parent)) {
if (!$this->hasInstance($parent)) {
throw new RegistryException("Undefined entity `{$parent->getRole()}`");
}

Expand All @@ -138,7 +129,7 @@ public function registerChild(Entity $parent, Entity $child)
*/
public function getChildren(Entity $entity): array
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

Expand All @@ -158,7 +149,7 @@ public function getChildren(Entity $entity): array
*/
public function linkTable(Entity $entity, ?string $database, string $table): Registry
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

Expand All @@ -179,7 +170,7 @@ public function linkTable(Entity $entity, ?string $database, string $table): Reg
*/
public function hasTable(Entity $entity): bool
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

Expand Down Expand Up @@ -243,7 +234,7 @@ public function getTableSchema(Entity $entity): AbstractTable
*/
public function registerRelation(Entity $entity, string $name, RelationInterface $relation)
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

Expand All @@ -261,7 +252,7 @@ public function registerRelation(Entity $entity, string $name, RelationInterface
*/
public function hasRelation(Entity $entity, string $name): bool
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

Expand Down Expand Up @@ -290,10 +281,19 @@ public function getRelation(Entity $entity, string $name): RelationInterface
*/
public function getRelations(Entity $entity): array
{
if (!$this->hasEntity($entity)) {
if (!$this->hasInstance($entity)) {
throw new RegistryException("Undefined entity `{$entity->getRole()}`");
}

return $this->relations[$entity];
}

/**
* @param Entity $entity
* @return bool
*/
protected function hasInstance(Entity $entity): bool
{
return array_search($entity, $this->entities, true) !== false;
}
}
2 changes: 1 addition & 1 deletion src/Relation/RelationSchema.php
Expand Up @@ -71,7 +71,7 @@ public function compute(Registry $registry)
'source:primaryKey' => $this->getPrimary($registry->getEntity($this->source))
]);

if ($registry->hasRole($this->target)) {
if ($registry->hasEntity($this->target)) {
$this->options = $this->options->withContext([
'target:primaryKey' => $this->getPrimary($registry->getEntity($this->target))
]);
Expand Down
9 changes: 4 additions & 5 deletions tests/Schema/RegistryTest.php
Expand Up @@ -27,12 +27,11 @@ public function testHasRole()

$r->register($e);

$this->assertTrue($r->hasEntity($e));
$this->assertTrue($r->hasRole('user'));
$this->assertTrue($r->hasRole(User::class));
$this->assertTrue($r->hasEntity('user'));
$this->assertTrue($r->hasEntity(User::class));

$this->assertFalse($r->hasRole('post'));
$this->assertFalse($r->hasRole(Post::class));
$this->assertFalse($r->hasEntity('post'));
$this->assertFalse($r->hasEntity(Post::class));
}

public function testGetEntity()
Expand Down

0 comments on commit 85385a0

Please sign in to comment.