Passed
Push — main ( edc39f...999cd0 )
by Thierry
02:03
created

ConfigTrait::directory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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