Passed
Pull Request — 2.4 (#2990)
by
unknown
11:29 queued 04:35
created

CloneTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A clone() 0 10 4
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