NameGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 31
rs 10

1 Method

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