Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PostgresqlPdoFactory
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace Phexium\Plugin\PdoFactory\Internal;
11
12use PDO;
13
14final readonly class PostgresqlPdoFactory
15{
16    public function __construct(
17        private array $env,
18    ) {}
19
20    public function create(): PDO
21    {
22        $host = $this->env['database.postgresql.host'];
23        $port = $this->env['database.postgresql.port'] ?? '5432';
24        $dbname = $this->env['database.postgresql.dbname'];
25
26        $dsn = sprintf('pgsql:host=%s;port=%s;dbname=%s', $host, $port, $dbname);
27
28        return new PDO($dsn, $this->env['database.postgresql.user'], $this->env['database.postgresql.password'], [
29            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
30        ]);
31    }
32}