Issues (44)

src/Middleware/DynamicDatabaseConfig.php (3 issues)

1
<?php
2
3
namespace Ikechukwukalu\Dynamicdatabaseconfig\Middleware;
4
5
use Closure;
6
use Ikechukwukalu\Dynamicdatabaseconfig\Trait\DatabaseConfig;
7
use Illuminate\Http\Request;
8
9
class DynamicDatabaseConfig
10
{
11
    use DatabaseConfig;
0 ignored issues
show
The trait Ikechukwukalu\Dynamicdat...ig\Trait\DatabaseConfig requires some properties which are not provided by Ikechukwukalu\Dynamicdat...e\DynamicDatabaseConfig: $database, $configuration, $name
Loading history...
12
13
    public function handle(Request $request, Closure $next, null|string $ref = null)
14
    {
15
        if (!$ref) {
16
            $ref = session(config('dynamicdatabaseconfig.session_ref', '_db_ref'));
17
        }
18
19
        [$database, $configuration, $name] = $this->getDynamicDatabaseConfiguration($ref);
0 ignored issues
show
It seems like $ref can also be of type Illuminate\Session\SessionManager and Illuminate\Session\Store; however, parameter $ref of Ikechukwukalu\Dynamicdat...DatabaseConfiguration() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        [$database, $configuration, $name] = $this->getDynamicDatabaseConfiguration(/** @scrutinizer ignore-type */ $ref);
Loading history...
20
21
        $request->merge([config('dynamicdatabaseconfig.connection_name', '_db_connection') => $name]);
22
23
        if ($database) {
24
            $newConfig = $this->setNewDynamicConfig($database, $configuration);
0 ignored issues
show
$configuration of type null|string is incompatible with the type array expected by parameter $configuration of Ikechukwukalu\Dynamicdat...::setNewDynamicConfig(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
            $newConfig = $this->setNewDynamicConfig($database, /** @scrutinizer ignore-type */ $configuration);
Loading history...
25
            $this->addNewConfig($database, $name, $newConfig);
26
            $this->createDatabase($database, $configuration['database']);
27
        }
28
29
        return $next($request);
30
    }
31
32
}
33