Skip to content

Commit

Permalink
#2407 - Reformat code with PHP8.0 syntax sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Aug 28, 2023
1 parent e051dc9 commit 8c4045b
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 91 deletions.
8 changes: 0 additions & 8 deletions Library/Cache/MethodCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use ReflectionException;
use Zephir\ClassDefinition;
use Zephir\CompilationContext;
use Zephir\MethodCallWarmUp;
use Zephir\Passes\CallGathererPass;
use Zephir\Variable;

Expand Down Expand Up @@ -148,13 +147,6 @@ public function get(CompilationContext $compilationContext, string $methodName,
$cacheable = false;
}

// Recursive methods require warm-up
if ($compilationContext->currentMethod == $method) {
if (!$compilationContext->methodWarmUp) {
$compilationContext->methodWarmUp = new MethodCallWarmUp();
}
}

if ('this_ptr' != $caller->getName()) {
$associatedClass = $caller->getAssociatedClass();
if ($this->isClassCacheable($associatedClass)) {
Expand Down
2 changes: 0 additions & 2 deletions Library/Classes/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Zephir\Classes;

use ReflectionClass;
use ReflectionException;
use Zephir\ClassDefinition;
use Zephir\CompilationContext;
use Zephir\Exception;
Expand Down Expand Up @@ -75,7 +74,6 @@ public function __construct(string $className, CompilationContext $compilationCo
* @return string
*
* @throws Exception
* @throws ReflectionException
*/
public function get(): string
{
Expand Down
2 changes: 1 addition & 1 deletion Library/Code/Builder/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __toString(): string
*
* @throws InvalidArgumentException
*/
public function addProperty(string $field, array $global)
public function addProperty(string $field, array $global): void
{
if (!isset($global['type']) || !is_string($global['type'])) {
throw new InvalidArgumentException('Property type must be string');
Expand Down
2 changes: 0 additions & 2 deletions Library/Compiler/FileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Zephir\Compiler;

/**
* FileInterface.
*
* Provides a common interface for compiler files
*/
interface FileInterface
Expand Down
3 changes: 0 additions & 3 deletions Library/EventsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

namespace Zephir;

/**
* Class EventsManager.
*/
class EventsManager
{
/**
Expand Down
9 changes: 1 addition & 8 deletions Library/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,10 @@ class Expression
protected bool $expecting = true;
protected bool $readOnly = false;
protected bool $evalMode = false;
protected array $expression = [];
protected ?Variable $expectingVariable = null;

/**
* Expression constructor.
*
* @param array $expression
*/
public function __construct(array $expression)
public function __construct(protected array $expression)
{
$this->expression = $expression;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Library/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getReflector($funcName)
*
* @return bool
*/
public function isBuiltInFunction($functionName)
public function isBuiltInFunction(string $functionName)
{
switch ($functionName) {
case 'memstr':
Expand Down
12 changes: 2 additions & 10 deletions Library/FunctionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@
namespace Zephir;

/**
* FunctionDefinition.
*
* Represents a function
*/
class FunctionDefinition extends ClassMethod
{
/**
* The namespace of the function.
*/
private string $namespace;

/**
* Whether the function is declared in a global or namespaced scope.
*
Expand All @@ -35,22 +28,21 @@ class FunctionDefinition extends ClassMethod
/**
* FunctionDefinition constructor.
*
* @param string $namespace
* @param string $namespace The namespace of the function.
* @param string $name
* @param ClassMethodParameters|null $parameters
* @param StatementsBlock|null $statements
* @param array|null $returnType
* @param array|null $expression
*/
public function __construct(
string $namespace,
private string $namespace,
string $name,
ClassMethodParameters $parameters = null,
StatementsBlock $statements = null,
array $returnType = null,
array $expression = null
) {
$this->namespace = $namespace;
$this->name = $name;
$this->parameters = $parameters;
$this->statements = $statements;
Expand Down
16 changes: 4 additions & 12 deletions Library/GlobalConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,23 @@
namespace Zephir;

/**
* GlobalConstant.
* Creates a new global constant.
*
* Global constants are allocated one time at extension initialization
* and are referenced across the C code saving memory
*/
class GlobalConstant
{
protected $name;

/**
* Creates a new global constant.
*
* @param string $name
*/
public function __construct($name)
public function __construct(protected string $name)
{
$this->name = $name;
}

/**
* Returns global constant name.
*
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}
Expand All @@ -46,7 +38,7 @@ public function getName()
*
* @return bool
*/
public function isTemporal()
public function isTemporal(): bool
{
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions Library/HeadersManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Zephir;

/**
* Class HeadersManager.
*
* Manages the c-headers that must be added to a file
*/
class HeadersManager
Expand Down
2 changes: 0 additions & 2 deletions Library/MethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use Zephir\Exception\CompilerException;

/**
* MethodCall.
*
* Call methods in a non-static context
*/
class MethodCall extends Call
Expand Down
27 changes: 3 additions & 24 deletions Library/SymbolTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Zephir\Variable\Globals;

/**
* Zephir\SymbolTable.
*
* A symbol table stores all the variables defined in a method, their data types and default values.
*/
class SymbolTable
Expand All @@ -37,22 +35,12 @@ class SymbolTable
*/
protected $localContext;

/**
* @var CompilationContext
*/
protected $compilationContext;

/**
* @var Globals
*/
protected $globalsManager;

/**
* SymbolTable.
*
* @param CompilationContext $compilationContext
*/
public function __construct(CompilationContext $compilationContext)
public function __construct(protected CompilationContext $compilationContext)
{
$this->globalsManager = new Globals();

Expand Down Expand Up @@ -85,7 +73,7 @@ public function resolveVariableToBranch($name, CompilationContext $compilationCo

do {
$currentId = $currentBranch->getUniqueId();
if (isset($this->branchVariables[$currentId]) && isset($this->branchVariables[$currentId][$name])) {
if (isset($this->branchVariables[$currentId][$name])) {
return $currentBranch;
}
$currentBranch = $currentBranch->getParentBranch();
Expand Down Expand Up @@ -222,7 +210,7 @@ public function getVariable($name, CompilationContext $compilationContext = null
public function getVariables()
{
$ret = [];
foreach ($this->branchVariables as $branchId => $vars) {
foreach ($this->branchVariables as $vars) {
foreach ($vars as $var) {
$ret[$var->getName()] = $var;
}
Expand All @@ -231,15 +219,6 @@ public function getVariables()
return $ret;
}

public function getVariablesByBranch($branchId)
{
if (isset($this->branchVariables[$branchId])) {
return $this->branchVariables[$branchId];
}

return null;
}

/**
* Return a variable in the symbol table, it will be used for a read operation.
*
Expand Down
17 changes: 1 addition & 16 deletions Library/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ class Variable implements TypeAwareInterface
*/
protected $name;

/**
* Branch where the variable was declared.
*
* @var Branch|null
*/
protected $branch;

/**
* Branch where the variable was initialized for the first time.
*/
Expand Down Expand Up @@ -164,14 +157,7 @@ class Variable implements TypeAwareInterface
'object' => 1,
];

/**
* Variable constructor.
*
* @param string $type
* @param string $name
* @param Branch $branch
*/
public function __construct(string $type, string $name, Branch $branch = null)
public function __construct(string $type, string $name, protected ?Branch $branch = null)
{
$this->globalsManager = new Globals();

Expand All @@ -181,7 +167,6 @@ public function __construct(string $type, string $name, Branch $branch = null)

$this->type = $type;
$this->name = $name;
$this->branch = $branch;
}

/**
Expand Down

0 comments on commit 8c4045b

Please sign in to comment.