1<?php
2
3/*
4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 *     Marcello Duarte <marcello.duarte@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Prophecy\Doubler;
13
14use ReflectionClass;
15
16/**
17 * Name generator.
18 * Generates classname for double.
19 *
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 */
22class 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