Completed
Push — master ( 887cf7...2ea773 )
by Emily
02:13
created

AutoConstructTrait::autoBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 2
cts 4
cp 0.5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1.125
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Traits;
16
17
use Spaark\CompositeUtils\Service\PropertyAccessor;
18
19
/**
20
 * Classes with this trait will be able to auto construct their
21
 * properties
22
 */
23
trait AutoConstructTrait
24
{
25
    use HasReflectorTrait;
26
27
    /**
28
     * Creates a new instance of this class, auto constructing the
29
     * properties using a PropertyAccessor
30
     */
31 1
    public function __construct(...$args)
32
    {
33 1
        $this->autoBuild(...$args);
34
    }
35
36
    /**
37
     * Creates a new instance of this class, auto constructing the
38
     * properties using a PropertyAccessor
39
     */
40 1
    protected function autoBuild(...$args)
41
    {
42 1
        (new PropertyAccessor($this, static::getReflectionComposite()))
43
            ->constructObject(...$args);
44
    }
45
}
46
47