1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 18:34:04 +00:00

Fix PHPStan errors

This commit is contained in:
lukinovec 2023-05-10 05:52:50 +02:00
parent 4f9147bf81
commit 3449f19748
2 changed files with 13 additions and 5 deletions

View file

@ -4,10 +4,11 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers\Integrations;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\DatabaseManager;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
use Illuminate\Database\DatabaseManager;
use Illuminate\Contracts\Config\Repository;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
class PostgresTenancyBootstrapper implements TenancyBootstrapper
{
@ -24,6 +25,7 @@ class PostgresTenancyBootstrapper implements TenancyBootstrapper
public function bootstrap(Tenant $tenant): void
{
/** @var TenantWithDatabase $tenant */
$this->database->purge('central');
$this->config->set('database.connections.pgsql.username', $tenant->getTenantKey());

View file

@ -44,7 +44,7 @@ class CreatePostgresUserForTenant implements ShouldQueue
DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';");
}
$this->grantPermissions($name);
$this->grantPermissions((string) $name);
}
protected function grantPermissions(string $userName): void
@ -53,7 +53,13 @@ class CreatePostgresUserForTenant implements ShouldQueue
* @var \Stancl\Tenancy\Database\Contracts\StatefulTenantDatabaseManager $databaseManager
*/
$databaseManager = $this->tenant->database()->manager();
foreach (array_map(fn (string $modelName) => (new $modelName), config('tenancy.models.rls')) as $model) {
/**
* @var Model[] $rlsModels
*/
$rlsModels = array_map(fn (string $modelName) => (new $modelName), config('tenancy.models.rls'));
foreach ($rlsModels as $model) {
$table = $model->getTable();
$databaseManager->database()->statement("GRANT ALL ON {$table} TO \"{$userName}\"");