Passed
Pull Request — 2.4 (#2990)
by
unknown
09:03
created

CloneTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A clone() 0 6 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
 * Clone given data if cloneable.
18
 *
19
 * @internal
20
 *
21
 * @author Quentin Barloy <[email protected]>
22
 */
23
trait CloneTrait
24
{
25
    public function clone($data): bool
26
    {
27
        try {
28
            return \is_object($data) && (new \ReflectionClass(\get_class($data)))->isCloneable() ? clone $data : $data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_object($data) ...) ? clone $data : $data could return the type object which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
29
        } catch (\ReflectionException $reflectionException) {
30
            return $data;
31
        }
32
    }
33
}
34