forked from GNUsocial/gnu-social
[PHPStan] Only run custom PHPStan extensions if environment vairable PHPSTAN_BOOT_KERNEL is defined (since it requires having the whole social setup available)
This commit is contained in:
@@ -28,12 +28,18 @@ class ClassFromTableNameDynamicStaticMethodReturnTypeExtension implements Dynami
|
||||
return in_array($methodReflection->getName(), DB::METHODS_ACCEPTING_TABLE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* For calls to DB::find and such, if the first argument is a
|
||||
* constant string, it's a table name, so convert it to the
|
||||
* corresponding entity. Only run if the environment variable
|
||||
* PHPSTAN_BOOT_KERNEL is defined
|
||||
*/
|
||||
public function getTypeFromStaticMethodCall(
|
||||
MethodReflection $methodReflection,
|
||||
StaticCall $staticCall,
|
||||
Scope $scope
|
||||
): \PHPStan\Type\Type {
|
||||
if (count($staticCall->args) >= 1 && ($arg = $staticCall->args[0]->value) instanceof String_) {
|
||||
if (isset($_ENV['PHPSTAN_BOOT_KERNEL']) && count($staticCall->args) >= 1 && ($arg = $staticCall->args[0]->value) instanceof String_) {
|
||||
// If called with the first argument as a string, it's a table name
|
||||
return $scope->resolveTypeByName(new Name(DB::filterTableName($staticCall->name, [$arg->value])));
|
||||
} else {
|
||||
|
@@ -14,15 +14,17 @@ class GNUsocialProvider
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->kernel = require __DIR__ . '/../../config/phpstan-bootstrap.php';
|
||||
$container = $this->kernel->getContainer()->get('test.service_container');
|
||||
$services = F\map(
|
||||
(new \ReflectionClass(GNUsocial::class))->getMethod('__construct')->getParameters(),
|
||||
fn ($p) => $container->get((string) $p->getType())
|
||||
);
|
||||
$this->gnu_social = new GNUsocial(...$services);
|
||||
$this->gnu_social->initialize();
|
||||
Event::handle('InitializeModule');
|
||||
if (isset($_ENV['PHPSTAN_BOOT_KERNEL'])) {
|
||||
$this->kernel = require __DIR__ . '/../../config/phpstan-bootstrap.php';
|
||||
$container = $this->kernel->getContainer()->get('test.service_container');
|
||||
$services = F\map(
|
||||
(new \ReflectionClass(GNUsocial::class))->getMethod('__construct')->getParameters(),
|
||||
fn ($p) => $container->get((string) $p->getType())
|
||||
);
|
||||
$this->gnu_social = new GNUsocial(...$services);
|
||||
$this->gnu_social->initialize();
|
||||
Event::handle('InitializeModule');
|
||||
}
|
||||
}
|
||||
|
||||
public function getGNUsocial(): GNUsocial
|
||||
|
Reference in New Issue
Block a user