DatabaseInfoDataCollector   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 90.24%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
dl 0
loc 81
ccs 37
cts 41
cp 0.9024
rs 10
c 2
b 0
f 0
wmc 22

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getDatabasePassword() 0 3 1
A getDatabaseName() 0 3 1
A getName() 0 3 1
A getDatabasePort() 0 3 1
A getDatabaseDriver() 0 18 5
A getDatabaseUser() 0 3 1
A reset() 0 3 1
A getDatabaseHost() 0 3 1
B collect() 0 16 9
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
        } else {
27
            $dbname = isset($driverinfo["path"])?$driverinfo["path"]:"";
28
        }
29 1
        $this->data = array(
30 1
            'database_driver' => isset($driverinfo["driver"])?$driverinfo["driver"]:"",
31 1
            'database_host' => isset($driverinfo["host"])?$driverinfo["host"]:"",
32 1
            'database_port' => isset($driverinfo["port"])?$driverinfo["port"]:"",
33 1
            'database_name' => $dbname,
34 1
            'database_user' => isset($driverinfo["user"])?$driverinfo["user"]:"",
35 1
            'database_password' => isset($driverinfo["password"])?$driverinfo["password"]:""
36 1
        );
37
    }
38
39 1
    public function getDatabaseDriver(): string
40
    {
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 1
            $driverName = 'PostgreSQL';
48
        }
49 1
        if ('pdo_sqlite' === $this->data['database_driver']) {
50
            $driverName = 'SQLite';
51
        }
52 1
        if ('oci8' === $this->data['database_driver']) {
53
            $driverName = 'Oracle';
54
        }
55
56 1
        return $driverName;
57
    }
58
59 1
    public function getDatabaseHost(): ?string
60
    {
61 1
        return $this->data['database_host'];
62
    }
63
64 1
    public function getDatabasePort(): ?string
65
    {
66 1
        return $this->data['database_port'];
67
    }
68
69 1
    public function getDatabaseName(): string
70
    {
71 1
        return $this->data['database_name'];
72
    }
73
74 1
    public function getDatabaseUser(): ?string
75
    {
76 1
        return $this->data['database_user'];
77
    }
78
79 1
    public function getDatabasePassword(): ?string
80
    {
81 1
        return $this->data['database_password'];
82
    }
83
84 20
    public function reset(): bool
85
    {
86 20
        return true;
87
    }
88
89 20
    public function getName(): string
90
    {
91 20
        return 'databaseInfo';
92
    }
93
}
94