Skip to content

Commit 7bdc668

Browse files
committed
Regression tests
Closes phpstan/phpstan#8958 Closes phpstan/phpstan#8563
1 parent 614c81e commit 7bdc668

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,22 @@ public function testBug8412(): void
138138
$this->analyse([__DIR__ . '/data/bug-8412.php'], []);
139139
}
140140

141+
public function testBug8958(): void
142+
{
143+
if (PHP_VERSION_ID < 80100) {
144+
$this->markTestSkipped('Test requires PHP 8.1.');
145+
}
146+
147+
$this->analyse([__DIR__ . '/data/bug-8958.php'], []);
148+
}
149+
150+
public function testBug8563(): void
151+
{
152+
if (PHP_VERSION_ID < 80100) {
153+
$this->markTestSkipped('Test requires PHP 8.1.');
154+
}
155+
156+
$this->analyse([__DIR__ . '/data/bug-8563.php'], []);
157+
}
158+
141159
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug8563;
4+
5+
class BankAccount {
6+
7+
readonly string $bic;
8+
readonly string $iban;
9+
readonly string $label;
10+
11+
function __construct(object $data = new \stdClass) {
12+
$this->bic = $data->bic ?? "";
13+
$this->iban = $data->iban ?? "";
14+
$this->label = $data->label ?? "";
15+
}
16+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug8958;
4+
5+
interface TimeRangeInterface
6+
{
7+
public function getStart(): \DateTimeInterface;
8+
9+
public function getEnd(): \DateTimeInterface;
10+
}
11+
12+
trait TimeRangeTrait
13+
{
14+
private readonly \DateTimeImmutable $start;
15+
16+
private readonly \DateTimeImmutable $end;
17+
18+
public function getStart(): \DateTimeImmutable
19+
{
20+
return $this->start; // @phpstan-ignore-line
21+
}
22+
23+
public function getEnd(): \DateTimeImmutable
24+
{
25+
return $this->end; // @phpstan-ignore-line
26+
}
27+
28+
private function initTimeRange(
29+
\DateTimeInterface $start,
30+
\DateTimeInterface $end
31+
): void {
32+
$this->start = \DateTimeImmutable::createFromInterface($start); // @phpstan-ignore-line
33+
$this->end = \DateTimeImmutable::createFromInterface($end); // @phpstan-ignore-line
34+
}
35+
}
36+
37+
class Foo implements TimeRangeInterface {
38+
use TimeRangeTrait;
39+
40+
public function __construct(\DateTimeInterface $start, \DateTimeInterface $end)
41+
{
42+
$this->initTimeRange($start, $end);
43+
}
44+
}
45+
46+
class Bar implements TimeRangeInterface {
47+
use TimeRangeTrait;
48+
49+
public function __construct(
50+
private TimeRangeInterface $first,
51+
private TimeRangeInterface $second,
52+
?\DateTimeInterface $start = null,
53+
\DateTimeInterface $end = null
54+
) {
55+
$this->initTimeRange(
56+
$start ?? max($first->getStart(), $second->getStart()),
57+
$end ?? min($first->getEnd(), $second->getEnd()),
58+
);
59+
}
60+
61+
public function getFirst(): TimeRangeInterface
62+
{
63+
return $this->first;
64+
}
65+
public function getSecond(): TimeRangeInterface
66+
{
67+
return $this->second;
68+
}
69+
}

0 commit comments

Comments
 (0)