Passed
Push — master ( ec5386...e56f88 )
by Andrey
53s queued 14s
created

dumprr()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 36
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 16
c 1
b 0
f 0
nc 8
nop 2
dl 0
loc 36
rs 9.7333
1
<?php
2
3
declare(strict_types=1);
4
5
use Symfony\Component\VarDumper\Caster\ReflectionCaster;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\VarDum...Caster\ReflectionCaster was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\VarDumper\Cloner\VarCloner;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\VarDumper\Cloner\VarCloner was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\VarDumper\Dumper\CliDumper;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\VarDumper\Dumper\CliDumper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\VarDumper\VarDumper;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\VarDumper\VarDumper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
if (!\function_exists('dumprr')) {
11
    /**
12
     * This function is designed to dump a value within your application while using RoadRunner server.
13
     * RoadRunner does not allow data to be sent through STDIN, the output must be sent to STDERR instead.
14
     */
15
    function dumprr(mixed $value, mixed ...$values): mixed
16
    {
17
        $previous = $_SERVER['VAR_DUMPER_FORMAT'] ?? false;
18
        unset($_SERVER['VAR_DUMPER_FORMAT']);
19
20
        if (!\defined('STDERR')) {
21
            \define('STDERR', \fopen('php://stderr', 'wb'));
22
        }
23
        static $dumper = new CliDumper(STDERR);
24
25
        //
26
        // Output modifiers
27
        //
28
        $cloner = new VarCloner();
29
        // remove File and Line definitions from a custom closure dump
30
        /** @psalm-suppress InvalidArgument */
31
        $cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
32
33
        // Set new handler and store previous one
34
        $prevent = VarDumper::setHandler(
35
            static fn (mixed $value): ?string => $dumper->dump($cloner->cloneVar($value)),
36
        );
37
        $result = VarDumper::dump($value);
38
39
        foreach ($values as $v) {
40
            VarDumper::dump($v);
41
        }
42
43
        // Reset handler
44
        VarDumper::setHandler($prevent);
45
46
        if ($previous) {
47
            $_SERVER['VAR_DUMPER_FORMAT'] = $previous;
48
        }
49
50
        return $result;
51
    }
52
}
53