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

codeigniter4 / CodeIgniter4 / 12673986434

08 Jan 2025 03:42PM UTC coverage: 84.455% (+0.001%) from 84.454%
12673986434

Pull #9385

github

web-flow
Merge 06e47f0ee into e475fd8fa
Pull Request #9385: refactor: Fix phpstan expr.resultUnused

20699 of 24509 relevant lines covered (84.45%)

190.57 hits per line

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

42.97
/system/Debug/Exceptions.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Debug;
15

16
use CodeIgniter\API\ResponseTrait;
17
use CodeIgniter\Exceptions\HasExitCodeInterface;
18
use CodeIgniter\Exceptions\HTTPExceptionInterface;
19
use CodeIgniter\Exceptions\PageNotFoundException;
20
use CodeIgniter\HTTP\Exceptions\HTTPException;
21
use CodeIgniter\HTTP\RequestInterface;
22
use CodeIgniter\HTTP\ResponseInterface;
23
use Config\Exceptions as ExceptionsConfig;
24
use Config\Paths;
25
use ErrorException;
26
use Psr\Log\LogLevel;
27
use Throwable;
28

29
/**
30
 * Exceptions manager
31
 *
32
 * @see \CodeIgniter\Debug\ExceptionsTest
33
 */
34
class Exceptions
35
{
36
    use ResponseTrait;
37

38
    /**
39
     * Nesting level of the output buffering mechanism
40
     *
41
     * @var int
42
     *
43
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
44
     */
45
    public $ob_level;
46

47
    /**
48
     * The path to the directory containing the
49
     * cli and html error view directories.
50
     *
51
     * @var string
52
     *
53
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
54
     */
55
    protected $viewPath;
56

57
    /**
58
     * Config for debug exceptions.
59
     *
60
     * @var ExceptionsConfig
61
     */
62
    protected $config;
63

64
    /**
65
     * The request.
66
     *
67
     * @var RequestInterface|null
68
     */
69
    protected $request;
70

71
    /**
72
     * The outgoing response.
73
     *
74
     * @var ResponseInterface
75
     */
76
    protected $response;
77

78
    private ?Throwable $exceptionCaughtByExceptionHandler = null;
79

80
    public function __construct(ExceptionsConfig $config)
81
    {
82
        // For backward compatibility
83
        $this->ob_level = ob_get_level();
12✔
84
        $this->viewPath = rtrim($config->errorViewPath, '\\/ ') . DIRECTORY_SEPARATOR;
12✔
85

86
        $this->config = $config;
12✔
87

88
        // workaround for upgraded users
89
        // This causes "Deprecated: Creation of dynamic property" in PHP 8.2.
90
        // @TODO remove this after dropping PHP 8.1 support.
91
        if (! isset($this->config->sensitiveDataInTrace)) {
12✔
92
            $this->config->sensitiveDataInTrace = [];
×
93
        }
94
        if (! isset($this->config->logDeprecations, $this->config->deprecationLogLevel)) {
12✔
95
            $this->config->logDeprecations     = false;
×
96
            $this->config->deprecationLogLevel = LogLevel::WARNING;
×
97
        }
98
    }
99

100
    /**
101
     * Responsible for registering the error, exception and shutdown
102
     * handling of our application.
103
     *
104
     * @codeCoverageIgnore
105
     *
106
     * @return void
107
     */
108
    public function initialize()
109
    {
110
        set_exception_handler($this->exceptionHandler(...));
3✔
111
        set_error_handler($this->errorHandler(...));
3✔
112
        register_shutdown_function([$this, 'shutdownHandler']);
3✔
113
    }
114

115
    /**
116
     * Catches any uncaught errors and exceptions, including most Fatal errors
117
     * (Yay PHP7!). Will log the error, display it if display_errors is on,
118
     * and fire an event that allows custom actions to be taken at this point.
119
     *
120
     * @return void
121
     */
122
    public function exceptionHandler(Throwable $exception)
123
    {
124
        $this->exceptionCaughtByExceptionHandler = $exception;
×
125

126
        [$statusCode, $exitCode] = $this->determineCodes($exception);
×
127

128
        $this->request = service('request');
×
129

130
        if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
×
131
            $uri       = $this->request->getPath() === '' ? '/' : $this->request->getPath();
×
132
            $routeInfo = '[Method: ' . $this->request->getMethod() . ', Route: ' . $uri . ']';
×
133

134
            log_message('critical', $exception::class . ": {message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
×
135
                'message'   => $exception->getMessage(),
×
136
                'routeInfo' => $routeInfo,
×
137
                'exFile'    => clean_path($exception->getFile()), // {file} refers to THIS file
×
138
                'exLine'    => $exception->getLine(), // {line} refers to THIS line
×
139
                'trace'     => self::renderBacktrace($exception->getTrace()),
×
140
            ]);
×
141

142
            // Get the first exception.
143
            $last = $exception;
×
144

145
            while ($prevException = $last->getPrevious()) {
×
146
                $last = $prevException;
×
147

148
                log_message('critical', '[Caused by] ' . $prevException::class . ": {message}\nin {exFile} on line {exLine}.\n{trace}", [
×
149
                    'message' => $prevException->getMessage(),
×
150
                    'exFile'  => clean_path($prevException->getFile()), // {file} refers to THIS file
×
151
                    'exLine'  => $prevException->getLine(), // {line} refers to THIS line
×
152
                    'trace'   => self::renderBacktrace($prevException->getTrace()),
×
153
                ]);
×
154
            }
155
        }
