Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
8 / 8
CRAP
100.00% covered (success)
100.00%
1 / 1
Db
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
8 / 8
10
100.00% covered (success)
100.00%
1 / 1
 setDbManager
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 select
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 selectOne
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 insert
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 delete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 connection
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPdo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Database;
6
7use Illuminate\Database\Capsule\Manager as CapsuleManager;
8use Illuminate\Database\Connection as DatabaseConnection;
9use PDO;
10
11/** @deprecated */
12class Db
13{
14    protected static CapsuleManager $dbManager;
15
16    /**
17     * Set the database connection manager
18     */
19    public static function setDbManager(CapsuleManager $dbManager): void
20    {
21        self::$dbManager = $dbManager;
22    }
23
24    /**
25     * Run a select query
26     *
27     * @return array[]
28     */
29    public static function select(string $query, array $bindings = []): array
30    {
31        $return = self::connection()->select($query, $bindings);
32
33        // @TODO: Remove type casting
34        foreach ($return as $key => $value) {
35            $return[$key] = (array) $value;
36        }
37
38        return $return;
39    }
40
41    /**
42     * Run a select query and return only the first result or null if no result is found.
43     */
44    public static function selectOne(string $query, array $bindings = []): ?array
45    {
46        $result = self::connection()->selectOne($query, $bindings);
47
48        // @TODO: remove typecast
49        $result = (array) $result;
50        if (empty($result)) {
51            return null;
52        }
53
54        return $result;
55    }
56
57    /**
58     * Run an insert query
59     */
60    public static function insert(string $query, array $bindings = []): bool
61    {
62        return self::connection()->insert($query, $bindings);
63    }
64
65    /**
66     * Run an update query
67     */
68    public static function update(string $query, array $bindings = []): int
69    {
70        return self::connection()->update($query, $bindings);
71    }
72
73    /**
74     * Run a delete query
75     */
76    public static function delete(string $query, array $bindings = []): int
77    {
78        return self::connection()->delete($query, $bindings);
79    }
80
81    public static function connection(): DatabaseConnection
82    {
83        return self::$dbManager->getConnection();
84    }
85
86    /**
87     * Get the PDO instance
88     */
89    public static function getPdo(): PDO
90    {
91        return self::connection()->getPdo();
92    }
93}