Skip to content

Commit

Permalink
Remove redundant 'array' type check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Jan 28, 2025
1 parent c3cbbb6 commit 5e6ac44
Showing 1 changed file with 59 additions and 62 deletions.
121 changes: 59 additions & 62 deletions src/Class/Definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,68 +496,62 @@ public function compile(CompilationContext $compilationContext): void
/**
* Implemented interfaces.
*/
$interfaces = $this->interfaces;
$compiler = $compilationContext->compiler;

if (is_array($interfaces)) {
$codePrinter->outputBlankLine(true);

foreach ($interfaces as $interface) {
/**
* Try to find the interface.
*/
$classEntry = null;

if ($compiler->isInterface($interface)) {
$classInterfaceDefinition = $compiler->getClassDefinition($interface);
$classEntry = $classInterfaceDefinition->getClassEntry($compilationContext);
} elseif ($compiler->isBundledInterface($interface)) {
$classInterfaceDefinition = $compiler->getInternalClassDefinition($interface);
$classEntry = (new Entry(
'\\' . $classInterfaceDefinition->getName(),
$compilationContext
))->get();
}

if (!$classEntry) {
if ($compiler->isClass($interface)) {
throw new CompilerException(
sprintf(
'Cannot locate interface %s when implementing interfaces on %s. ' .
'%s is currently a class',
$interface,
$this->getCompleteName(),
$interface
),
$this->originalNode
);
} else {
throw new CompilerException(
sprintf(
'Cannot locate interface %s when implementing interfaces on %s',
$interface,
$this->getCompleteName()
),
$this->originalNode
);
}
}
$codePrinter->outputBlankLine(true);
foreach ($this->interfaces as $interface) {
/**
* Try to find the interface.
*/
$classEntry = null;

if ($compilationContext->compiler->isInterface($interface)) {
$classInterfaceDefinition = $compilationContext->compiler->getClassDefinition($interface);
$classEntry = $classInterfaceDefinition->getClassEntry($compilationContext);
} elseif ($compilationContext->compiler->isBundledInterface($interface)) {
$classInterfaceDefinition = $compilationContext->compiler->getInternalClassDefinition($interface);
$classEntry = (new Entry(
'\\' . $classInterfaceDefinition->getName(),
$compilationContext
))->get();
}

/**
* We don't check if abstract classes implement the methods in their interfaces
*/
if (!$this->isAbstract() && !$this->isInterface()) {
$this->checkInterfaceImplements($this, $classInterfaceDefinition);
if (!$classEntry) {
if ($compilationContext->compiler->isClass($interface)) {
throw new CompilerException(
sprintf(
'Cannot locate interface %s when implementing interfaces on %s. ' .
'%s is currently a class',
$interface,
$this->getCompleteName(),
$interface
),
$this->originalNode
);
} else {
throw new CompilerException(
sprintf(
'Cannot locate interface %s when implementing interfaces on %s',
$interface,
$this->getCompleteName()
),
$this->originalNode
);
}
}

$codePrinter->output(
sprintf(
'zend_class_implements(%s, 1, %s);',
$this->getClassEntry(),
$classEntry
)
);
/**
* We don't check if abstract classes implement the methods in their interfaces
*/
if (!$this->isAbstract() && !$this->isInterface()) {
$this->checkInterfaceImplements($this, $classInterfaceDefinition);
}

$codePrinter->output(
sprintf(
'zend_class_implements(%s, 1, %s);',
$this->getClassEntry(),
$classEntry
)
);
}

if (!$this->isAbstract() && !$this->isInterface()) {
Expand All @@ -568,10 +562,13 @@ public function compile(CompilationContext $compilationContext): void
$interfaces = $classExtendsDefinition->getImplementedInterfaces();
foreach ($interfaces as $interface) {
$classInterfaceDefinition = null;
if ($compiler->isInterface($interface)) {
$classInterfaceDefinition = $compiler->getClassDefinition($interface);
} elseif ($compiler->isBundledInterface($interface)) {
$classInterfaceDefinition = $compiler->getInternalClassDefinition($interface);
if ($compilationContext->compiler->isInterface($interface)) {
$classInterfaceDefinition = $compilationContext->compiler->getClassDefinition($interface);
} elseif ($compilationContext->compiler->isBundledInterface($interface)) {
$classInterfaceDefinition = $compilationContext
->compiler
->getInternalClassDefinition($interface)
;
}

if ($classInterfaceDefinition !== null) {
Expand Down

0 comments on commit 5e6ac44

Please sign in to comment.