Completed
Push — location_content_property ( b180d5 )
by André
16:28
created

ContentProxy   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 29.63 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 54
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getVersionInfo() 0 8 2
A getFieldValue() 8 8 2
A getFields() 0 8 2
A getFieldsByLanguage() 0 8 2
A getField() 8 8 2

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
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Repository\Values\Content;
8
9
use eZ\Publish\API\Repository\Values\Content\Content as APIContent;
10
use eZ\Publish\Core\Repository\Values\GeneratorProxyTrait;
11
12
/**
13
 * This class represents a (lazy loaded) proxy for a content value.
14
 *
15
 * @internal Meant for internal use by Repository, type hint against API object instead.
16
 */
17
class ContentProxy extends APIContent
18
{
19
    use GeneratorProxyTrait;
20
21
    /**
22
     * @var \eZ\Publish\API\Repository\Values\Content\Content|null
23
     */
24
    protected $object;
25
26
    public function getVersionInfo()
27
    {
28
        if ($this->object === null) {
29
            $this->loadObject();
30
        }
31
32
        return $this->object->getVersionInfo();
33
    }
34
35 View Code Duplication
    public function getFieldValue($fieldDefIdentifier, $languageCode = null)
36
    {
37
        if ($this->object === null) {
38
            $this->loadObject();
39
        }
40
41
        return $this->object->getFieldValue($fieldDefIdentifier, $languageCode);
42
    }
43
44
    public function getFields()
45
    {
46
        if ($this->object === null) {
47
            $this->loadObject();
48
        }
49
50
        return $this->object->getFields();
51
    }
52
53
    public function getFieldsByLanguage($languageCode = null)
54
    {
55
        if ($this->object === null) {
56
            $this->loadObject();
57
        }
58
59
        return $this->object->getFieldsByLanguage($languageCode);
60
    }
61
62 View Code Duplication
    public function getField($fieldDefIdentifier, $languageCode = null)
63
    {
64
        if ($this->object === null) {
65
            $this->loadObject();
66
        }
67
68
        return $this->object->getField($fieldDefIdentifier, $languageCode);
69
    }
70
}
71