Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MysqlPdoFactory | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
8 / 8 |
|
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 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Plugin\PdoFactory\Internal; |
| 11 | |
| 12 | use PDO; |
| 13 | |
| 14 | final readonly class MysqlPdoFactory |
| 15 | { |
| 16 | public function __construct( |
| 17 | private array $env, |
| 18 | ) {} |
| 19 | |
| 20 | public function create(): PDO |
| 21 | { |
| 22 | $host = $this->env['database.mysql.host']; |
| 23 | $port = $this->env['database.mysql.port'] ?? '3306'; |
| 24 | $dbname = $this->env['database.mysql.dbname']; |
| 25 | $charset = $this->env['database.mysql.charset'] ?? 'utf8mb4'; |
| 26 | |
| 27 | $dsn = sprintf('mysql:host=%s;port=%s;dbname=%s;charset=%s', $host, $port, $dbname, $charset); |
| 28 | |
| 29 | return new PDO($dsn, $this->env['database.mysql.user'], $this->env['database.mysql.password'], [ |
| 30 | PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, |
| 31 | ]); |
| 32 | } |
| 33 | } |