NameResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 4 1
A shortClassName() 0 9 2
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Domain\EventSourcing\Utils;
12
13
use Cubiche\Domain\Model\IdInterface;
14
15
/**
16
 * NameResolver class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 */
20
class NameResolver
21
{
22
    /**
23
     * @param string      $aggregateClassName
24
     * @param IdInterface $id
25
     *
26
     * @return string
27
     */
28
    public static function resolve($aggregateClassName, IdInterface $id)
29
    {
30
        return sprintf('%s-%s', self::shortClassName($aggregateClassName), $id->toNative());
31
    }
32
33
    /**
34
     * @param string $aggregateClassName
35
     *
36
     * @return string
37
     */
38
    protected static function shortClassName($aggregateClassName)
39
    {
40
        // If class name has a namespace separator, only take last portion
41
        if (strpos($aggregateClassName, '\\') !== false) {
42
            return substr($aggregateClassName, strrpos($aggregateClassName, '\\') + 1);
43
        }
44
45
        return $aggregateClassName;
46
    }
47
}
48