1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:34:04 +00:00

Apply fixes from StyleCI

This commit is contained in:
stancl 2019-08-16 16:21:59 +00:00 committed by StyleCI Bot
parent 417330decd
commit 84890cdd1e
20 changed files with 73 additions and 73 deletions

View file

@ -18,7 +18,7 @@ class CacheManager extends BaseCacheManager
$names = $parameters[0];
$names = (array) $names; // cache()->tags('foo') https://laravel.com/docs/5.7/cache#removing-tagged-cache-items
return $this->store()->tags(array_merge($tags, $names));
return $this->store()->tags(\array_merge($tags, $names));
}
return $this->store()->tags($tags)->$method(...$parameters);

View file

@ -34,14 +34,14 @@ class Install extends Command
]);
$this->info('✔️ Created config/tenancy.php');
file_put_contents(app_path('Http/Kernel.php'), str_replace(
\file_put_contents(app_path('Http/Kernel.php'), \str_replace(
'protected $middlewarePriority = [',
"protected \$middlewarePriority = [\n \Stancl\Tenancy\Middleware\InitializeTenancy::class,",
file_get_contents(app_path('Http/Kernel.php'))
\file_get_contents(app_path('Http/Kernel.php'))
));
$this->info('✔️ Set middleware priority');
file_put_contents(base_path('routes/tenant.php'),
\file_put_contents(base_path('routes/tenant.php'),
"<?php
/*

View file

@ -40,7 +40,7 @@ class Run extends Command
$callback = function ($prefix = '') {
return function ($arguments, $argument) use ($prefix) {
[$key, $value] = explode('=', $argument, 2);
[$key, $value] = \explode('=', $argument, 2);
$arguments[$prefix . $key] = $value;
return $arguments;
@ -48,13 +48,13 @@ class Run extends Command
};
// Turns ['foo=bar', 'abc=xyz=zzz'] into ['foo' => 'bar', 'abc' => 'xyz=zzz']
$arguments = array_reduce($this->option('argument'), $callback(), []);
$arguments = \array_reduce($this->option('argument'), $callback(), []);
// Turns ['foo=bar', 'abc=xyz=zzz'] into ['--foo' => 'bar', '--abc' => 'xyz=zzz']
$options = array_reduce($this->option('option'), $callback('--'), []);
$options = \array_reduce($this->option('option'), $callback('--'), []);
// Run command
$this->call($this->argument('commandname'), array_merge($arguments, $options));
$this->call($this->argument('commandname'), \array_merge($arguments, $options));
tenancy()->end();
});

View file

@ -50,7 +50,7 @@ final class DatabaseManager
$databaseManagers = config('tenancy.database_managers');
if (! array_key_exists($driver, $databaseManagers)) {
if (! \array_key_exists($driver, $databaseManagers)) {
throw new \Exception("Database could not be created: no database manager for driver $driver is registered.");
}
@ -76,7 +76,7 @@ final class DatabaseManager
$databaseManagers = config('tenancy.database_managers');
if (! array_key_exists($driver, $databaseManagers)) {
if (! \array_key_exists($driver, $databaseManagers)) {
throw new \Exception("Database could not be deleted: no database manager for driver $driver is registered.");
}

View file

@ -37,7 +37,7 @@ class RedisStorageDriver implements StorageDriver
return $this->redis->hgetall("tenants:$uuid");
}
return array_combine($fields, $this->redis->hmget("tenants:$uuid", $fields));
return \array_combine($fields, $this->redis->hmget("tenants:$uuid", $fields));
}
public function getTenantIdByDomain(string $domain): ?string
@ -48,7 +48,7 @@ class RedisStorageDriver implements StorageDriver
public function createTenant(string $domain, string $uuid): array
{
$this->redis->hmset("domains:$domain", 'tenant_id', $uuid);
$this->redis->hmset("tenants:$uuid", 'uuid', json_encode($uuid), 'domain', json_encode($domain));
$this->redis->hmset("tenants:$uuid", 'uuid', \json_encode($uuid), 'domain', \json_encode($domain));
return $this->redis->hgetall("tenants:$uuid");
}
@ -63,7 +63,7 @@ class RedisStorageDriver implements StorageDriver
public function deleteTenant(string $id): bool
{
try {
$domain = json_decode($this->getTenantById($id)['domain']);
$domain = \json_decode($this->getTenantById($id)['domain']);
} catch (\Throwable $th) {
throw new \Exception("No tenant with UUID $id exists.");
}
@ -75,7 +75,7 @@ class RedisStorageDriver implements StorageDriver
public function getAllTenants(array $uuids = []): array
{
$hashes = array_map(function ($hash) {
$hashes = \array_map(function ($hash) {
return "tenants:{$hash}";
}, $uuids);
@ -91,13 +91,13 @@ class RedisStorageDriver implements StorageDriver
$all_keys = $this->redis->scan(null, 'MATCH', $redis_prefix . 'tenants:*')[1];
}
$hashes = array_map(function ($key) use ($redis_prefix) {
$hashes = \array_map(function ($key) use ($redis_prefix) {
// Left strip $redis_prefix from $key
return substr($key, strlen($redis_prefix));
return \substr($key, \strlen($redis_prefix));
}, $all_keys);
}
return array_map(function ($tenant) {
return \array_map(function ($tenant) {
return $this->redis->hgetall($tenant);
}, $hashes);
}

View file

@ -54,14 +54,14 @@ class Tenant extends Model
public static function decodeData($tenant)
{
$tenant = $tenant instanceof self ? (array) $tenant->attributes : $tenant;
$decoded = json_decode($tenant[$dataColumn = static::dataColumn()], true);
$decoded = \json_decode($tenant[$dataColumn = static::dataColumn()], true);
foreach ($decoded as $key => $value) {
$tenant[$key] = $value;
}
// If $tenant[$dataColumn] has been overriden by a value, don't delete the key.
if (! array_key_exists($dataColumn, $decoded)) {
if (! \array_key_exists($dataColumn, $decoded)) {
unset($tenant[$dataColumn]);
}
@ -70,7 +70,7 @@ class Tenant extends Model
public function getFromData(string $key)
{
$this->dataArray = $this->dataArray ?? json_decode($this->{$this->dataColumn()}, true);
$this->dataArray = $this->dataArray ?? \json_decode($this->{$this->dataColumn()}, true);
return $this->dataArray[$key] ?? null;
}
@ -83,18 +83,18 @@ class Tenant extends Model
/** @todo In v2, this should return an associative array. */
public function getMany(array $keys): array
{
return array_map([$this, 'get'], $keys);
return \array_map([$this, 'get'], $keys);
}
public function put(string $key, $value)
{
if (array_key_exists($key, $this->customColumns())) {
if (\array_key_exists($key, $this->customColumns())) {
$this->update([$key => $value]);
} else {
$obj = json_decode($this->{$this->dataColumn()});
$obj = \json_decode($this->{$this->dataColumn()});
$obj->$key = $value;
$this->update([$this->dataColumn() => json_encode($obj)]);
$this->update([$this->dataColumn() => \json_encode($obj)]);
}
return $value;

View file

@ -9,7 +9,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function createDatabase(string $name): bool
{
try {
return fclose(fopen(database_path($name), 'w'));
return \fclose(\fopen(database_path($name), 'w'));
} catch (\Throwable $th) {
return false;
}
@ -18,7 +18,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
public function deleteDatabase(string $name): bool
{
try {
return unlink(database_path($name));
return \unlink(database_path($name));
} catch (\Throwable $th) {
return false;
}

View file

@ -64,7 +64,7 @@ final class TenantManager
$tenant = $this->storage->identifyTenant($domain);
if (! $tenant || ! array_key_exists('uuid', $tenant) || ! $tenant['uuid']) {
if (! $tenant || ! \array_key_exists('uuid', $tenant) || ! $tenant['uuid']) {
throw new \Exception("Tenant could not be identified on domain {$domain}.");
}
@ -94,7 +94,7 @@ final class TenantManager
if ($data) {
$this->put($data, null, $tenant['uuid']);
$tenant = array_merge($tenant, $data);
$tenant = \array_merge($tenant, $data);
}
$this->database->create($this->getDatabaseName($tenant));
@ -175,7 +175,7 @@ final class TenantManager
$uuid = $this->getIdByDomain($domain);
if (is_null($uuid)) {
if (\is_null($uuid)) {
throw new \Exception("Tenant with domain $domain could not be identified.");
}
@ -240,7 +240,7 @@ final class TenantManager
$tenants = $this->storage->getAllTenants($uuids);
if ($this->useJson()) {
$tenants = array_map(function ($tenant_array) {
$tenants = \array_map(function ($tenant_array) {
return $this->jsonDecodeArrayValues($tenant_array);
}, $tenants);
}
@ -273,8 +273,8 @@ final class TenantManager
{
$uuid = $uuid ?: $this->tenant['uuid'];
if (array_key_exists('uuid', $this->tenant) && $uuid === $this->tenant['uuid'] &&
array_key_exists($key, $this->tenant) && ! is_array($key)) {
if (\array_key_exists('uuid', $this->tenant) && $uuid === $this->tenant['uuid'] &&
\array_key_exists($key, $this->tenant) && ! \is_array($key)) {
return $this->tenant[$key];
}
@ -282,7 +282,7 @@ final class TenantManager
return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key));
}
return json_decode($this->storage->get($uuid, $key), true);
return \json_decode($this->storage->get($uuid, $key), true);
}
/**
@ -295,10 +295,10 @@ final class TenantManager
*/
public function put($key, $value = null, string $uuid = null)
{
if (in_array($key, ['uuid', 'domain'], true) || (
is_array($key) && (
in_array('uuid', array_keys($key), true) ||
in_array('domain', array_keys($key), true)
if (\in_array($key, ['uuid', 'domain'], true) || (
\is_array($key) && (
\in_array('uuid', \array_keys($key), true) ||
\in_array('domain', \array_keys($key), true)
)
)) {
throw new CannotChangeUuidOrDomainException;
@ -319,7 +319,7 @@ final class TenantManager
}
if (! \is_null($value)) {
return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value)), true);
return $target[$key] = \json_decode($this->storage->put($uuid, $key, \json_encode($value)), true);
}
if (! \is_array($key)) {
@ -328,7 +328,7 @@ final class TenantManager
foreach ($key as $k => $v) {
$target[$k] = $v;
$key[$k] = json_encode($v);
$key[$k] = \json_encode($v);
}
return $this->jsonDecodeArrayValues($this->storage->putMany($uuid, $key));
@ -349,8 +349,8 @@ final class TenantManager
protected function jsonDecodeArrayValues(array $array)
{
array_walk($array, function (&$value, $key) {
$value = json_decode($value, true);
\array_walk($array, function (&$value, $key) {
$value = \json_decode($value, true);
});
return $array;
@ -358,7 +358,7 @@ final class TenantManager
public function useJson()
{
if (property_exists($this->storage, 'useJson') && $this->storage->useJson === false) {
if (\property_exists($this->storage, 'useJson') && $this->storage->useJson === false) {
return false;
}

View file

@ -10,7 +10,7 @@ class TenantRouteServiceProvider extends RouteServiceProvider
public function map()
{
if (! \in_array(request()->getHost(), $this->app['config']['tenancy.exempt_domains'] ?? [])
&& file_exists(base_path('routes/tenant.php'))) {
&& \file_exists(base_path('routes/tenant.php'))) {
Route::middleware(['web', 'tenancy'])
->namespace($this->app['config']['tenant_route_namespace'] ?? 'App\Http\Controllers')
->group(base_path('routes/tenant.php'));

View file

@ -138,7 +138,7 @@ trait BootstrapsTenancy
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
$old['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix();
if ($root = str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) {
if ($root = \str_replace('%storage_path%', storage_path(), $this->app['config']["tenancy.filesystem.root_override.{$disk}"])) {
Storage::disk($disk)->getAdapter()->setPathPrefix($root);
} else {
$root = $this->app['config']["filesystems.disks.{$disk}.root"];

View file

@ -8,7 +8,7 @@ trait HasATenantsOption
{
protected function getOptions()
{
return array_merge([
return \array_merge([
['tenants', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', null],
], parent::getOptions());
}

View file

@ -78,7 +78,7 @@ trait TenantManagerEvents
*/
public function event(string $name): Collection
{
return array_reduce($this->listeners[$name], function ($prevents, $listener) {
return \array_reduce($this->listeners[$name], function ($prevents, $listener) {
return $prevents->merge($listener($this) ?? []);
}, collect([]));
}

View file

@ -2,7 +2,7 @@
use Stancl\Tenancy\TenantManager;
if (! function_exists('tenancy')) {
if (! \function_exists('tenancy')) {
function tenancy($key = null)
{
if ($key) {
@ -13,14 +13,14 @@ if (! function_exists('tenancy')) {
}
}
if (! function_exists('tenant')) {
if (! \function_exists('tenant')) {
function tenant($key = null)
{
return tenancy($key);
}
}
if (! function_exists('tenant_asset')) {
if (! \function_exists('tenant_asset')) {
function tenant_asset($asset)
{
return route('stancl.tenancy.asset', ['asset' => $asset]);