Completed
Push — master ( cf2d59...36802d )
by André
16:28
created

MultiLanguageDescriptionTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 35
loc 35
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescriptions() 4 4 1
B getDescription() 14 14 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\Values;
10
11
/**
12
 * @internal Meant for internal use by Repository, type hint against API object instead.
13
 */
14 View Code Duplication
trait MultiLanguageDescriptionTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Bug introduced by
The property prioritizedLanguages does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
            if (isset($this->descriptions[$prioritizedLanguageCode])) {
42
                return $this->descriptions[$prioritizedLanguageCode];
43
            }
44
        }
45
46
        return $this->descriptions[$this->mainLanguageCode];
0 ignored issues
show
Bug introduced by
The property mainLanguageCode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
47
    }
48
}
49