Choose::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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