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

contributte / dev / 5642497232

pending completion
5642497232

push

github

f3l1x
Code: modernize, PHP 8.1, nette/utils 4.x

17 of 17 new or added lines in 2 files covered. (100.0%)

4 of 105 relevant lines covered (3.81%)

0.04 hits per line

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

2.9
/src/Dev.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Dev;
4

5
use Nette\StaticClass;
6
use Nette\Utils\Json;
7
use RuntimeException;
8
use Tracy\Debugger;
9
use Tracy\Helpers;
10
use Traversable;
11

12
class Dev
13
{
14

15
        use StaticClass;
16

17
        /**
18
         * Dump;
19
         */
20
        public static function d(): void
21
        {
22
                foreach (func_get_args() as $var) {
×
23
                        dump($var);
×
24
                }
25
        }
26

27
        /**
28
         * Dump; die;
29
         */
30
        public static function dd(): void
31
        {
32
                self::d(...func_get_args());
×
33
                die;
×
34
        }
35

36
        /**
37
         * echo;die
38
         *
39
         * @param scalar $value
40
         */
41
        public static function ed(mixed $value): void
42
        {
43
                echo $value;
×
44
                die;
×
45
        }
46

47
        /**
48
         * Foreach dump;
49
         *
50
         * @param array<mixed|mixed[]> $values
51
         */
52
        public static function fd(array $values): void
53
        {
54
                foreach ($values as $value) {
×
55
                        if ($value instanceof Traversable) {
×
56
                                $value = iterator_to_array($value);
×
57
                        }
58

59
                        dump($value);
×
60
                        echo "<hr style='border:0px;border-top:1px solid #DDD;height:0px;'>";
×
61
                }
62
        }
63

64
        /**
65
         * Foreach dump;die;
66
         *
67
         * @param mixed[] $values
68
         */
69
        public static function fdd(array $values): void
70
        {
71
                self::fd($values);
×
72
                die;
×
73
        }
74

75
        /**
76
         * Table dump;
77
         *
78
         * @param mixed[] $values
79
         */
80
        public static function td(array $values): void
81
        {
82
                echo "<table border=1 style='border-color:#DDD;border-collapse:collapse; font-family:Courier New; color:#222; font-size:13px' cellspacing=0 cellpadding=5>";
×
83
                $th = false;
×
84
                foreach ($values as $value) {
×
85
                        if (!$th) {
×
86
                                echo '<tr>';
×
87
                                foreach ((array) $value as $key2 => $value2) {
×
88
                                        echo '<th>' . $key2 . '</th>';
×
89
                                }
90

91
                                echo '</tr>';
×
92
                        }
93

94
                        $th = true;
×
95

96
                        echo '<tr>';
×
97
                        foreach ((array) $value as $key2 => $value2) {
×
98
                                echo '<td>' . $value2 . '</td>';
×
99
                        }
100

101
                        echo '</tr>';
×
102
                }
103

104
                echo '</table>';
×
105
        }
106

107
        /**
108
         * Table dump;die;
109
         *
110
         * @param mixed[] $values
111
         */
112
        public static function tdd(array $values): void
113
        {
114
                self::td($values);
×
115
                die;
×
116
        }
117

118
        /**
119
         * Bar dump shortcut.
120
         */
121
        public static function bd(mixed $var, ?string $title = null): mixed
122
        {
123
                $trace = debug_backtrace();
×
124
                $traceTitle = (isset($trace[1]['class']) ? htmlspecialchars($trace[1]['class']) . '->' : null) .
×
125
                        htmlspecialchars($trace[1]['function']) . '():';
×
126

127
                if ($title === null) {
×
128
                        foreach (func_get_args() as $arg) {
×
129
                                Debugger::barDump($arg, $traceTitle);
×
130
                        }
131

132
                        return $var;
×
133
                }
134

135
                return Debugger::barDump($var, $title);
×
136
        }
137

138
        /**
139
         * Function prints from where were method/function called
140
         */
141
        public static function wc(int $level = 1, bool $return = false, bool $fullTrace = false): mixed
142
        {
143
                $o = fn ($t) => (isset($t->class) ? htmlspecialchars($t->class) . '->' : null) . htmlspecialchars($t->function) . '()';
×
144
                $f = fn ($t) => isset($t->file) ? '(' . Helpers::editorLink($t->file, $t->line ?? null) . ')' : null;
×
145

146
                $trace = debug_backtrace();
×
147
                $target = (object) $trace[$level];
×
148
                $caller = (object) $trace[$level + 1];
×
149
                $message = null;
×
150

151
                if ($fullTrace) {
×
152
                        array_shift($trace);
×
153
                        foreach ($trace as $call) {
×
154
                                $message .= $o((object) $call) . " \n";
×
155
                        }
156
                } else {
157
                        $message = $o($target) . ' called from ' . $o($caller) . $f($caller);
×
158
                }
159

160
                if ($return) {
×
161
                        return strip_tags((string) $message);
×
162
                }
163

164
                echo "<pre class='nette-dump'>" . nl2br((string) $message) . '</pre>';
×
165

166
                return null;
×
167
        }
168

169
        /**
170
         * Function prints from where were method/function called
171
         */
172
        public static function fwc(int $level = 3, bool $return = false): void
173
        {
174
                self::wc($level, $return, true);
×
175
        }
176

177
        /**
178
         * Convert script into shortcut; exit;
179
         */
180
        public static function ss(string $code): void
181
        {
182
                $array = [
×
183
                        "\t" => "\\t",
184
                        "\n" => "\\n",
185
                ];
186

187
                echo strtr($code, $array);
×
188
                exit;
×
189
        }
190

191
        /**
192
         * Show debug bar
193
         */
194
        public static function e(): void
195
        {
196
                throw new RuntimeException('debug');
×
197
        }
198

199
        /**
200
         * Log message (alias for log)
201
         */
202
        public static function l(string $message): void
203
        {
204
                self::log($message);
×
205
        }
206

207
        /**
208
         * Log message
209
         */
210
        public static function log(string $message): void
211
        {
212
                $message = array_map(fn ($message) => !is_scalar($message) ? Json::encode($message) : $message, func_get_args());
×
213

214
                Debugger::log(implode(', ', $message));
×
215
        }
216

217
        /**
218
         * Show debug bar and dump $arg
219
         */
220
        public static function erd(): void
221
        {
222
                $e = new RuntimeException();
×
223
                fd(func_get_args());
×
224
                echo '<hr />';
×
225
                fd($e->getTrace());
×
226
                echo '<hr />';
×
227
        }
228

229
        /**
230
         * PHP workaround for direct usage of created class
231
         *
232
         * <code>
233
         * // echo (new Person)->name; // does not work in PHP
234
         * echo c(new Person)->name;
235
         * </code>
236
         */
237
        public static function c(object $instance): object
238
        {
239
                return $instance;
×
240
        }
241

242
        /**
243
         * PHP workaround for direct usage of cloned instances
244
         *
245
         * <code>
246
         * echo cl($startTime)->modify('+1 day')->format('Y-m-d');
247
         * </code>
248
         */
249
        public static function cl(object $instance): object
250
        {
251
                return clone $instance;
×
252
        }
253

254
        /**
255
         * PHP callback workaround
256
         *
257
         * @return array{object, string}
258
         */
259
        public static function callback(object $obj, string $method): array
1✔
260
        {
261
                return [$obj, $method];
1✔
262
        }
263

264
}
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

© 2025 Coveralls, Inc