CastToStringTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 3
cts 6
cp 0.5
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A strval() 0 10 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\CfdiToPdf\Internal;
6
7
use Stringable;
8
9
/**
10
 * @internal
11
 */
12
trait CastToStringTrait
13
{
14
    /** @param mixed $value */
15 4
    private function strval($value): string
16
    {
17 4
        if (is_string($value)) {
18 4
            return $value;
19
        }
20
        if (null === $value || is_scalar($value) || (is_object($value) && is_callable([$value, '__toString']))) {
21
            /** @phpstan-var null|scalar|Stringable $value */
22
            return strval($value);
23
        }
24
        return '';
25
    }
26
}
27