Passed
Pull Request — master (#817)
by Maxim
07:12
created

Trace   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 7 2
A stringifyValue() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Internal;
6
7
use Closure;
8
use ReflectionFunction;
9
use Spiral\Core\Exception\Traits\ClosureRendererTrait;
10
11
/**
12
 * @internal
13
 */
14
final class Trace implements \Stringable
15
{
16
    use ClosureRendererTrait;
0 ignored issues
show
Bug introduced by
The trait Spiral\Core\Exception\Traits\ClosureRendererTrait requires the property $class which is not provided by Spiral\Core\Internal\Trace.
Loading history...
17
18 742
    public function __construct(
19
        public readonly string $alias,
20
        public array $info,
21
    ) {
22
    }
23
24 421
    public function __toString(): string
25
    {
26 421
        $info = [$this->alias];
27 421
        foreach ($this->info as $key => $item) {
28 421
            $info[] = "$key: {$this->stringifyValue($item)}";
29
        }
30 421
        return \implode("\n", $info);
31
    }
32
33 421
    private function stringifyValue(mixed $item): string
34
    {
35
        return match (true) {
36 421
            \is_string($item) => "'$item'",
37 414
            \is_scalar($item) => (string)$item,
38 414
            $item instanceof Closure => $this->renderClosureSignature(new ReflectionFunction($item)),
39 414
            \is_object($item) => 'instance of ' . $item::class,
40 421
            default => \gettype($item),
41
        };
42
    }
43
}
44