156

157
        $this->response = service('response');
×
158

159
        if (method_exists($this->config, 'handler')) {
×
160
            // Use new ExceptionHandler
161
            $handler = $this->config->handler($statusCode, $exception);
×
162
            $handler->handle(
×
163
                $exception,
×
164
                $this->request,
×
165
                $this->response,
×
166
                $statusCode,
×
167
                $exitCode
×
168
            );
×
169

170
            return;
×
171
        }
172

173
        // For backward compatibility
174
        if (! is_cli()) {
×
175
            try {
176
                $this->response->setStatusCode($statusCode);
×
177
            } catch (HTTPException) {
×
178
                // Workaround for invalid HTTP status code.
179
                $statusCode = 500;
×
180
                $this->response->setStatusCode($statusCode);
×
181
            }
182

183
            if (! headers_sent()) {
×
184
                header(sprintf('HTTP/%s %s %s', $this->request->getProtocolVersion(), $this->response->getStatusCode(), $this->response->getReasonPhrase()), true, $statusCode);
×
185
            }
186

187
            if (! str_contains($this->request->getHeaderLine('accept'), 'text/html')) {
×
188
                $this->respond(ENVIRONMENT === 'development' ? $this->collectVars($exception, $statusCode) : '', $statusCode)->send();
×
189

190
                exit($exitCode);
×
191
            }
192
        }
193

194
        $this->render($exception, $statusCode);
×
195

196
        exit($exitCode);
×
197
    }
198

199
    /**
200
     * The callback to be registered to `set_error_handler()`.
201
     *
202
     * @return bool
203
     *
204
     * @throws ErrorException
205
     *
206
     * @codeCoverageIgnore
207
     */
208
    public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null)
209
    {
210
        if ($this->isDeprecationError($severity)) {
81✔
211
            if ($this->isSessionSidDeprecationError($message, $file, $line)) {
2✔
212
                return true;
×
213
            }
214

215
            if ($this->isImplicitNullableDeprecationError($message, $file, $line)) {
2✔
216
                return true;
×
217
            }
218

219
            if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) {
2✔
220
                throw new ErrorException($message, 0, $severity, $file, $line);
×
221
            }
222

223
            return $this->handleDeprecationError($message, $file, $line);
2✔
224
        }
225

226
        if ((error_reporting() & $severity) !== 0) {
79✔
227
            throw new ErrorException($message, 0, $severity, $file, $line);
46✔
228
        }
229

230
        return false; // return false to propagate the error to PHP standard error handler
33✔
231
    }
232

233
    /**
234
     * Handles session.sid_length and session.sid_bits_per_character deprecations
235
     * in PHP 8.4.
236
     */
