Skip to content

Commit

Permalink
a lot of phpcs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Nov 27, 2023
1 parent f686a01 commit 580ea0f
Show file tree
Hide file tree
Showing 339 changed files with 22,832 additions and 16,152 deletions.
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
</rule>

<!--
Expand Down
71 changes: 37 additions & 34 deletions src/AliasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace Zephir;

use function count;
use function in_array;

/**
* Manage aliases in a file
*/
Expand All @@ -34,18 +37,6 @@ public function add(array $useStatement): void
}
}

/**
* Checks if a class name is an existing alias.
*
* @param string $alias
*
* @return bool
*/
public function isAlias(string $alias): bool
{
return isset($this->aliases[$alias]);
}

/**
* Returns the class name according to an existing alias.
*
Expand All @@ -58,16 +49,6 @@ public function getAlias(string $alias): string
return $this->aliases[$alias];
}

/**
* Returns key-value pair of aliases.
*
* @return array
*/
public function getAliases(): array
{
return $this->aliases;
}

/**
* Returns alias by fully qualified class name.
*
Expand All @@ -79,29 +60,33 @@ public function getAliasForClassName(string $className): string
{
$keys = array_keys($this->aliases, trim($className, '\\'));

if (1 === \count($keys)) {
if (1 === count($keys)) {
return $keys[0];
}

return $className;
}

/**
* Check if class name use an aliasing in use statement.
* Returns key-value pair of aliases.
*
* ex: use Events\ManagerInterface as EventsManagerInterface;
* @return array
*/
public function getAliases(): array
{
return $this->aliases;
}

/**
* Checks if a class name is an existing alias.
*
* @param string $alias
*
* @return bool
*/
public function isUseStatementAliased(string $alias): bool
public function isAlias(string $alias): bool
{
if ($this->isAlias($alias)) {
return $alias !== $this->implicitAlias($this->getAlias($alias));
}

return false;
return isset($this->aliases[$alias]);
}

/**
Expand All @@ -115,12 +100,30 @@ public function isAliasPresentFor(string $className): bool
{
$extractAlias = $this->implicitAlias($className);

$isClassDeclared = \in_array($className, $this->aliases);
$classAlias = array_flip($this->aliases)[$className] ?? null;
$isClassDeclared = in_array($className, $this->aliases);
$classAlias = array_flip($this->aliases)[$className] ?? null;

return $isClassDeclared && $classAlias !== $extractAlias;
}

/**
* Check if class name use an aliasing in use statement.
*
* ex: use Events\ManagerInterface as EventsManagerInterface;
*
* @param string $alias
*
* @return bool
*/
public function isUseStatementAliased(string $alias): bool
{
if ($this->isAlias($alias)) {
return $alias !== $this->implicitAlias($this->getAlias($alias));
}

return false;
}

/**
* Extract implicit alias from use statement.
*
Expand All @@ -132,6 +135,6 @@ private function implicitAlias(string $className): string
{
$parts = explode('\\', $className);

return $parts[\count($parts) - 1];
return $parts[count($parts) - 1];
}
}
Loading

0 comments on commit 580ea0f

Please sign in to comment.