MethodWithShortObjectNameResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A resolve() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName;
12
13
/**
14
 * MethodWithShortObjectNameResolver class.
15
 *
16
 * Examples:
17
 *  - Cubiche\Application\Command\ChangeTitleCommand => $fooTaskCommandHandler->changeTitle()
18
 *  - Cubiche\Application\Query\PostListQuery => $postListQueryHandler->postList()
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class MethodWithShortObjectNameResolver extends MethodWithObjectNameResolver
23
{
24
    /**
25
     * @var string
26
     */
27
    private $suffix;
28
29
    /**
30
     * @var int
31
     */
32
    private $suffixLength;
33
34
    /**
35
     * @param string $suffix The string to remove from end of each class name
36
     */
37
    public function __construct($suffix = 'Message')
38
    {
39
        $this->suffix = $suffix;
40
        $this->suffixLength = strlen($suffix);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function resolve($className)
47
    {
48
        $methodName = parent::resolve($className);
49
        if (substr($methodName, $this->suffixLength * -1) !== $this->suffix) {
50
            return $methodName;
51
        }
52
53
        return substr($methodName, 0, strlen($methodName) - $this->suffixLength);
54
    }
55
}
56