Skip to content
Permalink
Browse files

Add warnings about uninitialised properties to mixed as well

  • Loading branch information...
muglug committed Aug 11, 2019
1 parent e32b92b commit 7c6b1581d3f08a916362a94ab1b6ae68d76a6c52
@@ -1053,7 +1053,7 @@ Emitted when a property is defined on a class without a type

```php
class A {
public $foo;
public $foo = 5;
}
```

@@ -678,17 +678,16 @@ public function analyze(
if ($property_storage->type) {
$property_type = clone $property_storage->type;
if (!$property_type->isMixed() &&
!$property_storage->has_default &&
!($property_type->isNullable() && $property_type->from_docblock)
) {
$property_type->initialized = false;
}
} else {
$property_type = Type::getMixed();
}
if (!$property_storage->has_default
&& !($property_type->isNullable() && $property_type->from_docblock)
) {
$property_type->initialized = false;
}
$property_type_location = $property_storage->type_location;
$fleshed_out_type = !$property_type->isMixed()
@@ -1048,13 +1047,11 @@ private function checkPropertyInitialization(
continue;
}
if ($property->has_default || !$property->type || $property_is_initialized) {
if ($property->has_default || $property_is_initialized) {
continue;
}
if ($property->type->isMixed()
|| ($property->type->isNullable() && $property->type->from_docblock)
) {
if ($property->type && $property->type->isNullable() && $property->type->from_docblock) {
continue;
}
@@ -158,7 +158,7 @@ class A {
/**
* @var mixed
*/
public $foo;
public $foo = "hello";
/** @return void */
public function barBar()
@@ -176,7 +176,7 @@ public function barBar()
'propertyWithoutTypeSuppressingIssue' => [
'<?php
class A {
public $foo;
public $foo = "hello";
}
$a = (new A)->foo;',
@@ -937,7 +937,7 @@ class A {
/**
* @var mixed
*/
private $mixed;
private $mixed = "hello";
/**
* @param mixed $value
@@ -1718,7 +1718,7 @@ public function fooFoo(): void {
'missingPropertyType' => [
'<?php
class A {
public $foo;
public $foo = null;
public function assignToFoo(): void {
$this->foo = 5;
@@ -2407,6 +2407,19 @@ public function __construct() {
}',
'error_message' => 'UninitializedProperty',
],
'unitializedPropertyWithoutType' => [
'<?php
class A {
public $foo;
public function __construct() {
echo strlen($this->foo);
$this->foo = "foo";
}
}',
'error_message' => 'UninitializedProperty',
['MixedArgument', 'MissingPropertyType']
],
'unitializedObjectProperty' => [
'<?php
class Foo {
@@ -906,7 +906,7 @@ class B {
'missingPropertyType' => [
'<?php
trait T {
public $foo;
public $foo = null;
}
class A {
use T;
@@ -987,7 +987,7 @@ public function fooFoo(string $a): void {
'missingTraitPropertyType' => [
'<?php
trait T {
public $foo;
public $foo = 5;
}
class A {
@@ -1306,7 +1306,7 @@ public function iffer() : bool {
class A {
/** @var mixed */
public $_array_value;
public $_array_value = null;
private function getArrayValue() : ?array {
return rand(0, 1) ? [] : null;

0 comments on commit 7c6b158

Please sign in to comment.
You can’t perform that action at this time.