Passed
Push — master ( 9251f2...ca8fc4 )
by Herberto
03:14
created

getDefaultStorageFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Hgraca\Phorensic\SharedKernel\Command;
4
5
use Cilex\Provider\Console\Command;
6
use Hgraca\MicroDbal\Crud\CrudClient;
7
use Hgraca\MicroDbal\Crud\QueryBuilder\Sql\SqlQueryBuilder;
8
use Hgraca\MicroDbal\Raw\PdoClient;
9
use Hgraca\Phorensic\SharedKernel\Port\Database\Adapter\MicroDbal\MicroDbalAdapter;
10
use Hgraca\Phorensic\SharedKernel\Port\Database\DatabaseClientInterface;
11
use PDO;
12
use Symfony\Component\Console\Input\InputInterface;
13
14
abstract class StorageAwareCommandAbstract extends Command
15
{
16
    protected function getDatabaseClient($dbPath): DatabaseClientInterface
17
    {
18
        $dsn = 'sqlite:' . $dbPath;
19
        $crudClient = new CrudClient($rawClient = new PdoClient(new PDO($dsn)), new SqlQueryBuilder());
20
21
        return new MicroDbalAdapter($crudClient, $rawClient);
22
    }
23
24
    protected function getDefaultStorageFilePath(): string
25
    {
26
        $time = date("Y-m-d_H:i:s");
27
28
        return ROOT_DIR . "/var/analyse_$time.sqlite";
29
    }
30
31
    protected function getDatabasePath(InputInterface $input): string
32
    {
33
        return $input->getArgument('dbPath') ?? $this->getDefaultStorageFilePath();
34
    }
35
}
36