NameGenerator::name()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Prophecy.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *     Marcello Duarte <[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
namespace Prophecy\Doubler;
13
14
use ReflectionClass;
15
16
/**
17
 * Name generator.
18
 * Generates classname for double.
19
 *
20
 * @author Konstantin Kudryashov <[email protected]>
21
 */
22
class NameGenerator
23
{
24
    private static $counter = 1;
25
26
    /**
27
     * Generates name.
28
     *
29
     * @param ReflectionClass   $class
30
     * @param ReflectionClass[] $interfaces
31
     *
32
     * @return string
33
     */
34
    public function name(ReflectionClass $class = null, array $interfaces)
35
    {
36
        $parts = array();
37
38
        if (null !== $class) {
39
            $parts[] = $class->getName();
40
        } else {
41
            foreach ($interfaces as $interface) {
42
                $parts[] = $interface->getShortName();
43
            }
44
        }
45
46
        if (!count($parts)) {
47
            $parts[] = 'stdClass';
48
        }
49
50
        return sprintf('Double\%s\P%d', implode('\\', $parts), self::$counter++);
51
    }
52
}
53