Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Node/ClassPropertiesNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@
}
$originalProperties[$property->getName()] = $property;
$is = TrinaryLogic::createFromBoolean($property->isPromoted() && !$property->isPromotedFromTrait());
if (!$is->yes() && $classReflection->hasConstructor()) {

Check warning on line 135 in src/Node/ClassPropertiesNode.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } $originalProperties[$property->getName()] = $property; $is = TrinaryLogic::createFromBoolean($property->isPromoted() && !$property->isPromotedFromTrait()); - if (!$is->yes() && $classReflection->hasConstructor()) { + if ($is->no() && $classReflection->hasConstructor()) { $constructorDeclaringClass = $classReflection->getConstructor()->getDeclaringClass(); if ( $constructorDeclaringClass->getName() !== $classReflection->getName()

Check warning on line 135 in src/Node/ClassPropertiesNode.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } $originalProperties[$property->getName()] = $property; $is = TrinaryLogic::createFromBoolean($property->isPromoted() && !$property->isPromotedFromTrait()); - if (!$is->yes() && $classReflection->hasConstructor()) { + if ($is->no() && $classReflection->hasConstructor()) { $constructorDeclaringClass = $classReflection->getConstructor()->getDeclaringClass(); if ( $constructorDeclaringClass->getName() !== $classReflection->getName()
$constructorDeclaringClass = $classReflection->getConstructor()->getDeclaringClass();
if (
$constructorDeclaringClass->getName() !== $classReflection->getName()
&& $constructorDeclaringClass->hasNativeProperty($property->getName())
&& $constructorDeclaringClass->getNativeProperty($property->getName())->isPromoted()
) {
$is = TrinaryLogic::createYes();
}
}
if (!$is->yes() && $classReflection->hasNativeProperty($property->getName())) {
$propertyReflection = $classReflection->getNativeProperty($property->getName());
if ($propertyReflection->isVirtual()->yes()) {
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,14 @@ public function testBug12547(): void
$this->analyse([__DIR__ . '/data/bug-12547.php'], []);
}

public function testBug13380(): void
{
$this->analyse([__DIR__ . '/data/bug-13380.php'], [
[
'Class Bug13380\Baz has an uninitialized property $prop. Give it default value or assign it in the constructor.',
20,
],
]);
}

}
26 changes: 26 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-13380.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug13380;

class Foo
{
public function __construct(
protected string $prop,
){
}
}

class Bar extends Foo {
public string $prop;
}

class Baz extends Foo {
public string $prop;

public function __construct()
{
// Does not call parent::__construct, so $prop is uninitialized
}
}
Loading