1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 17:44:03 +00:00

get down to 59 phpstan errors

This commit is contained in:
Samuel Štancl 2022-09-29 22:20:55 +02:00
parent 193e044777
commit a94227a19c
26 changed files with 130 additions and 130 deletions

View file

@ -23,14 +23,14 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper
) {
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
// Update batch repository connection to use the tenant connection
$this->previousConnection = $this->batchRepository->getConnection();
$this->batchRepository->setConnection($this->databaseManager->connection('tenant'));
}
public function revert()
public function revert(): void
{
if ($this->previousConnection) {
// Replace batch repository connection with the previously replaced one

View file

@ -13,18 +13,13 @@ use Stancl\Tenancy\Contracts\Tenant;
class CacheTenancyBootstrapper implements TenancyBootstrapper
{
/** @var CacheManager */
protected $originalCache;
protected ?CacheManager $originalCache = null;
/** @var Application */
protected $app;
public function __construct(
protected Application $app
) {}
public function __construct(Application $app)
{
$this->app = $app;
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
$this->resetFacadeCache();
@ -34,7 +29,7 @@ class CacheTenancyBootstrapper implements TenancyBootstrapper
});
}
public function revert()
public function revert(): void
{
$this->resetFacadeCache();
@ -50,7 +45,7 @@ class CacheTenancyBootstrapper implements TenancyBootstrapper
* facade has been made prior to bootstrapping tenancy. The
* facade has its own cache, separate from the container.
*/
public function resetFacadeCache()
public function resetFacadeCache(): void
{
Cache::clearResolvedInstances();
}

View file

@ -8,7 +8,7 @@ use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Database\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{
@ -20,7 +20,7 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
$this->database = $database;
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
/** @var TenantWithDatabase $tenant */
@ -35,7 +35,7 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
$this->database->connectToTenant($tenant);
}
public function revert()
public function revert(): void
{
$this->database->reconnectToCentral();
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
@ -27,13 +28,14 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
];
$this->app['url']->macro('setAssetRoot', function ($root) {
/** @var UrlGenerator $this */
$this->assetRoot = $root;
return $this;
});
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->getTenantKey();
@ -91,7 +93,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
}
}
public function revert()
public function revert(): void
{
// storage_path()
$this->app->useStoragePath($this->originalPaths['storage']);

View file

@ -10,27 +10,22 @@ use Stancl\Tenancy\Contracts\Tenant;
class ScoutTenancyBootstrapper implements TenancyBootstrapper
{
/** @var Repository */
protected $config;
protected ?string $originalScoutPrefix = null;
/** @var string */
protected $originalScoutPrefix;
public function __construct(
protected Repository $config,
) {}
public function __construct(Repository $config)
public function bootstrap(Tenant $tenant): void
{
$this->config = $config;
}
public function bootstrap(Tenant $tenant)
{
if (! isset($this->originalScoutPrefix)) {
if ($this->originalScoutPrefix !== null) {
$this->originalScoutPrefix = $this->config->get('scout.prefix');
}
$this->config->set('scout.prefix', $this->getTenantPrefix($tenant));
}
public function revert()
public function revert(): void
{
$this->config->set('scout.prefix', $this->originalScoutPrefix);
}

View file

@ -39,7 +39,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
* However, we're registering a hook to initialize tenancy. Therefore,
* we need to register the hook at service provider execution time.
*/
public static function __constructStatic(Application $app)
public static function __constructStatic(Application $app): void
{
static::setUpJobListener($app->make(Dispatcher::class), $app->runningUnitTests());
}
@ -52,7 +52,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
$this->setUpPayloadGenerator();
}
protected static function setUpJobListener($dispatcher, $runningTests)
protected static function setUpJobListener(Dispatcher $dispatcher, bool $runningTests): void
{
$previousTenant = null;
@ -79,7 +79,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
$dispatcher->listen(JobFailed::class, $revertToPreviousState); // artisan('queue:work') which fails
}
protected static function initializeTenancyForQueue($tenantId)
protected static function initializeTenancyForQueue(string|int $tenantId): void
{
if (! $tenantId) {
// The job is not tenant-aware
@ -97,7 +97,9 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
tenancy()->end();
}
tenancy()->initialize(tenancy()->find($tenantId));
/** @var Tenant $tenant */
$tenant = tenancy()->find($tenantId);
tenancy()->initialize($tenant);
return;
}
@ -112,10 +114,13 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
// Tenancy was either not initialized, or initialized for a different tenant.
// Therefore, we initialize it for the correct tenant.
tenancy()->initialize(tenancy()->find($tenantId));
/** @var Tenant $tenant */
$tenant = tenancy()->find($tenantId);
tenancy()->initialize($tenant);
}
protected static function revertToPreviousState($event, &$previousTenant)
protected static function revertToPreviousState($event, ?Tenant &$previousTenant): void
{
$tenantId = $event->job->payload()['tenant_id'] ?? null;
@ -135,7 +140,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
}
}
protected function setUpPayloadGenerator()
protected function setUpPayloadGenerator(): void
{
$bootstrapper = &$this;
@ -146,17 +151,17 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
}
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
//
}
public function revert()
public function revert(): void
{
//
}
public function getPayload(string $connection)
public function getPayload(string $connection): array
{
if (! tenancy()->initialized) {
return [];

View file

@ -22,18 +22,21 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
$this->config = $config;
}
public function bootstrap(Tenant $tenant)
public function bootstrap(Tenant $tenant): void
{
foreach ($this->prefixedConnections() as $connection) {
$prefix = $this->config['tenancy.redis.prefix_base'] . $tenant->getTenantKey();
$client = Redis::connection($connection)->client();
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);
/** @var string $originalPrefix */
$originalPrefix = $client->getOption($client::OPT_PREFIX);
$this->originalPrefixes[$connection] = $originalPrefix;
$client->setOption($client::OPT_PREFIX, $prefix);
}
}
public function revert()
public function revert(): void
{
foreach ($this->prefixedConnections() as $connection) {
$client = Redis::connection($connection)->client();
@ -44,7 +47,8 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
$this->originalPrefixes = [];
}
protected function prefixedConnections()
/** @return string[] */
protected function prefixedConnections(): array
{
return $this->config['tenancy.redis.prefixed_connections'];
}