Code Duplication    Length = 35-35 lines in 2 locations

eZ/Publish/Core/Repository/Values/MultiLanguageDescriptionTrait.php 1 location

@@ 14-48 (lines=35) @@
11
/**
12
 * @internal Meant for internal use by Repository, type hint against API object instead.
13
 */
14
trait MultiLanguageDescriptionTrait
15
{
16
    /**
17
     * Holds the collection of descriptions with languageCode keys.
18
     *
19
     * @var string[]
20
     */
21
    protected $descriptions = [];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getDescriptions()
27
    {
28
        return $this->descriptions;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getDescription($languageCode = null)
35
    {
36
        if (!empty($languageCode)) {
37
            return isset($this->descriptions[$languageCode]) ? $this->descriptions[$languageCode] : null;
38
        }
39
40
        foreach ($this->prioritizedLanguages as $prioritizedLanguageCode) {
41
            if (isset($this->descriptions[$prioritizedLanguageCode])) {
42
                return $this->descriptions[$prioritizedLanguageCode];
43
            }
44
        }
45
46
        return $this->descriptions[$this->mainLanguageCode];
47
    }
48
}
49

eZ/Publish/Core/Repository/Values/MultiLanguageNameTrait.php 1 location

@@ 14-48 (lines=35) @@
11
/**
12
 * @internal Meant for internal use by Repository, type hint against API object instead.
13
 */
14
trait MultiLanguageNameTrait
15
{
16
    /**
17
     * Holds the collection of names with languageCode keys.
18
     *
19
     * @var string[]
20
     */
21
    protected $names = [];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getNames()
27
    {
28
        return $this->names;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getName($languageCode = null)
35
    {
36
        if (!empty($languageCode)) {
37
            return isset($this->names[$languageCode]) ? $this->names[$languageCode] : null;
38
        }
39
40
        foreach ($this->prioritizedLanguages as $prioritizedLanguageCode) {
41
            if (isset($this->names[$prioritizedLanguageCode])) {
42
                return $this->names[$prioritizedLanguageCode];
43
            }
44
        }
45
46
        return $this->names[$this->mainLanguageCode];
47
    }
48
}
49