Skip to content

Commit b0086f6

Browse files
committed
Find the ancestors of a class value without resolving PHPDocs
1 parent 0d2c43a commit b0086f6

16 files changed

Lines changed: 224 additions & 5 deletions

‎e2e/bug-15375/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
/composer.lock

‎e2e/bug-15375/bootstrap.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php declare(strict_types = 1);
2+
3+
define('Bug15375\FRAMEWORK_VERSION', '13.26.1');

‎e2e/bug-15375/bug-15375_test.sh‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# @tags result-cache
3+
4+
function set_up() {
5+
e2e::set_up
6+
}
7+
8+
function tear_down() {
9+
e2e::tear_down
10+
}
11+
12+
function test_bug_15375() {
13+
# A class that was missing when the result cache was saved exists now. Restoring the
14+
# cache computes the class's value - its declarations and its ancestors' - in the main
15+
# process, before the deferred bootstrapFiles have run. It must not reach
16+
# StubPhpDocProvider, which runs the StubFilesExtensions.
17+
composer install
18+
OUTPUT=$(../../bin/phpstan analyse -vvv 2>&1 || true)
19+
echo "$OUTPUT"
20+
assert_contains 'Instantiated class Bug15375\Later not found.' "$OUTPUT"
21+
cp later/Later.php src/Later.php
22+
OUTPUT=$(../../bin/phpstan analyse -vvv 2>&1 || true)
23+
echo "$OUTPUT"
24+
assert_not_contains 'StubFilesExtension ran before bootstrapFiles.' "$OUTPUT"
25+
assert_contains 'No errors' "$OUTPUT"
26+
../../bin/phpstan analyse -vvv
27+
}

‎e2e/bug-15375/composer.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"Bug15375\\": "extension/"
5+
}
6+
}
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15375;
4+
5+
use LogicException;
6+
use PHPStan\PhpDoc\StubFilesExtension;
7+
use function defined;
8+
9+
final class FrameworkStubFilesExtension implements StubFilesExtension
10+
{
11+
12+
public function getFiles(): array
13+
{
14+
// mimics larastan, which picks its stubs by the framework version its bootstrapFiles entry defines
15+
if (!defined('Bug15375\FRAMEWORK_VERSION')) {
16+
throw new LogicException('StubFilesExtension ran before bootstrapFiles.');
17+
}
18+
19+
return [];
20+
}
21+
22+
}

‎e2e/bug-15375/later/Later.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15375;
4+
5+
/**
6+
* @extends Base<Entity>
7+
*/
8+
class Later extends Base
9+
{
10+
11+
use HasName;
12+
13+
public string $label = 'later';
14+
15+
}

‎e2e/bug-15375/phpstan.neon‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
bootstrapFiles:
6+
- bootstrap.php
7+
8+
services:
9+
-
10+
class: Bug15375\FrameworkStubFilesExtension
11+
tags:
12+
- phpstan.stubFilesExtension

‎e2e/bug-15375/src/Base.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15375;
4+
5+
/**
6+
* @template T of Entity
7+
*/
8+
abstract class Base implements Named
9+
{
10+
11+
/** @var list<T> */
12+
public array $items = [];
13+
14+
}

‎e2e/bug-15375/src/Caller.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15375;
4+
5+
class Caller
6+
{
7+
8+
public function name(): string
9+
{
10+
return (new Later())->name();
11+
}
12+
13+
}

‎e2e/bug-15375/src/Entity.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15375;
4+
5+
class Entity
6+
{
7+
8+
}

0 commit comments

Comments
 (0)