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

Allow the use of property docblocks without all docblocks

This commit is contained in:
Matthew Brown 2018-01-13 00:32:20 -05:00
parent 5d9ebd06d6
commit d61829adde
3 changed files with 18 additions and 15 deletions

View File

@ -15,11 +15,11 @@
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="stopOnFirstError" type="xs:string" />
<xs:attribute name="useDocblockTypes" type="xs:string" />
<xs:attribute name="useDocblockPropertyTypes" type="xs:string" />
<xs:attribute name="throwExceptionOnError" type="xs:string" />
<xs:attribute name="hideExternalErrors" type="xs:string" />
<xs:attribute name="autoloader" type="xs:string" />
<xs:attribute name="cacheDirectory" type="xs:string" />
<xs:attribute name="usePropertyDefaultForType" type="xs:string" />
<xs:attribute name="allowFileIncludes" type="xs:string" />
<xs:attribute name="totallyTyped" type="xs:string" />
<xs:attribute name="strictBinaryOperands" type="xs:string" />

View File

@ -63,6 +63,15 @@ class Config
*/
public $use_docblock_types = true;
/**
* Whether or not to use types as defined in property docblocks.
* This is distinct from the above because you may want to use
* property docblocks, but not function docblocks.
*
* @var bool
*/
public $use_docblock_property_types = true;
/**
* Whether or not to throw an exception on first error
*
@ -266,6 +275,11 @@ class Config
$config->use_docblock_types = $attribute_text === 'true' || $attribute_text === '1';
}
if (isset($config_xml['useDocblockPropertyTypes'])) {
$attribute_text = (string) $config_xml['useDocblockPropertyTypes'];
$config->use_docblock_property_types = $attribute_text === 'true' || $attribute_text === '1';
}
if (isset($config_xml['throwExceptionOnError'])) {
$attribute_text = (string) $config_xml['throwExceptionOnError'];
$config->throw_exception = $attribute_text === 'true' || $attribute_text === '1';
@ -291,11 +305,6 @@ class Config
exit(255);
}
if (isset($config_xml['usePropertyDefaultForType'])) {
$attribute_text = (string) $config_xml['usePropertyDefaultForType'];
$config->use_property_default_for_type = $attribute_text === 'true' || $attribute_text === '1';
}
if (isset($config_xml['allowFileIncludes'])) {
$attribute_text = (string) $config_xml['allowFileIncludes'];
$config->allow_includes = $attribute_text === 'true' || $attribute_text === '1';

View File

@ -1147,7 +1147,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
$property_is_initialized = false;
if ($comment && $comment->getText() && $config->use_docblock_types) {
if ($comment && $comment->getText() && ($config->use_docblock_types || $config->use_docblock_property_types)) {
if (preg_match('/[ \t\*]+@psalm-suppress[ \t]+PropertyNotSetInConstructor/', (string)$comment)) {
$property_is_initialized = true;
}
@ -1196,15 +1196,9 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
if (!$property_group_type) {
if ($property->default) {
$default_type = StatementsChecker::getSimpleType($property->default);
if (!$config->use_property_default_for_type) {
$property_type = false;
} else {
$property_type = $default_type ?: Type::getMixed();
}
} else {
$property_type = false;
}
$property_type = false;
} else {
if ($var_comment && $var_comment->line_number) {
$property_type_location = new CodeLocation(