1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Check this properties for redundant conditions

This commit is contained in:
Matt Brown 2018-07-10 12:32:53 -04:00
parent ecf4ed65e3
commit 5bb5bb2476
3 changed files with 18 additions and 2 deletions

View File

@ -629,7 +629,6 @@ class ClassLikes
}
if ($classlike_storage->location
&& $this->config
&& $this->config->isInProjectDirs($classlike_storage->location->file_path)
&& !$classlike_storage->is_trait
) {

View File

@ -692,7 +692,7 @@ class Context
$stripped_var = preg_replace('/(->|\[).*$/', '', $var_name);
if ($stripped_var[0] === '$' && $stripped_var !== '$this') {
if ($stripped_var[0] === '$' && ($stripped_var !== '$this' || $var_name !== $stripped_var)) {
$this->referenced_var_ids[$var_name] = true;
if ($this->collect_references && $statements_checker) {

View File

@ -1494,6 +1494,23 @@ class PropertyTypeTest extends TestCase
if (is_string($a->foo)) {}',
'error_message' => 'DocblockTypeContradiction',
],
'impossiblePropertyCheck' => [
'<?php
class Bar {}
class Foo {
/** @var Bar */
private $bar;
public function __construct() {
$this->bar = new Bar();
}
public function getBar(): void {
if (!$this->bar) {}
}
}',
'error_message' => 'DocblockTypeContradiction',
],
];
}
}