Passed
Push — master ( 01c6a8...5a4258 )
by Jesse
09:00
created

CanBeBoolean::value()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 15
rs 9.9
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping\Property\Type;
5
6
use Stratadox\Hydration\Mapping\Composite\CompositeMapping;
7
use Stratadox\Hydration\Mapping\Primitive\BooleanMapping;
8
use Stratadox\Hydration\Mapping\Property\Keyed;
9
use Stratadox\HydrationMapping\KeyedMapping;
10
11
final class CanBeBoolean
12
{
13
    public static function or(KeyedMapping $mapping): KeyedMapping
14
    {
15
        return Keyed::mapping($mapping->key(),
16
            CompositeMapping::either(
17
                BooleanMapping::inProperty($mapping->key()),
18
                $mapping
19
            )
20
        );
21
    }
22
23
    public static function orCustom(
24
        KeyedMapping $mapping,
25
        array $truths,
26
        array $falsehoods
27
    ): KeyedMapping {
28
        return Keyed::mapping($mapping->key(),
29
            CompositeMapping::either(
30
                BooleanMapping::custom($mapping->key(), $truths, $falsehoods),
31
                $mapping
32
            )
33
        );
34
    }
35
}
36