mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Do not complain about missing void return types if config set
This commit is contained in:
parent
15e8c1b904
commit
7e7743d6fb
@ -22,6 +22,7 @@
|
||||
<xs:attribute name="allowFileIncludes" type="xs:string" />
|
||||
<xs:attribute name="totallyTyped" type="xs:string" />
|
||||
<xs:attribute name="strictBinaryOperands" type="xs:string" />
|
||||
<xs:attribute name="addVoidDocblockReturnType" type="xs:string" />
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ProjectFilesType">
|
||||
|
@ -824,7 +824,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
if ($this->function instanceof Closure) {
|
||||
if (IssueBuffer::accepts(
|
||||
new MissingClosureReturnType(
|
||||
'Closure does not have a return type',
|
||||
'Closure does not have a return type, expecting ' . $inferred_return_type,
|
||||
new CodeLocation($this, $this->function, true)
|
||||
),
|
||||
$this->suppressed_issues
|
||||
@ -837,7 +837,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new MissingReturnType(
|
||||
'Method ' . $cased_method_id . ' does not have a return type',
|
||||
'Method ' . $cased_method_id . ' does not have a return type, expecting ' . $inferred_return_type,
|
||||
new CodeLocation($this, $this->function, true)
|
||||
),
|
||||
$this->suppressed_issues
|
||||
@ -848,23 +848,6 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
return null;
|
||||
}
|
||||
|
||||
$inferred_yield_types = [];
|
||||
$inferred_return_types = EffectsAnalyser::getReturnTypes(
|
||||
$this->function->getStmts(),
|
||||
$inferred_yield_types,
|
||||
true
|
||||
);
|
||||
|
||||
$inferred_return_type = $inferred_return_types ? Type::combineTypes($inferred_return_types) : Type::getVoid();
|
||||
$inferred_yield_type = $inferred_yield_types ? Type::combineTypes($inferred_yield_types) : null;
|
||||
|
||||
$inferred_generator_return_type = null;
|
||||
|
||||
if ($inferred_yield_type) {
|
||||
$inferred_generator_return_type = $inferred_return_type;
|
||||
$inferred_return_type = $inferred_yield_type;
|
||||
}
|
||||
|
||||
if ($is_to_string) {
|
||||
if (!$inferred_return_type->isMixed() && (string)$inferred_return_type !== 'string') {
|
||||
if (IssueBuffer::accepts(
|
||||
@ -956,16 +939,6 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
return null;
|
||||
}
|
||||
|
||||
$inferred_return_type = TypeChecker::simplifyUnionType(
|
||||
ExpressionChecker::fleshOutTypes(
|
||||
$inferred_return_type,
|
||||
[],
|
||||
$this->source->getFQCLN(),
|
||||
''
|
||||
),
|
||||
$this->getFileChecker()
|
||||
);
|
||||
|
||||
$return_types_different = false;
|
||||
|
||||
if (!TypeChecker::isContainedBy($inferred_return_type, $declared_return_type, $this->getFileChecker())) {
|
||||
|
@ -141,6 +141,9 @@ class Config
|
||||
/** @var bool */
|
||||
public $strict_binary_operands = false;
|
||||
|
||||
/** @var bool */
|
||||
public $add_void_docblocks = true;
|
||||
|
||||
/**
|
||||
* Psalm plugins
|
||||
*
|
||||
@ -275,6 +278,11 @@ class Config
|
||||
$config->strict_binary_operands = $attribute_text === 'true' || $attribute_text === '1';
|
||||
}
|
||||
|
||||
if (isset($config_xml['addVoidDocblockReturnType'])) {
|
||||
$attribute_text = (string) $config_xml['addVoidDocblockReturnType'];
|
||||
$config->add_void_docblocks = $attribute_text === 'true' || $attribute_text === '1';
|
||||
}
|
||||
|
||||
if (isset($config_xml->projectFiles)) {
|
||||
$config->project_files = ProjectFileFilter::loadFromXMLElement($config_xml->projectFiles, $config, true);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class JsonOutputTest extends PHPUnit_Framework_TestCase
|
||||
$issue_data = IssueBuffer::getIssueData()[0];
|
||||
$this->assertSame('somefile.php', $issue_data['file_path']);
|
||||
$this->assertSame('error', $issue_data['type']);
|
||||
$this->assertSame('Method fooFoo does not have a return type', $issue_data['message']);
|
||||
$this->assertSame('Method fooFoo does not have a return type, expecting string', $issue_data['message']);
|
||||
$this->assertSame(2, $issue_data['line_number']);
|
||||
$this->assertSame(
|
||||
'function fooFoo() {',
|
||||
|
Loading…
x
Reference in New Issue
Block a user