mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Also detect non-inherited private constructors
This commit is contained in:
parent
c7b0f6685f
commit
67338c4bf5
@ -704,12 +704,14 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
$constructor_class_storage = self::$storage[strtolower($construct_fqcln)];
|
||||
}
|
||||
|
||||
if ((!$constructor_class_storage || !$constructor_class_storage->all_properties_set_in_constructor) &&
|
||||
!$property->has_default &&
|
||||
$property->type &&
|
||||
!$property->type->isMixed() &&
|
||||
!$property->type->isNullable() &&
|
||||
!$property->is_static
|
||||
if ((!$constructor_class_storage
|
||||
|| !$constructor_class_storage->all_properties_set_in_constructor
|
||||
|| $constructor_class_storage->methods['__construct']->visibility === self::VISIBILITY_PRIVATE)
|
||||
&& !$property->has_default
|
||||
&& $property->type
|
||||
&& !$property->type->isMixed()
|
||||
&& !$property->type->isNullable()
|
||||
&& !$property->is_static
|
||||
) {
|
||||
$uninitialized_variables[] = '$this->' . $property_name;
|
||||
$uninitialized_properties[$property_name] = $property;
|
||||
|
@ -669,6 +669,36 @@ class PropertyTypeTest extends TestCase
|
||||
class B extends A {}',
|
||||
'error_message' => 'MissingConstructor',
|
||||
],
|
||||
'abstractClassInheritsPrivateConstructor' => [
|
||||
'<?php
|
||||
abstract class A {
|
||||
/** @var string */
|
||||
public $foo;
|
||||
|
||||
private function __construct() {
|
||||
$this->foo = "hello";
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {}',
|
||||
'error_message' => 'InaccessibleMethod',
|
||||
],
|
||||
'classInheritsPrivateConstructorWithImplementedConstructor' => [
|
||||
'<?php
|
||||
abstract class A {
|
||||
/** @var string */
|
||||
public $foo;
|
||||
|
||||
private function __construct() {
|
||||
$this->foo = "hello";
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public function __construct() {}
|
||||
}',
|
||||
'error_message' => 'PropertyNotSetInConstructor',
|
||||
],
|
||||
'notSetInAllBranchesOfIf' => [
|
||||
'<?php
|
||||
class A {
|
||||
|
Loading…
x
Reference in New Issue
Block a user