Passed
Push — master ( 8aca16...784b35 )
by Andrea
61:57 queued 12s
created

DatabaseInfoDataCollector::collect()   B

Complexity

Conditions 9
Paths 96

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 13
nc 96
nop 3
dl 0
loc 16
ccs 11
cts 11
cp 1
crap 9
rs 8.0555
c 1
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Collector;
4
5
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Throwable;
10
11
class DatabaseInfoDataCollector extends DataCollector
12
{
13
    private EntityManagerInterface $em;
14
15 20
    public function __construct(EntityManagerInterface $em)
16
    {
17 20
        $this->em = $em;
18
    }
19
20 1
    public function collect(Request $request, Response $response, Throwable $exception = null): void
21
    {
22 1
        $driverinfo = $this->em->getConnection()->getParams();
23 1
        $dbname = "";
24 1
        if (isset($driverinfo["dbname"]) && array_key_exists("dbname", $driverinfo)) {
25 1
            $dbname = $driverinfo["dbname"];
26 1
        } else {
27 1
            $dbname = isset($driverinfo["path"])?$driverinfo["path"]:"";
28 1
        }
29 1
        $this->data = array(
30
            'database_driver' => isset($driverinfo["driver"])?$driverinfo["driver"]:"",
31
            'database_host' => isset($driverinfo["host"])?$driverinfo["host"]:"",
32
            'database_port' => isset($driverinfo["port"])?$driverinfo["port"]:"",
33 1
            'database_name' => $dbname,
34
            'database_user' => isset($driverinfo["user"])?$driverinfo["user"]:"",
35 1
            'database_password' => isset($driverinfo["password"])?$driverinfo["password"]:""
36
        );
37 1
    }
38
39
    public function getDatabaseDriver(): string
40 1
    {
41 1
        $driverName = 'Driver non gestito da questo pannello';
42
43 1
        if ('pdo_mysql' === $this->data['database_driver']) {
44
            $driverName = 'MySql';
45
        }
46 1
        if ('pdo_pgsql' === $this->data['database_driver']) {
47
            $driverName = 'PostgreSQL';
48
        }
49
        if ('pdo_sqlite' === $this->data['database_driver']) {
50 1
            $driverName = 'SQLite';
51
        }
52
        if ('oci8' === $this->data['database_driver']) {
53 1
            $driverName = 'Oracle';
54
        }
55 1
56
        return $driverName;
57
    }
58 1
59
    public function getDatabaseHost(): ?string
60 1
    {
61
        return $this->data['database_host'];
62
    }
63 1
64
    public function getDatabasePort(): ?string
65 1
    {
66
        return $this->data['database_port'];
67
    }
68 1
69
    public function getDatabaseName(): string
70 1
    {
71
        return $this->data['database_name'];
72
    }
73 1
74
    public function getDatabaseUser(): ?string
75 1
    {
76
        return $this->data['database_user'];
77
    }
78 20
79
    public function getDatabasePassword(): ?string
80 20
    {
81
        return $this->data['database_password'];
82
    }
83 20
84
    public function reset(): bool
85 20
    {
86
        return true;
87
    }
88
89
    public function getName(): string
90
    {
91
        return 'databaseInfo';
92
    }
93
}
94