Completed
Pull Request — master (#152)
by Christopher
03:37
created

ODataLink   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 12.05 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setExpandResult() 10 13 3
A getExpandResult() 0 12 3

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
namespace POData\ObjectModel;
4
5
/**
6
 * Class ODataLink represents an OData Navigation Link.
7
 */
8
class ODataLink
9
{
10
    /**
11
     * Name of the link. This becomes last segment of rel attribute value.
12
     *
13
     * @var string
14
     */
15
    public $name;
16
    /**
17
     * Title of the link. This become value of title attribute.
18
     *
19
     * @var string
20
     */
21
    public $title;
22
    /**
23
     * Type of link.
24
     *
25
     * @var string
26
     */
27
    public $type;
28
    /**
29
     * Url to the navigation property. This become value of href attribute.
30
     *
31
     * @var string
32
     */
33
    public $url;
34
    /**
35
     * Checks is Expand result contains single entity or collection of
36
     * entities i.e. feed.
37
     *
38
     * @var bool
39
     */
40
    public $isCollection;
41
    /**
42
     * The expanded result. This becomes the inline content of the link.
43
     *
44
     * @var ODataEntry|ODataFeed
45
     */
46
    public $expandedResult;
47
    /**
48
     * True if Link is Expanded, False if not.
49
     *
50
     * @var bool
51
     */
52
    public $isExpanded;
53
    /**
54
     * @var null
55
     */
56
    public $expandResult;
57
58
    /**
59
     * @return null|\POData\ObjectModel\ODataExpandedResult
60
     */
61
    public function getExpandResult()
62
    {
63
        if (!$this->isExpanded) {
64
            return null;
65
        }
66
        if ($this->isCollection) {
67
            assert($this->expandedResult instanceof ODataFeed);
68
            return new ODataExpandedResult(null, $this->expandedResult);
69
        }
70
        assert($this->expandedResult instanceof ODataEntry);
71
        return new ODataExpandedResult($this->expandedResult);
72
    }
73
74
    /**
75
     * @param \POData\ObjectModel\ODataExpandedResult $eResult
76
     */
77
    public function setExpandResult(ODataExpandedResult $eResult)
78
    {
79 View Code Duplication
        if (null !== $eResult->feed) {
80
            $this->isExpanded = true;
81
            $this->isCollection = true;
82
            $this->expandedResult = $eResult->feed;
83
        }
84 View Code Duplication
        if (null !== $eResult->entry) {
85
            $this->isExpanded = true;
86
            $this->isCollection = false;
87
            $this->expandedResult = $eResult->entry;
88
        }
89
    }
90
}
91