1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Remove some unused return values

This commit is contained in:
Matt Brown 2021-06-10 12:09:46 -04:00
parent e5a7478b38
commit 8509999f3f
11 changed files with 45 additions and 77 deletions

View File

@ -115,12 +115,12 @@ class ClassAnalyzer extends ClassLikeAnalyzer
}
/**
* @return null|false
* @return void
*/
public function analyze(
?Context $class_context = null,
?Context $global_context = null
): ?bool {
): void {
$class = $this->class;
if (!$class instanceof PhpParser\Node\Stmt\Class_ && !$class instanceof PhpParser\Node\Stmt\Enum_) {
@ -132,7 +132,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$storage = $this->storage;
if ($storage->has_visitor_issues) {
return null;
return;
}
if ($class->name
@ -160,7 +160,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
// fall through
}
return null;
return;
}
$project_analyzer = $this->file_analyzer->project_analyzer;
@ -332,11 +332,11 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$fq_class_name,
$storage
) === false) {
return false;
return;
}
if ($storage->invalid_dependencies) {
return null;
return;
}
if ($this->leftover_stmts) {
@ -370,7 +370,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
),
$storage->suppressed_issues + $this->getSuppressedIssues()
)) {
return false;
return;
}
}
}
@ -421,7 +421,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$global_context,
$constructor_analyzer
) === false) {
return false;
return;
}
} elseif ($stmt instanceof PhpParser\Node\Stmt\Property) {
foreach ($stmt->props as $prop) {
@ -620,7 +620,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
);
if ($codebase->config->eventDispatcher->dispatchAfterClassLikeAnalysis($event) === false) {
return false;
return;
}
$file_manipulations = $event->getFileReplacements();
if ($file_manipulations) {
@ -629,8 +629,6 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$file_manipulations
);
}
return null;
}
public static function addContextProperties(

View File

@ -251,19 +251,18 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
/**
* Check that __clone, __construct, and __destruct do not have a return type
* hint in their signature.
*
* @return false|null
*/
public static function checkMethodSignatureMustOmitReturnType(
MethodStorage $method_storage,
CodeLocation $code_location
): ?bool {
): void {
if ($method_storage->signature_return_type === null) {
return null;
return;
}
$cased_method_name = $method_storage->cased_name;
$methodsOfInterest = ['__clone', '__construct', '__destruct'];
if (in_array($cased_method_name, $methodsOfInterest)) {
if (IssueBuffer::accepts(
new MethodSignatureMustOmitReturnType(
@ -271,11 +270,9 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
$code_location
)
)) {
return false;
// fall through
}
}
return null;
}
public function getMethodId(?string $context_self = null): \Psalm\Internal\MethodIdentifier

View File

@ -21,20 +21,18 @@ use function in_array;
*/
class SwitchAnalyzer
{
/**
* @return false|null
*/
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Stmt\Switch_ $stmt,
Context $context
): ?bool {
): void {
$codebase = $statements_analyzer->getCodebase();
$context->inside_conditional = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->cond, $context) === false) {
return false;
return;
}
$context->inside_conditional = false;
$switch_var_id = ExpressionIdentifier::getArrayVarId(
@ -132,7 +130,7 @@ class SwitchAnalyzer
$switch_scope
) === false
) {
return false;
return;
}
}
@ -225,7 +223,5 @@ class SwitchAnalyzer
//a switch can't return in all options without a default
$context->has_returned = $all_options_returned && $has_default;
return null;
}
}

View File

@ -12,14 +12,11 @@ use Psalm\Type;
class ContinueAnalyzer
{
/**
* @return false|null
*/
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Stmt\Continue_ $stmt,
Context $context
): ?bool {
): void {
$count = $stmt->num
&& $stmt->num instanceof PhpParser\Node\Scalar\LNumber
? $stmt->num->value
@ -44,7 +41,7 @@ class ContinueAnalyzer
),
$statements_analyzer->getSource()->getSuppressedIssues()
)) {
return false;
return;
}
}
} else {
@ -105,7 +102,5 @@ class ContinueAnalyzer
}
$context->has_returned = true;
return null;
}
}

View File

@ -38,14 +38,11 @@ class IssetAnalyzer
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr $stmt,
Context $context
) : bool {
) : void {
$context->inside_isset = true;
$result = ExpressionAnalyzer::analyze($statements_analyzer, $stmt, $context);
ExpressionAnalyzer::analyze($statements_analyzer, $stmt, $context);
$context->inside_isset = false;
return $result;
}
}

View File

