Completed
Pull Request — master (#9)
by
unknown
02:23
created

TransactionNameMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTransactionName() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
namespace Kartenmacherei\RestFramework\Monitoring;
5
6
class TransactionNameMapper
7
{
8
    const FALLBACK_TRANSACTION_NAME = 'transaction_name_was_not_set';
9
10
    /**
11
     * @var array
12
     */
13
    private $mapping;
14
15
    /**
16
     * @param array $mapping
17
     */
18
    public function __construct(array $mapping)
19
    {
20
        $this->mapping = $mapping;
21
    }
22
23
    /**
24
     * @param string $className
25
     * @return string
26
     */
27
    public function getTransactionName(string $className): string
28
    {
29
        if (!array_key_exists($className, $this->mapping)) {
30
            return self::FALLBACK_TRANSACTION_NAME;
31
        }
32
33
        return $this->mapping[$className];
34
    }
35
}
36