237
    private function isSessionSidDeprecationError(string $message, ?string $file = null, ?int $line = null): bool
238
    {
239
        if (
240
            PHP_VERSION_ID >= 80400
2✔
241
            && str_contains($message, 'session.sid_')
2✔
242
        ) {
243
            log_message(
×
244
                LogLevel::WARNING,
×
245
                '[DEPRECATED] {message} in {errFile} on line {errLine}.',
×
246
                [
×
247
                    'message' => $message,
×
248
                    'errFile' => clean_path($file ?? ''),
×
249
                    'errLine' => $line ?? 0,
×
250
                ]
×
251
            );
×
252

253
            return true;
×
254
        }
255

256
        return false;
2✔
257
    }
258

259
    /**
260
     * Workaround to implicit nullable deprecation errors in PHP 8.4.
261
     *
262
     * "Implicitly marking parameter $xxx as nullable is deprecated,
263
     *  the explicit nullable type must be used instead"
264
     *
265
     * @TODO remove this before v4.6.0 release
266
     */
267
    private function isImplicitNullableDeprecationError(string $message, ?string $file = null, ?int $line = null): bool
268
    {
269
        if (
270
            PHP_VERSION_ID >= 80400
2✔
271
            && str_contains($message, 'the explicit nullable type must be used instead')
2✔
272
            // Only Kint and Faker, which cause this error, are logged.
273
            && (str_starts_with($message, 'Kint\\') || str_starts_with($message, 'Faker\\'))
2✔
274
        ) {
275
            log_message(
×
276
                LogLevel::WARNING,
×
277
                '[DEPRECATED] {message} in {errFile} on line {errLine}.',
×
278
                [
×
279
                    'message' => $message,
×
280
                    'errFile' => clean_path($file ?? ''),
×
281
                    'errLine' => $line ?? 0,
×
282
                ]
×
283
            );
×
284

285
            return true;
×
286
        }
287

288
        return false;
2✔
289
    }
290

291
    /**
292
     * Checks to see if any errors have happened during shutdown that
293
     * need to be caught and handle them.
294
     *
295
     * @codeCoverageIgnore
296
     *
297
     * @return void
298
     */
299
    public function shutdownHandler()
300
    {
301
        $error = error_get_last();
×
302

303
        if ($error === null) {
×
304
            return;
×
305
        }
306

307
        ['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error;
×
308

309
        if ($this->exceptionCaughtByExceptionHandler instanceof Throwable) {
×
310
            $message .= "\n【Previous Exception】\n"
×
311
                . $this->exceptionCaughtByExceptionHandler::class . "\n"
×
312
                . $this->exceptionCaughtByExceptionHandler->getMessage() . "\n"
×
313
                . $this->exceptionCaughtByExceptionHandler->getTraceAsString();
×
314
        }
315

316
        if (in_array($type, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE], true)) {
×
317
            $this->exceptionHandler(new ErrorException($message, 0, $type, $file, $line));
×
318
        }
319
    }
320

321
    /**
322
     * Determines the view to display based on the exception thrown,
323
     * whether an HTTP or CLI request, etc.
324
     *
325
     * @return string The path and filename of the view file to use
326
     *
327
     * @deprecated 4.4.0 No longer used. Moved to ExceptionHandler.
328
     */
329
    protected function determineView(Throwable $exception, string $templatePath): string
330
    {
331
        // Production environments should have a custom exception file.
332
        $view         = 'production.php';
1✔
333
        $templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR;
1✔
334

335
        if (
336
            in_array(
1✔
337
                strtolower(ini_get('display_errors')),
1✔
338
                ['1', 'true', 'on', 'yes'],
1✔
339
                true
1✔
340
            )
1✔
341
        ) {
342
            $view = 'error_exception.php';
1✔
343
        }
344

345
        // 404 Errors
346
        if ($exception instanceof PageNotFoundException) {
1✔
347
            return 'error_404.php';
1✔
348
        }
349

350
        // Allow for custom views based upon the status code
351
        if (is_file($templatePath . 'error_' . $exception->getCode() . '.php')) {
1✔
352
            return 'error_' . $exception->getCode() . '.php';
1✔
353
        }
354

355
        return $view;
1✔
356
    }