@ -42,14 +42,11 @@ use function strtolower;
*/
class ReturnAnalyzer
{
/**
* @return false|null
*/
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Stmt\Return_ $stmt,
Context $context
): ?bool {
): void {
$doc_comment = $stmt->getDocComment();
$var_comments = [];
@ -145,7 +142,7 @@ class ReturnAnalyzer
}
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
return false;
return;
}
$stmt_expr_type = $statements_analyzer->node_data->getType($stmt->expr);
@ -284,7 +281,7 @@ class ReturnAnalyzer
}
if ($local_return_type->isGenerator() && $storage->has_yield) {
return null;
return;
}
if ($stmt_type->hasMixed()) {
@ -296,7 +293,7 @@ class ReturnAnalyzer
),
$statements_analyzer->getSuppressedIssues()
)) {
return false;
return;
}
}
@ -339,7 +336,7 @@ class ReturnAnalyzer
// fall through
}
return null;
return;
}
if (IssueBuffer::accepts(
@ -354,7 +351,7 @@ class ReturnAnalyzer
}
if ($local_return_type->isMixed()) {
return null;
return;
}
if (!$context->collect_initializations
@ -373,10 +370,10 @@ class ReturnAnalyzer
),
$statements_analyzer->getSuppressedIssues()
)) {
return false;
return;
}
return null;
return;
}
$union_comparison_results = new \Psalm\Internal\Type\Comparator\TypeComparisonResult();
@ -446,7 +443,7 @@ class ReturnAnalyzer
new ClassLikeNameOptions(true)
) === false
) {
return false;
return;
}
} elseif ($local_type_part instanceof Type\Atomic\TArray
&& $stmt->expr instanceof PhpParser\Node\Expr\Array_
@ -467,7 +464,7 @@ class ReturnAnalyzer
new ClassLikeNameOptions(true)
) === false
) {
return false;
return;
}
}
}
@ -544,8 +541,6 @@ class ReturnAnalyzer
}
}
}
return null;
}
private static function handleTaints(

View File

@ -16,14 +16,11 @@ use function is_string;
class StaticAnalyzer
{
/**
* @return false|null
*/
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Stmt\Static_ $stmt,
Context $context
): ?bool {
): void {
$codebase = $statements_analyzer->getCodebase();
if ($context->mutation_free) {
@ -148,7 +145,7 @@ class StaticAnalyzer
if ($var->default) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $var->default, $context) === false) {
return false;
return;
}
if ($comment_type
@ -186,7 +183,5 @@ class StaticAnalyzer
);
}
}
return null;
}
}

View File

@ -36,12 +36,10 @@ class TextDocument
* Diagnostics notification are sent from the server to the client to signal results of validation runs.
*
* @param Diagnostic[] $diagnostics
*
* @return Promise<void>
*/
public function publishDiagnostics(string $uri, array $diagnostics): Promise
public function publishDiagnostics(string $uri, array $diagnostics): void
{
return $this->handler->notify('textDocument/publishDiagnostics', [
$this->handler->notify('textDocument/publishDiagnostics', [
'uri' => $uri,
'diagnostics' => $diagnostics,
]);

View File

@ -46,7 +46,7 @@ interface EmitterInterface
string $eventName,
array $arguments = [],
?callable $continueCallBack = null
) : bool;
) : void;
/**
* Returns the list of listeners for an event.

View File

@ -71,13 +71,13 @@ trait EmitterTrait
string $eventName,
array $arguments = [],
?callable $continueCallBack = null
) : bool {
): void {
if ($continueCallBack === null) {
foreach ($this->listeners($eventName) as $listener) {
/** @psalm-suppress MixedAssignment */
$result = \call_user_func_array($listener, $arguments);
if ($result === false) {
return false;
return;
}
}
} else {
@ -89,7 +89,7 @@ trait EmitterTrait
/** @psalm-suppress MixedAssignment */
$result = \call_user_func_array($listener, $arguments);
if ($result === false) {
return false;
return;
}
if ($counter > 0) {
@ -99,8 +99,6 @@ trait EmitterTrait
}
}
}
return true;
}
/**

View File

@ -395,10 +395,8 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* The shutdown request is sent from the client to the server. It asks the server to shut down,
* but to not exit (otherwise the response might not be delivered correctly to the client).
* There is a separate exit notification that asks the server to exit.
*
* @psalm-return Promise<null>
*/
public function shutdown(): Promise
public function shutdown(): void
{
$this->clientStatus('closing');
$this->verboseLog("Shutting down...");
@ -409,7 +407,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$scanned_files
);
$this->clientStatus('closed');
return new Success(null);
new Success(null);
}
/**
@ -433,19 +431,20 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* - 3 = Info
* - 4 = Log
*/
private function verboseLog(string $message, int $type = 4): Promise
private function verboseLog(string $message, int $type = 4): void
{
if ($this->project_analyzer->language_server_verbose) {
try {
return $this->client->logMessage(
$this->client->logMessage(
'[Psalm ' .PSALM_VERSION. ' - PHP Language Server] ' . $message,
$type
);
return;
} catch (\Throwable $err) {
// do nothing
}
}
return new Success(null);
new Success(null);
}
/**