Completed
Push — master ( 703b67...f51a8f )
by Emily
02:01
created

AutoConstructTrait::autoBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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 6
    public function __construct(...$args)
32
    {
33 6
        $this->autoBuild(...$args);
34 5
    }
35
36
    /**
37
     * Creates a new instance of this class, auto constructing the
38
     * properties using a PropertyAccessor
39
     */
40 6
    protected function autoBuild(...$args)
41
    {
42 6
        (new PropertyAccessor($this, static::getReflectionComposite()))
43 6
            ->constructObject(...$args);
44 5
    }
45
}
46
47