357

358
    /**
359
     * Given an exception and status code will display the error to the client.
360
     *
361
     * @return void
362
     *
363
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
364
     */
365
    protected function render(Throwable $exception, int $statusCode)
366
    {
367
        // Determine possible directories of error views
368
        $path    = $this->viewPath;
×
369
        $altPath = rtrim((new Paths())->viewDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'errors' . DIRECTORY_SEPARATOR;
×
370

371
        $path    .= (is_cli() ? 'cli' : 'html') . DIRECTORY_SEPARATOR;
×
372
        $altPath .= (is_cli() ? 'cli' : 'html') . DIRECTORY_SEPARATOR;
×
373

374
        // Determine the views
375
        $view    = $this->determineView($exception, $path);
×
376
        $altView = $this->determineView($exception, $altPath);
×
377

378
        // Check if the view exists
379
        if (is_file($path . $view)) {
×
380
            $viewFile = $path . $view;
×
381
        } elseif (is_file($altPath . $altView)) {
×
382
            $viewFile = $altPath . $altView;
×
383
        }
384

385
        if (! isset($viewFile)) {
×
386
            echo 'The error view files were not found. Cannot render exception trace.';
×
387

388
            exit(1);
×
389
        }
390

391
        echo (function () use ($exception, $statusCode, $viewFile): string {
×
392
            $vars = $this->collectVars($exception, $statusCode);
×
393
            extract($vars, EXTR_SKIP);
×
394

395
            ob_start();
×
396
            include $viewFile;
×
397

398
            return ob_get_clean();
×
399
        })();
×
400
    }
401

402
    /**
403
     * Gathers the variables that will be made available to the view.
404
     *
405
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
406
     */
407
    protected function collectVars(Throwable $exception, int $statusCode): array
408
    {
409
        // Get the first exception.
410
        $firstException = $exception;
1✔
411

412
        while ($prevException = $firstException->getPrevious()) {
1✔
413
            $firstException = $prevException;
×
414
        }
415

416
        $trace = $firstException->getTrace();
1✔
417

418
        if ($this->config->sensitiveDataInTrace !== []) {
1✔
419
            $trace = $this->maskSensitiveData($trace, $this->config->sensitiveDataInTrace);
×
420
        }
421

422
        return [
1✔
423
            'title'   => $exception::class,
1✔
424
            'type'    => $exception::class,
1✔
425
            'code'    => $statusCode,
1✔
426
            'message' => $exception->getMessage(),
1✔
427
            'file'    => $exception->getFile(),
1✔
428
            'line'    => $exception->getLine(),
1✔
429
            'trace'   => $trace,
1✔
430
        ];
1✔
431
    }
432

433
    /**
434
     * Mask sensitive data in the trace.
435
     *
436
     * @param array $trace
437
     *
438
     * @return array
439
     *
440
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
441
     */
442
    protected function maskSensitiveData($trace, array $keysToMask, string $path = '')
443
    {
444
        foreach ($trace as $i => $line) {
2✔
445
            $trace[$i]['args'] = $this->maskData($line['args'], $keysToMask);
2✔
446
        }
447

448
        return $trace;
2✔
449
    }
450

451
    /**
452
     * @param array|object $args
453
     *
454
     * @return array|object
455
     *
456
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
457
     */
458
    private function maskData($args, array $keysToMask, string $path = '')
459
    {
460
        foreach ($keysToMask as $keyToMask) {
2✔
461
            $explode = explode('/', $keyToMask);
2✔
462
            $index   = end($explode);
2✔
463

464
            if (str_starts_with(strrev($path . '/' . $index), strrev($keyToMask))) {
2✔
465
                if (is_array($args) && array_key_exists($index, $args)) {
2✔
466
                    $args[$index] = '******************';
1✔
467
                } elseif (
468
                    is_object($args) && property_exists($args, $index)
2✔
469
                    && isset($args->{$index}) && is_scalar($args->{$index})
2✔
470
                ) {
471
                    $args->{$index} = '******************';
1✔
472
                }
473
            }
474
        }
475

476
        if (is_array($args)) {
2✔
477
            foreach ($args as $pathKey => $subarray) {
2✔
478
                $args[$pathKey] = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
1✔
479
            }
480
        } elseif (is_object($args)) {
1✔
481
            foreach ($args as $pathKey => $subarray) {
1✔
482
                $args->{$pathKey} = $this->maskData($subarray, $keysToMask, $path . '/' . $pathKey);
1✔
483
            }
484
        }
485

486
        return $args;
2✔
487
    }
488

489
    /**
490
     * Determines the HTTP status code and the exit status code for this request.
491
     */
492
    protected function determineCodes(Throwable $exception): array
493
    {
494
        $statusCode = 500;
1✔
495
        $exitStatus = EXIT_ERROR;
1✔
496

497
        if ($exception instanceof HTTPExceptionInterface) {
1✔
498
            $statusCode = $exception->getCode();
×
499
        }
500

501
        if ($exception instanceof HasExitCodeInterface) {
1✔
502
            $exitStatus = $exception->getExitCode();
1✔
503
        }
504

505
        return [$statusCode, $exitStatus];
1✔
506
    }
507

508
    private function isDeprecationError(int $error): bool
509
    {
510
        $deprecations = E_DEPRECATED | E_USER_DEPRECATED;
81✔
511

512
        return ($error & $deprecations) !== 0;
81✔
513
    }
514

515
    /**
516
     * @return true
517
     */
518
    private function handleDeprecationError(string $message, ?string $file = null, ?int $line = null): bool
519
    {
520
        // Remove the trace of the error handler.
521
        $trace = array_slice(debug_backtrace(), 2);
2✔
522

523
        log_message(
2✔
524
            $this->config->deprecationLogLevel,
2✔
525
            "[DEPRECATED] {message} in {errFile} on line {errLine}.\n{trace}",
2✔
526
            [
2✔
527
                'message' => $message,
2✔
528
                'errFile' => clean_path($file ?? ''),
2✔
529
                'errLine' => $line ?? 0,
2✔
530
                'trace'   => self::renderBacktrace($trace),
2✔
531
            ]
2✔
532
        );
2✔
533

534
        return true;
2✔
535
    }
536

537
    // --------------------------------------------------------------------
538
    // Display Methods
539
    // --------------------------------------------------------------------
540

541
    /**
542
     * This makes nicer looking paths for the error output.
543
     *
544
     * @deprecated Use dedicated `clean_path()` function.
545
     */
546
    public static function cleanPath(string $file): string
547
    {
548
        return match (true) {
549
            str_starts_with($file, APPPATH)                             => 'APPPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(APPPATH)),
×
550
            str_starts_with($file, SYSTEMPATH)                          => 'SYSTEMPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(SYSTEMPATH)),
×
551
            str_starts_with($file, FCPATH)                              => 'FCPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(FCPATH)),
×
552
            defined('VENDORPATH') && str_starts_with($file, VENDORPATH) => 'VENDORPATH' . DIRECTORY_SEPARATOR . substr($file, strlen(VENDORPATH)),
×
553
            default                                                     => $file,
×
554
        };
555
    }
556

557
    /**
558
     * Describes memory usage in real-world units. Intended for use
559
     * with memory_get_usage, etc.
560
     *
561
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
562
     */
563
    public static function describeMemory(int $bytes): string
564
    {
565
        if ($bytes < 1024) {
×
566
            return $bytes . 'B';
×
567
        }
568

569
        if ($bytes < 1_048_576) {
×
570
            return round($bytes / 1024, 2) . 'KB';
×
571
        }
572

573
        return round($bytes / 1_048_576, 2) . 'MB';
×
574
    }
575

576
    /**
577
     * Creates a syntax-highlighted version of a PHP file.
578
     *
579
     * @return bool|string
580
     *
581
     * @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
582
     */
583
    public static function highlightFile(string $file, int $lineNumber, int $lines = 15)
584
    {
585
        if ($file === '' || ! is_readable($file)) {
×
586
            return false;
×
587
        }
588

589
        // Set our highlight colors:
590
        if (function_exists('ini_set')) {
×
591
            ini_set('highlight.comment', '#767a7e; font-style: italic');
×
592
            ini_set('highlight.default', '#c7c7c7');
×
593
            ini_set('highlight.html', '#06B');
×
594
            ini_set('highlight.keyword', '#f1ce61;');
×
595
            ini_set('highlight.string', '#869d6a');
×
596
        }
597

598
        try {
599
            $source = file_get_contents($file);
×
600
        } catch (Throwable) {
×
601
            return false;
×
602
        }
603

604
        $source = str_replace(["\r\n", "\r"], "\n", $source);
×
605
        $source = explode("\n", highlight_string($source, true));
×
606
        $source = str_replace('<br />', "\n", $source[1]);
×
607
        $source = explode("\n", str_replace("\r\n", "\n", $source));
×
608

609
        // Get just the part to show
610
        $start = max($lineNumber - (int) round($lines / 2), 0);
×
611

612
        // Get just the lines we need to display, while keeping line numbers...
613
        $source = array_splice($source, $start, $lines, true);
×
614

615
        // Used to format the line number in the source
616
        $format = '% ' . strlen((string) ($start + $lines)) . 'd';
×
617

618
        $out = '';
×
619
        // Because the highlighting may have an uneven number
620
        // of open and close span tags on one line, we need
621
        // to ensure we can close them all to get the lines
622
        // showing correctly.
623
        $spans = 1;
×
624

625
        foreach ($source as $n => $row) {
×
626
            $spans += substr_count($row, '<span') - substr_count($row, '</span');
×
627
            $row = str_replace(["\r", "\n"], ['', ''], $row);
×
628

629
            if (($n + $start + 1) === $lineNumber) {
×
630
                preg_match_all('#<[^>]+>#', $row, $tags);
×
631

632
                $out .= sprintf(
×
633
                    "<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s",
×
634
                    $n + $start + 1,
×
635
                    strip_tags($row),
×
636
                    implode('', $tags[0])
×
637
                );
×
638
            } else {
639
                $out .= sprintf('<span class="line"><span class="number">' . $format . '</span> %s', $n + $start + 1, $row) . "\n";
×
640
            }
641
        }
642

643
        if ($spans > 0) {
×
644
            $out .= str_repeat('</span>', $spans);
×
645
        }
646

647
        return '<pre><code>' . $out . '</code></pre>';
×
648
    }
649

650
    private static function renderBacktrace(array $backtrace): string
651
    {
652
        $backtraces = [];
3✔
653

654
        foreach ($backtrace as $index => $trace) {
3✔
655
            $frame = $trace + ['file' => '[internal function]', 'line' => '', 'class' => '', 'type' => '', 'args' => []];
3✔
656

657
            if ($frame['file'] !== '[internal function]') {
3✔
658
                $frame['file'] = sprintf('%s(%s)', $frame['file'], $frame['line']);
3✔
659
            }
660

661
            unset($frame['line']);
3✔
662
            $idx = $index;
3✔
663
            $idx = str_pad((string) ++$idx, 2, ' ', STR_PAD_LEFT);
3✔
664

665
            $args = implode(', ', array_map(static fn ($value): string => match (true) {
3✔
666
                is_object($value)   => sprintf('Object(%s)', $value::class),
3✔
667
                is_array($value)    => $value !== [] ? '[...]' : '[]',
3✔
668
                $value === null     => 'null',
3✔
669
                is_resource($value) => sprintf('resource (%s)', get_resource_type($value)),
3✔
670
                default             => var_export($value, true),
3✔
671
            }, $frame['args']));
3✔
672

673
            $backtraces[] = sprintf(
3✔
674
                '%s %s: %s%s%s(%s)',
3✔
675
                $idx,
3✔
676
                clean_path($frame['file']),
3✔
677
                $frame['class'],
3✔
678
                $frame['type'],
3✔
679
                $frame['function'],
3✔
680
                $args
3✔
681
            );
3✔
682
        }
683

684
        return implode("\n", $backtraces);
3✔
685
    }
686
}
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