Passed
Push — master ( da9ebc...eab3b6 )
by Tobias
02:14
created

ControllerNamingStrategy::getTransactionName()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 15
nc 11
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\TransactionNamingStrategy;
15
16
use Symfony\Component\HttpFoundation\Request;
17
18
/**
19
 * @author Magnus Nordlander
20
 * @author Bart van den Burg <[email protected]>
21
 */
22
class ControllerNamingStrategy implements TransactionNamingStrategyInterface
23
{
24
    public function getTransactionName(Request $request): string
25
    {
26
        $controller = $request->attributes->get('_controller');
27
        if (empty($controller)) {
28
            return 'Unknown Symfony controller';
29
        }
30
31
        if ($controller instanceof \Closure) {
32
            return 'Closure controller';
33
        }
34
35
        if (\is_object($controller)) {
36
            if (\method_exists($controller, '__invoke')) {
37
                return 'Callback controller: '.\get_class($controller).'::__invoke()';
38
            }
39
        }
40
41
        if (\is_callable($controller)) {
42
            if (\is_array($controller)) {
43
                if (\is_object($controller[0])) {
44
                    $controller[0] = \get_class($controller[0]);
45
                }
46
47
                $controller = \implode('::', $controller);
48
            }
49
50
            return 'Callback contoller: '.$controller.'()';
51
        }
52
53
        return $controller;
54
    }
55
}
56