Skip to content

Commit

Permalink
sonarlint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Nov 27, 2023
1 parent 331b62c commit 9a9adbd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/Class/Method/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -1841,16 +1841,19 @@ public function compile(CompilationContext $compilationContext): void
*/
$lastType = $this->statements->getLastStatementType();

if ('return' !== $lastType && 'throw' !== $lastType && !$this->hasChildReturnStatementType($statement)) {
/**
* If a method has return-type hints we need to ensure the last statement is a 'return' statement
*/
if ($this->hasReturnTypes()) {
throw new CompilerException(
'Reached end of the method without returning a valid type specified in the return-type hints',
$this->expression['return-type']
);
}
/**
* If a method has return-type hints we need to ensure the last
* statement is a 'return' statement
*/
if (
'return' !== $lastType &&
'throw' !== $lastType && !$this->hasChildReturnStatementType($statement) &&
$this->hasReturnTypes()

Check warning on line 1851 in src/Class/Method/Method.php

View check run for this annotation

Codecov / codecov/patch

src/Class/Method/Method.php#L1849-L1851

Added lines #L1849 - L1851 were not covered by tests
) {
throw new CompilerException(
'Reached end of the method without returning a valid type specified in the return-type hints',
$this->expression['return-type']
);

Check warning on line 1856 in src/Class/Method/Method.php

View check run for this annotation

Codecov / codecov/patch

src/Class/Method/Method.php#L1853-L1856

Added lines #L1853 - L1856 were not covered by tests
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/Statements/ReturnStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Zephir\Statements;

use ReflectionException;
use Zephir\CompilationContext;
use Zephir\Exception;
use Zephir\Exception\CompilerException;
Expand All @@ -26,11 +27,13 @@
*/
final class ReturnStatement extends StatementAbstract
{
private const RETURN_RETURN = 'return;';

/**
* @param CompilationContext $compilationContext
*
* @throws Exception
* @throws \ReflectionException
* @throws ReflectionException
*/
public function compile(CompilationContext $compilationContext): void
{
Expand Down Expand Up @@ -222,7 +225,7 @@ public function compile(CompilationContext $compilationContext): void
if ('return_value' != $resolvedExpr->getCode()) {
$codePrinter->output('RETURN_CTOR('.$resolvedExpr->getCode().');');
} else {
$codePrinter->output('return;');
$codePrinter->output(self::RETURN_RETURN);

Check warning on line 228 in src/Statements/ReturnStatement.php

View check run for this annotation

Codecov / codecov/patch

src/Statements/ReturnStatement.php#L228

Added line #L228 was not covered by tests
}
break;

Expand Down Expand Up @@ -300,10 +303,10 @@ public function compile(CompilationContext $compilationContext): void
$compilationContext->backend->getVariableCode($symbolVariable)
)
);
$codePrinter->output('return;');
$codePrinter->output(self::RETURN_RETURN);

Check warning on line 306 in src/Statements/ReturnStatement.php

View check run for this annotation

Codecov / codecov/patch

src/Statements/ReturnStatement.php#L306

Added line #L306 was not covered by tests
}
} else {
$codePrinter->output('return;');
$codePrinter->output(self::RETURN_RETURN);

Check warning on line 309 in src/Statements/ReturnStatement.php

View check run for this annotation

Codecov / codecov/patch

src/Statements/ReturnStatement.php#L309

Added line #L309 was not covered by tests
}
}
if ($symbolVariable->isTemporal()) {
Expand Down

0 comments on commit 9a9adbd

Please sign in to comment.