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

VariadicConstructor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forThe() 0 3 1
A fromArray() 0 4 1
A __construct() 0 3 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