Skip to content

Commit

Permalink
#2407 - Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Sep 10, 2023
1 parent 1dfb4d5 commit bd7c643
Show file tree
Hide file tree
Showing 210 changed files with 959 additions and 1,128 deletions.
4 changes: 1 addition & 3 deletions Library/AliasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Zephir;

use function in_array;

/**
* Manage aliases in a file
*/
Expand Down Expand Up @@ -117,7 +115,7 @@ public function isAliasPresentFor(string $className): bool
{
$extractAlias = $this->implicitAlias($className);

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

return $isClassDeclared && $classAlias !== $extractAlias;
Expand Down
79 changes: 36 additions & 43 deletions Library/Backend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
use Zephir\GlobalConstant;
use Zephir\Variable\Globals;
use Zephir\Variable\Variable;
use function in_array;
use function strlen;

use function Zephir\add_slashes;

class Backend
Expand Down Expand Up @@ -121,9 +120,9 @@ 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'])) {
if ($variable->isDoublePointer()
|| \in_array($variable->getName(), ['this_ptr', 'return_value'])
|| \in_array($variable->getType(), ['int', 'long'])) {
return $variable->getName();
}

Expand Down Expand Up @@ -243,13 +242,13 @@ public function getTypeDefinition($type): array
}

/**
* @param Variable $variableVariable
* @param string $operator
* @param string $value
*
* @throws CompilerException
* @param Variable $variableVariable
* @param string $operator
* @param string $value
*
* @return string
*
* @throws CompilerException
*/
public function getTypeofCondition(
Variable $variableVariable,
Expand Down Expand Up @@ -309,7 +308,7 @@ public function getTypeofCondition(
public function onPreInitVar(Method $method): string
{
if (!$method instanceof FunctionDefinition && !$method->isInternal()) {
return "zval *this_ptr = getThis();\n"; //TODO: think about a better way to solve this.
return "zval *this_ptr = getThis();\n"; // TODO: think about a better way to solve this.
}

return '';
Expand Down Expand Up @@ -343,7 +342,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 @@ -397,9 +396,9 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va
break;

case 'char':
$defaultValue = (string)$defaultValue;
if (strlen($defaultValue) > 4) {
if (strlen($defaultValue) > 10) {
$defaultValue = (string) $defaultValue;
if (\strlen($defaultValue) > 4) {
if (\strlen($defaultValue) > 10) {
throw new CompilerException("Invalid char literal: '".substr($defaultValue, 0, 10)."...'", $variable->getOriginal());
} else {
throw new CompilerException("Invalid char literal: '".$defaultValue."'", $variable->getOriginal());
Expand Down Expand Up @@ -428,9 +427,9 @@ public function generateInitCode(&$groupVariables, $type, $pointer, Variable $va
* @param Variable[] $variables
* @param CompilationContext $context
*
* @throws CompilerException
*
* @return string
*
* @throws CompilerException
*/
public function initializeVariableDefaults(array $variables, CompilationContext $context): string
{
Expand Down Expand Up @@ -504,7 +503,7 @@ public function declareConstant($type, $name, $value, CompilationContext $contex
}

/**
* @param Method $method
* @param Method $method
* @param CompilationContext $context
*
* @return string
Expand Down Expand Up @@ -646,7 +645,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 @@ -771,16 +770,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 @@ -920,11 +919,12 @@ public function fetchProperty(
}

/**
* @param Variable $symbolVariable
* @param Definition $classDefinition
* @param $property
* @param bool $readOnly
* @param Variable $symbolVariable
* @param Definition $classDefinition
* @param $property
* @param bool $readOnly
* @param CompilationContext $context
*
* @throws Exception
*/
public function fetchStaticProperty(Variable $symbolVariable, $classDefinition, $property, $readOnly, CompilationContext $context): void
Expand All @@ -943,14 +943,14 @@ public function fetchStaticProperty(Variable $symbolVariable, $classDefinition,
}

/**
* @param $value
* @param $value
* @param CompilationContext $context
*
* @throws CompilerException
*
* @return bool|string|Variable
*
* @throws CompilerException
*/
public function resolveValue($value, CompilationContext $context): Variable|bool|string
public function resolveValue($value, CompilationContext $context): Variable | bool | string
{
if ($value instanceof GlobalConstant) {
switch ($value->getName()) {
Expand Down Expand Up @@ -988,7 +988,7 @@ public function resolveValue($value, CompilationContext $context): Variable|bool
$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 @@ -1313,7 +1313,7 @@ public function getScalarTempVariable(
*
* @return void
*/
public function initArray(Variable $variable, CompilationContext $context, ?int $size = null): void
public function initArray(Variable $variable, CompilationContext $context, int $size = null): void
{
$code = $this->getVariableCode($variable);

Expand Down Expand Up @@ -1406,7 +1406,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA
$type = 'long';
break;

/* Types which map to the same */
/* Types which map to the same */
case 'variable':
case 'mixed':
case 'string':
Expand All @@ -1419,7 +1419,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 Expand Up @@ -1630,19 +1630,11 @@ public function checkStrictType($type, $var, CompilationContext $context)

/**
* Assign value to variable helper.
*
* @param string $macro
* @param string $variableName
* @param string|Variable|null $value
* @param CompilationContext $context
* @param bool $useCodePrinter
*
* @return string
*/
protected function assignHelper(
string $macro,
string $variableName,
$value,
$value,
CompilationContext $context,
bool $useCodePrinter
): string {
Expand Down Expand Up @@ -1696,6 +1688,7 @@ protected function returnHelper(string $macro, $value, CompilationContext $conte
* @param CompilationContext $compilationContext
*
* @return array
*
* @throws CompilerException
*/
private function resolveOffsetExprs(array $offsetExprs, CompilationContext $compilationContext): array
Expand Down
7 changes: 4 additions & 3 deletions Library/Backend/FcallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Zephir\Backend;

use Zephir\Code\Printer;

use function Zephir\file_put_contents_ex;

class FcallManager implements FcallManagerInterface
Expand All @@ -24,8 +25,8 @@ class FcallManager implements FcallManagerInterface
* {@inheritdoc}
*
* @param bool $static
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
*
* @return string
*/
Expand Down Expand Up @@ -133,7 +134,7 @@ public function genFcallCode(): void
sprintf(
'method(0, execute_data, %s, %s%s%s); \\',
$retParam,
($scope ? 'NULL, ' : $objParam),
$scope ? 'NULL, ' : $objParam,
$retValueUsed,
$i ? ', &'.implode(', &', $zvals) : ''
)
Expand Down
4 changes: 2 additions & 2 deletions Library/Backend/FcallManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface FcallManagerInterface
* Resolve internal fcall attributes to a suitable macro and ensure that it's generated during compilation.
*
* @param bool $static
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
*
* @return string
*/
Expand Down
3 changes: 1 addition & 2 deletions Library/Backend/StringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Zephir\StringsManager as BaseStringsManager;

use function strlen;
use function Zephir\file_put_contents_ex;

/**
Expand Down Expand Up @@ -61,7 +60,7 @@ public function genConcatCode(): void
$macros = [];
ksort($this->concatKeys, SORT_STRING);
foreach ($this->concatKeys as $key => $one) {
$len = strlen($key);
$len = \strlen($key);
$params = [];
$zvalCopy = [];
$useCopy = [];
Expand Down
5 changes: 3 additions & 2 deletions Library/Backend/VariablesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Zephir\Exception\CompilerException as Exception;
use Zephir\Types\Types;
use Zephir\Variable\Variable;

use function Zephir\Backend\ZendEngine3\add_slashes;

class VariablesManager
Expand Down Expand Up @@ -174,9 +175,9 @@ private function initArrayVar(Variable $variable, array $value, Context $context
*
* @param array $value
*
* @throws Exception
*
* @return void
*
* @throws Exception
*/
private function validateCharValue(array $value): void
{
Expand Down
2 changes: 1 addition & 1 deletion Library/Builder/Operators/CastOperatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CastOperatorBuilder extends AbstractOperatorBuilder
public function __construct(
string $left,
FunctionCallBuilder $right,
?string $file = null,
string $file = null,
int $line = 0,
int $char = 0
) {
Expand Down
6 changes: 2 additions & 4 deletions Library/Builder/Operators/UnaryOperatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Zephir\Builder\Operators;

use function is_object;

/**
* Allows to manually build a unary operator AST node
*/
Expand All @@ -34,7 +32,7 @@ class UnaryOperatorBuilder extends AbstractOperatorBuilder
*/
protected $leftExpression;

public function __construct(string $operator, $leftExpression, ?string $file = null, int $line = 0, int $char = 0)
public function __construct(string $operator, $leftExpression, string $file = null, int $line = 0, int $char = 0)
{
$this->operator = $operator;
$this->leftExpression = $leftExpression;
Expand All @@ -50,7 +48,7 @@ public function __construct(string $operator, $leftExpression, ?string $file = n
*/
public function get(): array
{
if (is_object($this->leftExpression) && method_exists($this->leftExpression, 'get')) {
if (\is_object($this->leftExpression) && method_exists($this->leftExpression, 'get')) {
$expr = $this->leftExpression->get();
} else {
$expr = $this->leftExpression;
Expand Down
2 changes: 1 addition & 1 deletion Library/Cache/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Manager
*
* @param CallGathererPass|null $gatherer
*/
public function setGatherer(?CallGathererPass $gatherer = null): void
public function setGatherer(CallGathererPass $gatherer = null): void
{
$this->gatherer = $gatherer;
}
Expand Down
Loading

0 comments on commit bd7c643

Please sign in to comment.