CloneableTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A cloneObject() 0 10 2
1
<?php
2
3
namespace DMT\Aura\Psr\Helpers;
4
5
trait CloneableTrait
6
{
7
    /** @var object $object */
8
    private $object;
9
10
    /**
11
     * CloneableTrait constructor.
12
     *
13
     * @param object $object the object to clone.
14
     */
15 74
    public function __construct($object)
16
    {
17 74
        $this->object = $object;
18 74
    }
19
20
    /**
21
     * Clone an object.
22
     *
23
     * @return object
24
     */
25 44
    public function cloneObject()
26
    {
27 44
        $object = clone($this->object);
28
29 44
        $objectProperties = array_filter(get_object_vars($object), 'is_object');
30 44
        foreach ($objectProperties as $property => $values) {
31 44
            $object->{$property} = clone($values);
32
        }
33
34 44
        return $object;
35
    }
36
}
37