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

Value::stringify()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
nc 6
nop 2
dl 0
loc 16
rs 9.2222
c 1
b 0
f 0
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
}