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 |
||
| 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) |
||
| 90 | } |
||
| 91 |