Completed
Push — master ( 2cee6a...9d457f )
by Jesse
03:27
created

VariadicConstructor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 4 1
A forThe() 0 3 1
A __construct() 0 3 1
A currentInstance() 0 1 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Stratadox\Hydration\Hydrator;
6
7
use Stratadox\Hydration\Hydrates;
8
9
/**
10
 * Hydrates an object by calling its constructor with squashed array input.
11
 *
12
 * @package Stratadox\Hydrate
13
 * @author Stratadox
14
 */
15
final class VariadicConstructor implements Hydrates
16
{
17
    private $class;
18
19
    private function __construct(string $forTheClass)
20
    {
21
        $this->class = $forTheClass;
22
    }
23
24
    public static function forThe(string $class) : Hydrates
25
    {
26
        return new VariadicConstructor($class);
27
    }
28
29
    public function fromArray(array $input)
30
    {
31
        $class = $this->class;
32
        return new $class(...$input);
33
    }
34
35
    public function currentInstance() {}
36
}
37