-
-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when there is no database #656
Comments
This occurs when you test a package for Laravel, not an application. |
AFAIK Larastan used to boot up Laraval but now it does real clean static analysis. @canvural ? |
Hi, Can you run PHPStan only on one file, @szepeviktor We still boot up the Laravel. |
Sure.
|
Maybe we need the xdebug extension to get a stack trace... |
Can you show your phpstan config, maybe there is some autoloader configured? |
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/timeweb/phpstan-enum/extension.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
paths:
- app
level: max
ignoreErrors:
- '#Dynamic call to static method#'
- '#Access to an undefined property SObject::#'
- '#Variable property access on SObject#'
checkMissingIterableValueType: false |
I'm also using spatie/laravel-permission and got this similar error as mentioned in the issue.
|
This may not help but we're striving to release Laravel 1.0 |
Totally looking forward to Laravel 1.0 release 🥳 😏 |
I'm experiencing the same error. Here's a simple piece of code that will throw the error: use Spatie\Permission\Models\Role;
public function doSomething(Role $role)
{
return $role->permissions;
} I did some debugging and I'm pretty sure this change is the culprit. Specifically, this part: if (! isset(static::$guardableColumns[get_class($this)])) {
static::$guardableColumns[get_class($this)] = $this->getConnection()
->getSchemaBuilder()
->getColumnListing($this->getTable());
} Larastan seems to call the constructor for the To temporarily fix this, one could use a Laravel version before this change was added. E.g. |
In work projects, we are extending the But when I explicitly use that model like so: public function doSomething(\Spatie\Permission\Models\Role $role): Collection
{
return $role->permissions;
} 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 --- src/Properties/ModelPropertyExtension.php
+++ src/Properties/ModelPropertyExtension.php
@@ -73,9 +73,16 @@
}
$modelName = $classReflection->getNativeReflection()->getName();
+
/** @var Model $modelInstance */
- $modelInstance = new $modelName;
- $tableName = $modelInstance->getTable();
+ try {
+ $modelInstance = new $modelName;
+
+ $tableName = $modelInstance->getTable();
+ } catch (\Exception $e) {
+ $tableName = Str::snake(Str::pluralStudly(class_basename($modelName)));
+ }
+
if (! array_key_exists($tableName, $this->tables)) {
return false;
Or we can just Any other suggestions? |
Seems good to me. Can't think of another solution. |
@eislambey and @Daanra Can you test master and check if it fixed the issue for you? |
@canvural That fixed it for me. Thanks! |
--level
used: maxDescription
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: symfony/symfony#37069
Error Output
Laravel code where the issue was found
Another example
ConnectionFactory reads Salesforce config from .env and creates a soap client.
Error Output
The text was updated successfully, but these errors were encountered: