ConfigTrait::filename()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Sqlite\Db;
4
5
use function rtrim;
6
use function str_replace;
7
use function file_exists;
8
9
trait ConfigTrait
10
{
11
    /**
12
     * Get the full path to the database directory
13
     *
14
     * @param array $options
15
     *
16
     * @return string
17
     */
18
    private function directory(array $options): string
19
    {
20
        return rtrim(str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $options['directory']), '/\\');
21
    }
22
23
    /**
24
     * Get the full path to the database file
25
     *
26
     * @param string $database
27
     * @param array $options
28
     *
29
     * @return string
30
     */
31
    private function filename(string $database, array $options): string
32
    {
33
        if (!$database) {
34
            // By default, connect to the in memory database.
35
            return ':memory:';
36
        }
37
        return $this->directory($options) . DIRECTORY_SEPARATOR . $database;
38
    }
39
40
    /**
41
     * Check if a database file exists
42
     *
43
     * @param string $database
44
     * @param array $options
45
     *
46
     * @return bool
47
     */
48
    private function fileExists(string $database, array $options): bool
49
    {
50
        return ($database) && file_exists($this->directory($options) . DIRECTORY_SEPARATOR . $database);
51
    }
52
}
53