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

StorageAwareCommandAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 22
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatabaseClient() 0 7 1
A getDefaultStorageFilePath() 0 6 1
A getDatabasePath() 0 4 1
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