Completed
Push — master ( 9d457f...574e8f )
by Jesse
02:48
created

VariadicConstructor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Stratadox\Hydrator;
6
7
/**
8
 * Hydrates an object by calling its constructor with squashed array input.
9
 *
10
 * @package Stratadox\Hydrate
11
 * @author Stratadox
12
 */
13
final class VariadicConstructor implements Hydrates
14
{
15
    private $class;
16
17
    private function __construct(string $forTheClass)
18
    {
19
        $this->class = $forTheClass;
20
    }
21
22
    /**
23
     * Creates a new variadic constructor calling hydrator.
24
     *
25
     * @param string $class The class to hydrate.
26
     * @return self         The variadic construction calling hydrator.
27
     */
28
    public static function forThe(string $class) : self
29
    {
30
        return new self($class);
31
    }
32
33
    /** @inheritdoc */
34
    public function fromArray(array $input)
35
    {
36
        $class = $this->class;
37
        return new $class(...$input);
38
    }
39
}
40