Skip to content

Commit

Permalink
#2407 - Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 28, 2023
1 parent 1752478 commit 7c3d630
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
19 changes: 9 additions & 10 deletions Library/Backend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Zephir\Variable\Globals;
use Zephir\Variable\Variable;

use function in_array;
use function Zephir\add_slashes;

class Backend
Expand Down Expand Up @@ -116,8 +115,8 @@ public function initVar(Variable $variable, CompilationContext $context, $useCod
public function getVariableCode(Variable $variable): string
{
if ($variable->isDoublePointer()
|| in_array($variable->getName(), ['this_ptr', 'return_value'])
|| in_array($variable->getType(), ['int', 'long'])) {
|| \in_array($variable->getName(), ['this_ptr', 'return_value'])
|| \in_array($variable->getType(), ['int', 'long'])) {
return $variable->getName();
}

Expand Down Expand Up @@ -337,7 +336,7 @@ public function onPostCompile(Method $method, CompilationContext $context): void

public function generateInitCode(&$groupVariables, $type, $pointer, Variable $variable)
{
$isComplex = in_array($type, ['variable', 'string', 'array', 'resource', 'callable', 'object', 'mixed'], true);
$isComplex = \in_array($type, ['variable', 'string', 'array', 'resource', 'callable', 'object', 'mixed'], true);

if ($isComplex && !$variable->isDoublePointer()) {
$groupVariables[] = $variable->getName();
Expand Down Expand Up @@ -640,7 +639,7 @@ public function addArrayEntry(Variable $variable, $key, $value, CompilationConte
$var = $context->symbolTable->getVariableForRead($key->getCode(), $context);
$typeKey = $var->getType();
}
if (in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) {
if (\in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) {
$keyType = 'index';
}
}
Expand Down Expand Up @@ -765,16 +764,16 @@ public function arrayIssetFetch2(Variable $target, Variable $var, $resolvedExpr,
if (!($resolvedExpr instanceof Variable)) {
if ('string' === $resolvedExpr->getType()) {
return new CompiledExpression('bool', 'zephir_array_isset_string_fetch('.$code.', SS("'.$resolvedExpr->getCode().'"), '.$flags.')', $expression);
} elseif (in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) {
} elseif (\in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) {
return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$resolvedExpr->getCode().', '.$flags.')', $expression);
} else {
$resolvedExpr = $context->symbolTable->getVariableForRead($resolvedExpr->getCode(), $context);
}
}

if (in_array($resolvedExpr->getType(), ['int', 'long'])) {
if (\in_array($resolvedExpr->getType(), ['int', 'long'])) {
return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression);
} elseif (in_array($resolvedExpr->getType(), ['variable', 'mixed', 'string'])) {
} elseif (\in_array($resolvedExpr->getType(), ['variable', 'mixed', 'string'])) {
return new CompiledExpression('bool', 'zephir_array_isset_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression);
}

Expand Down Expand Up @@ -983,7 +982,7 @@ public function resolveValue($value, CompilationContext $context): Variable | bo
$value = $this->getVariableCode($tempVariable);
} else {
if ($value instanceof CompiledExpression) {
if (in_array($value->getType(), ['array', 'variable', 'mixed'])) {
if (\in_array($value->getType(), ['array', 'variable', 'mixed'])) {
$value = $context->symbolTable->getVariableForWrite($value->getCode(), $context);
} else {
return $value->getCode();
Expand Down Expand Up @@ -1414,7 +1413,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA
$arrayAccess['right']
);
}
if ($isVariable && in_array($index->getType(), ['variable', 'string', 'mixed'])) {
if ($isVariable && \in_array($index->getType(), ['variable', 'string', 'mixed'])) {
$output = 'zephir_array_fetch('.$this->getVariableCode($var).', '.$this->getVariableCode($src).', '.$this->getVariableCode($index).', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
} else {
if ($isVariable) {
Expand Down
2 changes: 1 addition & 1 deletion Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public function applyClassHeaders(CompilationContext $compilationContext)

$separators = str_repeat('../', \count(explode('\\', $classDefinition->getCompleteName())) - 1);

$code = PHP_EOL;
$code = PHP_EOL;
$code .= '#ifdef HAVE_CONFIG_H'.PHP_EOL;
$code .= '#include "'.$separators.'ext_config.h"'.PHP_EOL;
$code .= '#endif'.PHP_EOL;
Expand Down
6 changes: 3 additions & 3 deletions Library/Passes/LocalContextPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public function declareVariables(array $statement): void
foreach ($statement['variables'] as $variable) {
if (isset($variable['expr'])) {
if (
'string' === $variable['expr']['type'] ||
'empty-array' === $variable['expr']['type'] ||
'array' === $variable['expr']['type']
'string' === $variable['expr']['type']
|| 'empty-array' === $variable['expr']['type']
|| 'array' === $variable['expr']['type']
) {
$this->variables[$variable['variable']] = false;
continue;
Expand Down
4 changes: 1 addition & 3 deletions Library/Passes/SkipVariantInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

use Zephir\StatementsBlock;

use function count;

/**
* In 'if'/'else' statements sometimes dynamical variables are initialized in every branch
* Same case in 'switch' statements
Expand Down Expand Up @@ -95,7 +93,7 @@ public function getVariables(): array
}

$variables = [];
$numberBranches = count($this->branches);
$numberBranches = \count($this->branches);
foreach ($variableStats as $variable => $number) {
if ($number == $numberBranches) {
$variables[] = $variable;
Expand Down

0 comments on commit 7c3d630

Please sign in to comment.