• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / dibi / 22284472534

22 Feb 2026 08:11PM UTC coverage: 76.31% (-0.2%) from 76.552%
22284472534

push

github

dg
phpstan

56 of 106 new or added lines in 23 files covered. (52.83%)

82 existing lines in 8 files now uncovered.

1762 of 2309 relevant lines covered (76.31%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.89
/src/Dibi/dibi.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Dibi, smart database abstraction layer (https://dibi.nette.org)
5
 * Copyright (c) 2005 David Grudl (https://davidgrudl.com)
6
 */
7

8

9
/**
10
 * Static container class for Dibi connections.
11
 *
12
 * @method static void disconnect()
13
 * @method static Dibi\Result query(mixed ...$args)
14
 * @method static Dibi\Result nativeQuery(string $sql)
15
 * @method static bool test(mixed ...$args)
16
 * @method static Dibi\DataSource dataSource(mixed ...$args)
17
 * @method static Dibi\Row|null fetch(mixed ...$args)
18
 * @method static list<Dibi\Row|array<string, mixed>> fetchAll(mixed ...$args)
19
 * @method static mixed fetchSingle(mixed ...$args)
20
 * @method static array<string, mixed> fetchPairs(mixed ...$args)
21
 * @method static int getAffectedRows()
22
 * @method static int getInsertId(?string $sequence = null)
23
 * @method static void begin(?string $savepoint = null)
24
 * @method static void commit(?string $savepoint = null)
25
 * @method static void rollback(?string $savepoint = null)
26
 * @method static mixed transaction(callable(Dibi\Connection): mixed $callback)
27
 * @method static Dibi\Reflection\Database getDatabaseInfo()
28
 * @method static Dibi\Fluent command()
29
 * @method static Dibi\Fluent select(mixed ...$args)
30
 * @method static Dibi\Fluent update(string|string[] $table, iterable<string, mixed> $args)
31
 * @method static Dibi\Fluent insert(string $table, iterable<string, mixed> $args)
32
 * @method static Dibi\Fluent delete(string $table)
33
 * @method static Dibi\HashMap getSubstitutes()
34
 * @method static int loadFile(string $file)
35
 */
36
class dibi
37
{
38
        public const Version = '5.1-dev';
39

40
        /** @deprecated use dibi::Version */
41
        public const VERSION = self::Version;
42

43
        /** @deprecated use Dibi\Fluent::AffectedRows */
44
        public const AFFECTED_ROWS = Dibi\Fluent::AffectedRows;
45

46
        /** @deprecated use Dibi\Fluent::Identifier */
47
        public const IDENTIFIER = Dibi\Fluent::Identifier;
48

49
        /** sorting order */
50
        public const
51
                ASC = 'ASC',
52
                DESC = 'DESC';
53

54
        /** Last SQL command @see dibi::query() */
55
        public static ?string $sql = null;
56

57
        /** Elapsed time for last query */
58
        public static ?float $elapsedTime = null;
59

60
        /** Elapsed time for all queries */
61
        public static float $totalTime = 0;
62

63
        /** Number or queries */
64
        public static int $numOfQueries = 0;
65

66
        /** @var Dibi\Connection[]  Connection registry storage for Dibi\Connection objects */
67
        private static array $registry = [];
68

69
        /** Current connection */
70
        private static Dibi\Connection $connection;
71

72

73
        /**
74
         * Static class - cannot be instantiated.
75
         */
76
        final public function __construct()
77
        {
78
                throw new LogicException('Cannot instantiate static class ' . static::class);
×
79
        }
80

81

82
        /********************* connections handling ****************d*g**/
83

84

85
        /**
86
         * Creates a new Connection object and connects it to specified database.
87
         * @param  array<string, mixed>  $config  connection parameters
88
         * @throws Dibi\Exception
89
         */
90
        public static function connect(array $config = [], string $name = '0'): Dibi\Connection
1✔
91
        {
92
                return self::$connection = self::$registry[$name] = new Dibi\Connection($config, $name);
1✔
93
        }
94

95

96
        /**
97
         * Returns true when connection was established.
98
         */
99
        public static function isConnected(): bool
100
        {
NEW
101
                return isset(self::$connection) && self::$connection->isConnected();
×
102
        }
103

104

105
        /**
106
         * Retrieve active connection.
107
         * @throws Dibi\Exception
108
         */
109
        public static function getConnection(?string $name = null): Dibi\Connection
1✔
110
        {
111
                if ($name === null) {
1✔
112
                        if (!isset(self::$connection)) {
1✔
113
                                throw new Dibi\Exception('Dibi is not connected to database.');
×
114
                        }
115

116
                        return self::$connection;
1✔
117
                }
118

119
                if (!isset(self::$registry[$name])) {
×
120
                        throw new Dibi\Exception("There is no connection named '$name'.");
×
121
                }
122

123
                return self::$registry[$name];
×
124
        }
125

126

127
        /**
128
         * Sets connection.
129
         */
130
        public static function setConnection(Dibi\Connection $connection): Dibi\Connection
131
        {
132
                return self::$connection = $connection;
×
133
        }
134

135

136
        /********************* monostate for active connection ****************d*g**/
137

138

139
        /**
140
         * Monostate for Dibi\Connection.
141
         * @param  list<mixed>  $args
142
         */
143
        public static function __callStatic(string $name, array $args): mixed
1✔
144
        {
145
                return self::getConnection()->$name(...$args);
1✔
146
        }
147

148

149
        /********************* misc tools ****************d*g**/
150

151

152
        /**
153
         * Prints out a syntax highlighted version of the SQL command or Result.
154
         * @param  bool  $return  return output instead of printing it?
155
         */
156
        public static function dump(string|Dibi\Result|null $sql = null, bool $return = false): ?string
157
        {
158
                return Dibi\Helpers::dump($sql, $return);
×
159
        }
160

161

162
        /**
163
         * Strips microseconds part.
164
         */
165
        public static function stripMicroseconds(DateTimeInterface $dt): DateTimeInterface
1✔
166
        {
167
                $class = $dt::class;
1✔
168
                return new $class($dt->format('Y-m-d H:i:s'), $dt->getTimezone());
1✔
169
        }
170
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc