Completed
Pull Request — dev (#9)
by Arnaud
12:24
created

TranslationKeyTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getTranslationKey() 0 11 3
1
<?php
2
3
namespace LAG\AdminBundle\Utils;
4
5
use LAG\AdminBundle\Application\Configuration\ApplicationConfiguration;
6
7
trait TranslationKeyTrait
8
{
9
    /**
10
     * @param ApplicationConfiguration $configuration
11
     * @param $key
12
     * @param string $adminName
13
     * @return string
14
     */
15
    public function getTranslationKey(ApplicationConfiguration $configuration, $key, $adminName = null)
16
    {
17
        $translationKey = $configuration->getParameter('translation')['pattern'];
18
19
        if (strstr($configuration->getParameter('translation')['pattern'], '{admin}') && $adminName != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $adminName of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
20
            $translationKey = str_replace('{admin}', $adminName, $translationKey);
21
        }
22
        $translationKey = str_replace('{key}', $key, $translationKey);
23
24
        return $translationKey;
25
    }
26
}
27