Skip to content

add failing tests #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function testRule(): void
'Access to an uninitialized readonly property MissingReadOnlyPropertyAssign\AssignOp::$bar.',
87,
],
[
'Readonly property MissingReadOnlyPropertyAssign\DoubleAssign::$foo is already assigned.',
128,
],
[
'Class MissingReadOnlyPropertyAssign\Foo has an maybe uninitialized readonly property $foo.',
139,
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,42 @@ public function __construct(int $foo)
}

}

class ValidDoubleAssign
{
private readonly int $foo;

public function __construct(int $foo)
{
if (rand(0, 1)) {
$this->foo = $foo;
} else {
$this->foo = 0;
}
}
}

class DoubleAssign
{
private readonly int $foo;

public function __construct(int $foo)
{
if (rand(0, 1)) {
$this->foo = $foo;
}
$this->foo = 0;
}
}

class MaybeUninitialized
{
private readonly int $foo;

public function __construct(int $foo)
{
if (rand(0, 1)) {
$this->foo = $foo;
}
}
}