Choose   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A with() 0 4 1
A finish() 0 3 1
A the() 0 3 1
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapper\Instruction\Relation;
5
6
use Stratadox\Hydration\Mapper\Mapper;
7
use Stratadox\HydrationMapper\InstructsHowToMap;
8
use Stratadox\HydrationMapper\MakesMap;
9
use Stratadox\HydrationMapper\RepresentsChoice;
10
use Stratadox\Hydrator\Hydrates;
11
12
/**
13
 * Indicates a choice for one of several concrete types.
14
 *
15
 * @package Stratadox\Hydrate
16
 * @author  Stratadox
17
 */
18
final class Choose implements RepresentsChoice
19
{
20
    private $class;
21
22
    private function __construct(MakesMap $class)
23
    {
24
        $this->class = $class;
25
    }
26
27
    /**
28
     * Creates a new option to choose from.
29
     *
30
     * @param string $class     The fully qualified name of the class that can
31
     *                          be chosen.
32
     * @return RepresentsChoice The object representation of the choice.
33
     */
34
    public static function the(string $class): RepresentsChoice
35
    {
36
        return new Choose(Mapper::forThe($class));
37
    }
38
39
    /** @inheritdoc */
40
    public function with(string $property, InstructsHowToMap $howToMap = null): RepresentsChoice
41
    {
42
        $this->class = $this->class->property($property, $howToMap);
43
        return $this;
44
    }
45
46
    /** @inheritdoc */
47
    public function finish(): Hydrates
48
    {
49
        return $this->class->finish();
50
    }
51
}
52