Passed
Push — master ( 924412...d4b74b )
by Jesse
02:02
created

Defaults::to()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping\Simple;
5
6
use Stratadox\Hydration\Mapping\Composite\CompositeMapping;
7
use Stratadox\Hydration\Mapping\FixedMapping;
8
use Stratadox\HydrationMapping\Mapping;
9
10
final class Defaults
11
{
12
    /**
13
     * @param mixed $defaultValue
14
     * @param Mapping $mapping
15
     * @return Mapping
16
     */
17
    public static function to(
18
        $defaultValue,
19
        Mapping $mapping
20
    ): Mapping {
21
        return CompositeMapping::either(
22
            $mapping,
23
            FixedMapping::inProperty($mapping->name(), $defaultValue)
24
        );
25
    }
26
}
27