Skip to content

Commit e99e630

Browse files
committed
fix(codex): inherit method docblocks from ancestor classes through intermediate classes
closes #766 Signed-off-by: azjezz <[email protected]>
1 parent 1bbb2e1 commit e99e630

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
class Entity
6+
{
7+
public function __construct(
8+
public int $id,
9+
) {}
10+
}
11+
12+
/**
13+
* @template TEntity of object
14+
*/
15+
abstract class AbstractVoter
16+
{
17+
/** @param TEntity $object */
18+
abstract protected function voteOnEntity(object $object): bool;
19+
}
20+
21+
/**
22+
* @extends AbstractVoter<Entity>
23+
*/
24+
abstract class AbstractEntityVoter extends AbstractVoter
25+
{
26+
}
27+
28+
final class Voter1 extends AbstractEntityVoter
29+
{
30+
#[Override]
31+
protected function voteOnEntity(object $object): bool
32+
{
33+
return $object->id === 1;
34+
}
35+
}
36+
37+
final class Voter1Inherit extends AbstractEntityVoter
38+
{
39+
/**
40+
* @inheritDoc
41+
*/
42+
#[Override]
43+
protected function voteOnEntity(object $object): bool
44+
{
45+
return $object->id === 1;
46+
}
47+
}
48+
49+
/**
50+
* @extends AbstractVoter<Entity>
51+
*/
52+
final class Voter2 extends AbstractVoter
53+
{
54+
#[Override]
55+
protected function voteOnEntity(object $object): bool
56+
{
57+
return $object->id === 2;
58+
}
59+
}
60+
61+
/**
62+
* @extends AbstractVoter<Entity>
63+
*/
64+
final class Voter2Inherit extends AbstractVoter
65+
{
66+
/**
67+
* @inheritDoc
68+
*/
69+
#[Override]
70+
protected function voteOnEntity(object $object): bool
71+
{
72+
return $object->id === 2;
73+
}
74+
}

crates/analyzer/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ test_case!(issue_755);
471471
test_case!(issue_756);
472472
test_case!(issue_764);
473473
test_case!(issue_765);
474+
test_case!(issue_766);
474475

475476
#[test]
476477
fn test_all_test_cases_are_ran() {

crates/codex/src/populator/docblock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ pub fn inherit_method_docblocks(codebase: &mut CodebaseMetadata) {
191191
}
192192
}
193193

194+
if parent_method_id.is_none() {
195+
if let Some((declaring_class, method_id)) = method_ids.iter().next() {
196+
parent_method_id = Some((*declaring_class, *method_id.get_method_name()));
197+
}
198+
}
199+
194200
if let Some((parent_class, parent_method)) = parent_method_id {
195201
inheritance_work.push((*class_name, *method_name, parent_class, parent_method));
196202
}

0 commit comments

Comments
 (0)