larastan: Error when there is no database
- Larastan Version: 0.6.4
--levelused: max
Description
I’m using spatie/laravel-permission package in my app. That registers some stuffs in service provider. When i setup a pipeline this error occured.
Similar issue: https://github.com/symfony/symfony/issues/37069
Error Output
------ ---------------------------------------------------------------------
Line Http/Controllers/Api/RoleController.php
------ ---------------------------------------------------------------------
Internal error: SQLSTATE[HY000] [2002] Connection refused (SQL:
select column_name as `column_name` from information_schema.columns
where table_schema = forge and table_name = roles)
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new
------ ---------------------------------------------------------------------
------ ---------------------------------------------------------------------
Line Http/Resources/PermissionResource.php
------ ---------------------------------------------------------------------
Internal error: SQLSTATE[HY000] [2002] Connection refused (SQL:
select column_name as `column_name` from information_schema.columns
where table_schema = forge and table_name = permissions)
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new
------ ---------------------------------------------------------------------
------ ---------------------------------------------------------------------
Line Rules/EmptyRole.php
------ ---------------------------------------------------------------------
Internal error: SQLSTATE[HY000] [2002] Connection refused (SQL:
select column_name as `column_name` from information_schema.columns
where table_schema = forge and table_name = roles)
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new
------ ---------------------------------------------------------------------
Laravel code where the issue was found
class PermissionController extends Controller
{
public function index(): JsonResponse
{
$permissions = Permission::all();
return new JsonResponse([
'data' => $permissions->pluck('name'),
]);
}
}
Another example
ConnectionFactory reads Salesforce config from .env and creates a soap client.
public function register(): void
{
$this->app->singleton(SforceEnterpriseClient::class, static function (): SforceEnterpriseClient {
$factory = new ConnectionFactory();
return $factory->createConnection();
});
}
Error Output
------ ---------------------------------------------------------------------
Line Salesforce/Services/UserService.php
------ ---------------------------------------------------------------------
Internal error: INVALID_LOGIN: Invalid username, password, security
token; or user locked out.
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new
------ ---------------------------------------------------------------------
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (4 by maintainers)
@canvural That fixed it for me. Thanks!
In work projects, we are extending the
\Spatie\Permission\Models\Rolemodel and using our ownRolemodel. So at first, I did not see this error.But when I explicitly use that model like so:
it produces the same error as in the original issue.
The error originates from here. The solution I’m thinking is wrapping this statement in try/catch block. And fallback to “guessing” the table name in
catchblock. Like this:Or we can just
return falsefrom thecatchblock. Ignoring this model.Any other suggestions?
Hi,
Can you run PHPStan only on one file,
Http/Controllers/Api/RoleController.phpfor example, with--debugflag and post the stack trace here?@szepeviktor We still boot up the Laravel.