Skip to content
Merged
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
Cover the loader shapes the reverted autoloader attempts broke
#6292 reverted five commits because the attempts fixed one use case and
broke another, and only some of those breakages had an e2e project. These
two do not test PHPStan's current behaviour so much as pin the shapes a
future attempt at phpstan/phpstan#14976 and phpstan/phpstan#14988 must not
regress.

class-alias-loader uses the real typo3/class-alias-loader: it replaces
Composer's loader with its own wrapper, resolves a legacy name through a
class alias map, and an IDE-only stub in the analysed paths declares that
name as a plain class. The alias has to win. 2.2.9 returns the stub and
reports a missing method.

robot-loader registers a Nette RobotLoader over a directory Composer does
not map, so only that loader can find the class. RobotLoader locks and
writes a cache file while resolving, which fails inside the file-read trap:
on 598faaa the analysis dies in RobotLoader::acquireLock() with
"Unable to create file '<tmp>/....php.lock'".

Both pass on this commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
  • Loading branch information
SanderMuller and claude committed Aug 27, 2026
commit 7132109ddcf384733194bf37778890a402bad52d
8 changes: 8 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ jobs:
cd e2e/bug-12972c
composer install
../../bin/phpstan analyze
- script: |
cd e2e/class-alias-loader
composer install
../../bin/phpstan analyze
- script: |
cd e2e/robot-loader
composer install
../../bin/phpstan analyze
- script: |
cd e2e/bug-15102b
../../bin/phpstan analyze
Expand Down
2 changes: 2 additions & 0 deletions e2e/class-alias-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.lock
7 changes: 7 additions & 0 deletions e2e/class-alias-loader/alias-map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types = 1);

// typo3/class-alias-loader replaces Composer's class loader with its own wrapper and
// resolves these names through class_alias() at runtime.
return [
'AliasLoaderE2e\\LegacyName' => 'AliasLoaderE2e\\ModernName',
];
23 changes: 23 additions & 0 deletions e2e/class-alias-loader/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"require": {
"typo3/class-alias-loader": "^1.2"
},
"autoload": {
"psr-4": {
"AliasLoaderE2e\\": "src/"
}
},
"extra": {
"typo3/class-alias-loader": {
"class-alias-maps": [
"alias-map.php"
],
"always-add-alias-loader": true
}
},
"config": {
"allow-plugins": {
"typo3/class-alias-loader": true
}
}
}
7 changes: 7 additions & 0 deletions e2e/class-alias-loader/phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 8
bootstrapFiles:
- vendor/autoload.php
paths:
- test.php
- stub
13 changes: 13 additions & 0 deletions e2e/class-alias-loader/src/ModernName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace AliasLoaderE2e;

class ModernName
{

public function doFoo(): int
{
return 1;
}

}
13 changes: 13 additions & 0 deletions e2e/class-alias-loader/stub/LegacyName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace AliasLoaderE2e;

// An IDE-only stub, never loaded at runtime: it declares the legacy name as a plain class so
// editors resolve it. At runtime typo3/class-alias-loader makes the name a class_alias to
// ModernName, which is the declaration PHPStan has to use - it has doFoo(), this does not.
die('never loaded at runtime');

class LegacyName
{

}
7 changes: 7 additions & 0 deletions e2e/class-alias-loader/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types = 1);

use AliasLoaderE2e\LegacyName;

function (LegacyName $legacy): int {
return $legacy->doFoo();
};
2 changes: 2 additions & 0 deletions e2e/robot-loader/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
composer.lock
8 changes: 8 additions & 0 deletions e2e/robot-loader/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);

require __DIR__ . '/vendor/autoload.php';

$loader = new Nette\Loaders\RobotLoader();
$loader->addDirectory(__DIR__ . '/classes');
$loader->setTempDirectory(sys_get_temp_dir() . '/phpstan-e2e-robot-loader');
$loader->register();
15 changes: 15 additions & 0 deletions e2e/robot-loader/classes/Discovered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace RobotLoaderE2e;

// Deliberately outside any Composer autoload mapping: only RobotLoader can find this class,
// by scanning the directory. PHPStan has to consult the bootstrap-registered loader for it.
class Discovered
{

public function doFoo(): int
{
return 1;
}

}
5 changes: 5 additions & 0 deletions e2e/robot-loader/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"nette/robot-loader": "^4.0"
}
}
6 changes: 6 additions & 0 deletions e2e/robot-loader/phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
bootstrapFiles:
- bootstrap.php
paths:
- test.php
7 changes: 7 additions & 0 deletions e2e/robot-loader/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types = 1);

use RobotLoaderE2e\Discovered;

function (Discovered $discovered): int {
return $discovered->doFoo();
};
Loading