Completed
Push — 2.4 ( f1802e...ee4bf8 )
by Kévin
26s queued 12s
created

CloneTrait::clone()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Util;
15
16
/**
17
 * Clones given data if cloneable.
18
 *
19
 * @internal
20
 *
21
 * @author Quentin Barloy <[email protected]>
22
 */
23
trait CloneTrait
24
{
25
    public function clone($data)
26
    {
27
        if (!\is_object($data)) {
28
            return $data;
29
        }
30
31
        try {
32
            return (new \ReflectionClass($data))->isCloneable() ? clone $data : null;
33
        } catch (\ReflectionException $reflectionException) {
34
            return null;
35
        }
36
    }
37
}
38