Skip to content

Commit

Permalink
removing unreachable statements
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Nov 30, 2023
1 parent a69f5e4 commit 0968d2d
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 259 deletions.
24 changes: 12 additions & 12 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ public function jsonSerialize(): array
/**
* Allows to check whether a $key is defined.
*
* @param mixed $key
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($key): bool
public function offsetExists($offset): bool

Check notice on line 261 in src/Config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing parameter's type declaration

Missing parameter's type declaration
{
return isset($this->container[$key]) || array_key_exists($key, $this->container);
return isset($this->container[$offset]) || array_key_exists($offset, $this->container);
}

/**
Expand Down Expand Up @@ -294,40 +294,40 @@ public function offsetGet($offset)
/**
* Sets a configuration value.
*
* @param mixed $key
* @param mixed $offset
* @param mixed $value
*/
#[ReturnTypeWillChange]
public function offsetSet($key, $value): void
public function offsetSet($offset, $value): void

Check notice on line 301 in src/Config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing parameter's type declaration

Missing parameter's type declaration

Check notice on line 301 in src/Config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing parameter's type declaration

Missing parameter's type declaration
{
if (!is_array($key)) {
if (!is_array($offset)) {
$this->container[$key] = $value;

return;
}

$namespace = key($key);
$key = current($key);
$namespace = key($offset);
$offset = current($offset);

if (!array_key_exists($namespace, $this->container)) {
$this->container[$namespace] = [];
}

$this->container[$namespace][$key] = $value;
$this->container[$namespace][$offset] = $value;
}

/**
* Unsets a $key from internal container.
*
* @param mixed $key
* @param mixed $offset
*
* @deprecated
*
*/
#[ReturnTypeWillChange]
public function offsetUnset($key): void
public function offsetUnset($offset): void

Check notice on line 328 in src/Config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing parameter's type declaration

Missing parameter's type declaration
{
unset($this->container[$key]);
unset($this->container[$offset]);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Exception/CompilerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class CompilerException extends RuntimeException
* @param int $code the Exception code [optional]
* @param Exception|Throwable $previous the previous throwable used for the exception chaining [optional]

Check notice on line 32 in src/Exception/CompilerException.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

PHPDoc comment matches function/method signature

Argument type does not match the declared
*/
public function __construct(string $message = '', $extra = null, $code = 0, $previous = null)
public function __construct(
string $message = '',
?array $extra = null,
int $code = 0,
Exception | Throwable $previous = null)
{
if (is_array($extra) && isset($extra['file'])) {
$message .= ' in ' . $extra['file'] . ' on line ' . $extra['line'];
Expand Down Expand Up @@ -129,7 +133,7 @@ public static function illegalOperationTypeOnStaticVariable(
array $statement
): self {
return new self(
"Operator '{$operator}' isn't supported for static variables and {$dataType} typed expressions",
"Operator '$operator' isn't supported for static variables and $dataType typed expressions",
$statement
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ interface ExceptionInterface
*
* @return string
*/
public function getErrorRegion();
public function getErrorRegion(): string;

/**
* Gets extra info.
*
* @return array
* @return array|null
*/
public function getExtra();
public function getExtra(): array | null;
}
8 changes: 6 additions & 2 deletions src/Exception/ParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class ParseException extends RuntimeException
* @param int $code the Exception code [optional]
* @param Exception|Throwable $previous the previous throwable used for the exception chaining [optional]

Check notice on line 32 in src/Exception/ParseException.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

PHPDoc comment matches function/method signature

Argument type does not match the declared
*/
public function __construct($message = '', $extra = null, $code = 0, $previous = null)
{
public function __construct(
string $message = '',
?array $extra = null,
int $code = 0,
Exception | Throwable $previous = null
) {
if (is_array($extra) && isset($extra['file'])) {
$message .= ' in ' . $extra['file'] . ' on line ' . $extra['line'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operators/AbstractOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getExpected(CompilationContext $compilationContext, array $expre
* @param CompilationContext $compilationContext
* @param string $type
*
* @return Variable
* @return Variable|null
*/
public function getExpectedComplexLiteral(
CompilationContext $compilationContext,
Expand Down
40 changes: 18 additions & 22 deletions src/Operators/Arithmetical/ArithmeticalBaseOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,13 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;

default:
throw new CompilerException(
"Cannot operate 'int' with '" . $right->getType() . "'",
$expression
);
}
break;

case 'bool':
switch ($right->getType()) {
Expand Down Expand Up @@ -178,7 +176,6 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;

case 'double':
switch ($right->getType()) {
Expand Down Expand Up @@ -254,22 +251,22 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate 'double' with '" . $right->getType() . "'",
$expression
);
}
break;


case 'string':
switch ($right->getType()) {
default:
throw new CompilerException('Operation is not supported between strings', $expression);
}
break;


case 'variable':
$variableLeft = $compilationContext->symbolTable->getVariableForRead(
Expand Down Expand Up @@ -342,15 +339,15 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate variable('int') with '" . $right->getType() . "'",
$expression
);
}
break;


case 'char':
switch ($right->getType()) {
Expand Down Expand Up @@ -403,15 +400,15 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate variable('char') with '" . $right->getType() . "'",
$expression
);
}
break;


case 'bool':
switch ($right->getType()) {
Expand Down Expand Up @@ -481,15 +478,15 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate variable('int') with '" . $right->getType() . "'",
$expression
);
}
break;


case 'double':
switch ($right->getType()) {
Expand Down Expand Up @@ -571,15 +568,15 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate variable('int') with '" . $right->getType() . "'",
$expression
);
}
break;


case 'string':
throw new CompilerException("Cannot operate string variables'", $expression);
Expand Down Expand Up @@ -627,9 +624,8 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;
}
break;


case 'variable':
switch ($right->getType()) {
Expand Down Expand Up @@ -657,7 +653,7 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


/* a(var) + a(x) */
case 'variable':
Expand Down Expand Up @@ -686,7 +682,7 @@ public function compile($expression, CompilationContext $compilationContext)
),
$expression
);
break;


/* a(var) + a(bool) */
case 'bool':
Expand All @@ -699,7 +695,7 @@ public function compile($expression, CompilationContext $compilationContext)
) . ')',
$expression
);
break;


/* a(var) + a(var) */
case 'variable':
Expand Down Expand Up @@ -735,20 +731,20 @@ public function compile($expression, CompilationContext $compilationContext)
$expression
);
}
break;


default:
throw new CompilerException(
"Cannot operate 'variable' with '" . $right->getType() . "'",
$expression
);
}
break;


default:
throw new CompilerException("Unknown '" . $variableLeft->getType() . "'", $expression);
}
break;


default:
throw new CompilerException('Unsupported type: ' . $left->getType(), $expression);
Expand Down
Loading

0 comments on commit 0968d2d

Please sign in to comment.