CastToStringTrait::strval()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 10.5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 3
cts 6
cp 0.5
crap 10.5
rs 9.2222
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