Issues (265)

src/Config/SQLiteDriverConfig.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * This file is part of Cycle Database package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Config;
13
14
use Cycle\Database\Config\SQLite\ConnectionConfig;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Cycle\Database\Config\ConnectionConfig. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use Cycle\Database\Config\SQLite\MemoryConnectionConfig;
16
use Cycle\Database\Driver\SQLite\SQLiteDriver;
17
18
/**
19
 * @template-extends DriverConfig<ConnectionConfig>
20
 */
21
class SQLiteDriverConfig extends DriverConfig
22
{
23
    public function __construct(
24
        ?ConnectionConfig $connection = null,
25
        string $driver = SQLiteDriver::class,
26
        bool $reconnect = true,
27
        string $timezone = 'UTC',
28 26
        bool $queryCache = true,
29
        bool $readonlySchema = false,
30
        bool $readonly = false,
31
        array $options = [],
32
    ) {
33
        /** @psalm-suppress ArgumentTypeCoercion */
34
        parent::__construct(
35
            connection: $connection ?? new MemoryConnectionConfig(),
36
            driver: $driver,
37
            reconnect: $reconnect,
38 26
            timezone: $timezone,
39 26
            queryCache: $queryCache,
40
            readonlySchema: $readonlySchema,
41
            readonly: $readonly,
42
            options: $options,
43
        );
44
    }
45
}
46