1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the prooph/php-ddd-cargo-sample. |
4
|
|
|
* (c) Alexander Miertsch <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* Date: 29.03.14 - 16:59 |
10
|
|
|
*/ |
11
|
|
|
declare(strict_types = 1); |
12
|
|
|
|
13
|
|
|
namespace Codeliner\CargoBackend\Application\Booking\Dto; |
14
|
|
|
use Assert\Assertion; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class CargoRoutingDto |
18
|
|
|
* |
19
|
|
|
* @package CargoBackend\API\Booking\Dto |
20
|
|
|
* @author Alexander Miertsch <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class CargoRoutingDto |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $trackingId; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $origin; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $finalDestination; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var LegDto[] |
41
|
|
|
*/ |
42
|
|
|
private $legs = array(); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $finalDestination |
46
|
|
|
*/ |
47
|
|
|
public function setFinalDestination(string $finalDestination) |
48
|
|
|
{ |
49
|
|
|
\Assert\that($finalDestination)->notEmpty()->string(); |
50
|
|
|
|
51
|
|
|
$this->finalDestination = $finalDestination; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getFinalDestination(): string |
58
|
|
|
{ |
59
|
|
|
return $this->finalDestination; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param LegDto[] $legs |
64
|
|
|
*/ |
65
|
|
|
public function setLegs(array $legs): array |
66
|
|
|
{ |
67
|
|
|
foreach($legs as $leg) { |
68
|
|
|
Assertion::isInstanceOf($leg, LegDto::class); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->legs = $legs; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function addLeg(LegDto $leg) |
75
|
|
|
{ |
76
|
|
|
$this->legs[] = $leg; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return LegDto[] |
81
|
|
|
*/ |
82
|
|
|
public function getLegs(): array |
83
|
|
|
{ |
84
|
|
|
return $this->legs; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $origin |
89
|
|
|
*/ |
90
|
|
|
public function setOrigin(string $origin) |
91
|
|
|
{ |
92
|
|
|
Assertion::notEmpty($origin); |
93
|
|
|
|
94
|
|
|
$this->origin = $origin; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getOrigin() |
101
|
|
|
{ |
102
|
|
|
return $this->origin; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $trackingId |
107
|
|
|
*/ |
108
|
|
|
public function setTrackingId(string $trackingId) |
109
|
|
|
{ |
110
|
|
|
Assertion::uuid($trackingId); |
111
|
|
|
|
112
|
|
|
$this->trackingId = $trackingId; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getTrackingId(): string |
119
|
|
|
{ |
120
|
|
|
return $this->trackingId; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function getArrayCopy(): array |
127
|
|
|
{ |
128
|
|
|
$legsArrayCopy = array(); |
129
|
|
|
|
130
|
|
View Code Duplication |
foreach ($this->getLegs() as $leg) { |
|
|
|
|
131
|
|
|
$legsArrayCopy[] = array( |
132
|
|
|
'load_location' => $leg->getLoadLocation(), |
133
|
|
|
'unload_location' => $leg->getUnloadLocation(), |
134
|
|
|
'load_time' => $leg->getLoadTime(), |
135
|
|
|
'unload_time' => $leg->getUnloadTime() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return array( |
140
|
|
|
'tracking_id' => $this->getTrackingId(), |
141
|
|
|
'origin' => $this->getOrigin(), |
142
|
|
|
'final_destination' => $this->getFinalDestination(), |
143
|
|
|
'legs' => $legsArrayCopy |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
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.