UnitTestPublicReferenceGenerator::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * File was created 12.10.2015 06:53
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Helper;
7
8
use PeekAndPoke\Component\Slumber\Data\Addon\PublicReference\PublicReferenceGenerator;
9
10
/**
11
 * @author Karsten J. Gerber <[email protected]>
12
 */
13
class UnitTestPublicReferenceGenerator implements PublicReferenceGenerator
14
{
15
    private $used = [];
16
17
    /**
18
     * @param mixed $subject The object to create a public unique reference for
19
     *
20
     * @return string
21
     */
22 26
    public function create($subject)
23
    {
24 26
        $reflect = new \ReflectionClass($subject);
25
26
        do {
27 26
            $reference = $reflect->getName() . '@' . mt_rand();
0 ignored issues
show
Bug introduced by
Consider using $reflect->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
28 26
        } while (\in_array($reference, $this->used, true));
29
30 26
        $this->used[] = $reference;
31
32 26
        return $reference;
33
    }
34
}
35