Skip to content

Commit f057303

Browse files
Add test
1 parent 1865530 commit f057303

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

tests/PHPStan/Rules/PhpDoc/VarTagChangedExpressionTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function testBug10130(): void
7979
]);
8080
}
8181

82+
public function testBug14429(): void
83+
{
84+
$this->analyse([__DIR__ . '/data/bug-14429.php'], []);
85+
}
86+
8287
public function testBug12708(): void
8388
{
8489
$this->analyse([__DIR__ . '/data/bug-12708.php'], [
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Bug14429;
4+
5+
interface IEntity {
6+
/**
7+
* @return IRepository<IEntity>
8+
*/
9+
public function getRepository(): IRepository;
10+
}
11+
12+
interface IProperty {}
13+
14+
interface IPropertyContainer extends IProperty {}
15+
16+
/**
17+
* @template E of IEntity
18+
*/
19+
interface IEntityAwareProperty extends IProperty {}
20+
21+
/**
22+
* @template E of IEntity
23+
* @extends IEntityAwareProperty<E>
24+
*/
25+
interface IRelationshipContainer extends IPropertyContainer, IEntityAwareProperty {}
26+
27+
interface IModel {
28+
/**
29+
* @template E of IEntity
30+
* @template T of IRepository<E>
31+
* @param class-string<T> $className
32+
* @return T
33+
*/
34+
public function getRepository(string $className): IRepository;
35+
}
36+
37+
/**
38+
* @template E of IEntity
39+
*/
40+
interface IRepository {
41+
public function getModel(): IModel;
42+
}
43+
44+
class PropertyRelationshipMetadata {
45+
/** @var class-string<IRepository<IEntity>> */
46+
public string $repository;
47+
}
48+
49+
/**
50+
* @template E of IEntity
51+
* @implements IRelationshipContainer<E>
52+
*/
53+
class HasOne implements IRelationshipContainer
54+
{
55+
/** @var E|null */
56+
protected ?IEntity $parent = null;
57+
58+
/** @var IRepository<E>|null */
59+
protected ?IRepository $targetRepository = null;
60+
61+
protected PropertyRelationshipMetadata $metadataRelationship;
62+
63+
/**
64+
* @return E
65+
*/
66+
protected function getParentEntity(): IEntity
67+
{
68+
return $this->parent ?? throw new \InvalidArgumentException('Relationship is not attached to a parent entity.');
69+
}
70+
71+
/**
72+
* @return IRepository<E>
73+
*/
74+
protected function getTargetRepository(): IRepository
75+
{
76+
if ($this->targetRepository === null) {
77+
/** @var IRepository<E> $targetRepository */
78+
$targetRepository = $this->getParentEntity()
79+
->getRepository()
80+
->getModel()
81+
->getRepository($this->metadataRelationship->repository);
82+
$this->targetRepository = $targetRepository;
83+
}
84+
85+
return $this->targetRepository;
86+
}
87+
}

0 commit comments

Comments
 (0)