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

minor improvements for phpstan

This commit is contained in:
Samuel Štancl 2022-09-01 19:06:54 +02:00
parent 62d19c5f5d
commit f941df3a82
4 changed files with 18 additions and 9 deletions

View file

@ -15,11 +15,16 @@ class CrossDomainRedirect implements Feature
RedirectResponse::macro('domain', function (string $domain) {
/** @var RedirectResponse $this */
// Replace first occurrence of the hostname fragment with $domain
$url = $this->getTargetUrl();
/**
* The original hostname in the redirect response.
*
* @var string $hostname
*/
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
$this->setTargetUrl(substr_replace($url, $domain, $position, strlen($hostname)));
$this->setTargetUrl((string) str($url)->replace($hostname, $domain));
return $this;
});

View file

@ -146,7 +146,7 @@ class Tenancy
$tenants = is_string($tenants) ? [$tenants] : $tenants;
// Use all tenants if $tenants is falsey
$tenants = $tenants ?: $this->model()->cursor();
$tenants = $tenants ?: $this->model()->cursor(); // todo0 phpstan thinks this isn't needed, but tests fail without it
$originalTenant = $this->tenant;

View file

@ -58,11 +58,15 @@ if (! function_exists('global_cache')) {
if (! function_exists('tenant_route')) {
function tenant_route(string $domain, string $route, array $parameters = [], bool $absolute = true): string
{
// replace the first occurrence of the hostname fragment with $domain
$url = route($route, $parameters, $absolute);
$hostname = parse_url($url, PHP_URL_HOST);
$position = strpos($url, $hostname);
return substr_replace($url, $domain, $position, strlen($hostname));
/**
* The original hostname in the generated route.
*
* @var string $hostname
*/
$hostname = parse_url($url, PHP_URL_HOST);
return (string) str($url)->replace($hostname, $domain);
}
}

View file

@ -96,7 +96,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'--realpath' => true,
'--force' => true,
],
'tenancy.bootstrappers.redis' => \Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class,
'tenancy.bootstrappers.redis' => \Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // todo0 change this to []? two tests in TenantDatabaseManagerTest are failing with that
'queue.connections.central' => [
'driver' => 'sync',
'central' => true,