Passed
Push — master ( 200d88...9b81d7 )
by Alec
02:43 queued 15s
created

Value   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 19
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A stringify() 0 16 6
1
<?php
2
3
declare(strict_types=1);
4
// 25.03.23
5
namespace AlecRabbit\Spinner\Helper;
6
7
final class Value
8
{
9
10
    public static function stringify(mixed $value, bool $unwrap = true): string
11
    {
12
        $type = gettype($value);
13
        if (!$unwrap) {
14
            return $type;
15
        }
16
        if (is_scalar($value)) {
17
            if (is_bool($value)) {
18
                $value = $value ? 'true' : 'false';
19
            }
20
            return sprintf('%s(%s)', $type, $value);
21
        }
22
        if (is_object($value)) {
23
            return sprintf('%s(%s)', $type, get_class($value));
24
        }
25
        return $type;
26
    }
27
}