mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Allow the use of property docblocks without all docblocks
This commit is contained in:
parent
5d9ebd06d6
commit
d61829adde
@ -15,11 +15,11 @@
|
|||||||
<xs:attribute name="name" type="xs:string" />
|
<xs:attribute name="name" type="xs:string" />
|
||||||
<xs:attribute name="stopOnFirstError" type="xs:string" />
|
<xs:attribute name="stopOnFirstError" type="xs:string" />
|
||||||
<xs:attribute name="useDocblockTypes" 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="throwExceptionOnError" type="xs:string" />
|
||||||
<xs:attribute name="hideExternalErrors" type="xs:string" />
|
<xs:attribute name="hideExternalErrors" type="xs:string" />
|
||||||
<xs:attribute name="autoloader" type="xs:string" />
|
<xs:attribute name="autoloader" type="xs:string" />
|
||||||
<xs:attribute name="cacheDirectory" 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="allowFileIncludes" type="xs:string" />
|
||||||
<xs:attribute name="totallyTyped" type="xs:string" />
|
<xs:attribute name="totallyTyped" type="xs:string" />
|
||||||
<xs:attribute name="strictBinaryOperands" type="xs:string" />
|
<xs:attribute name="strictBinaryOperands" type="xs:string" />
|
||||||
|
@ -63,6 +63,15 @@ class Config
|
|||||||
*/
|
*/
|
||||||
public $use_docblock_types = true;
|
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
|
* 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';
|
$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'])) {
|
if (isset($config_xml['throwExceptionOnError'])) {
|
||||||
$attribute_text = (string) $config_xml['throwExceptionOnError'];
|
$attribute_text = (string) $config_xml['throwExceptionOnError'];
|
||||||
$config->throw_exception = $attribute_text === 'true' || $attribute_text === '1';
|
$config->throw_exception = $attribute_text === 'true' || $attribute_text === '1';
|
||||||
@ -291,11 +305,6 @@ class Config
|
|||||||
exit(255);
|
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'])) {
|
if (isset($config_xml['allowFileIncludes'])) {
|
||||||
$attribute_text = (string) $config_xml['allowFileIncludes'];
|
$attribute_text = (string) $config_xml['allowFileIncludes'];
|
||||||
$config->allow_includes = $attribute_text === 'true' || $attribute_text === '1';
|
$config->allow_includes = $attribute_text === 'true' || $attribute_text === '1';
|
||||||
|
@ -1147,7 +1147,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
|||||||
|
|
||||||
$property_is_initialized = false;
|
$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)) {
|
if (preg_match('/[ \t\*]+@psalm-suppress[ \t]+PropertyNotSetInConstructor/', (string)$comment)) {
|
||||||
$property_is_initialized = true;
|
$property_is_initialized = true;
|
||||||
}
|
}
|
||||||
@ -1196,15 +1196,9 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
|
|||||||
if (!$property_group_type) {
|
if (!$property_group_type) {
|
||||||
if ($property->default) {
|
if ($property->default) {
|
||||||
$default_type = StatementsChecker::getSimpleType($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 {
|
} else {
|
||||||
if ($var_comment && $var_comment->line_number) {
|
if ($var_comment && $var_comment->line_number) {
|
||||||
$property_type_location = new CodeLocation(
|
$property_type_location = new CodeLocation(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user