1 | <?php namespace SimpleUPS; |
||
12 | class Shipment extends Model |
||
13 | { |
||
14 | |||
15 | private |
||
16 | /* @var Shipper $shipper */ |
||
17 | $shipper, |
||
18 | |||
19 | /* @var InstructionalAddress $destination */ |
||
20 | $destination, |
||
21 | |||
22 | /* @var Service $service */ |
||
23 | $service, |
||
24 | |||
25 | /* @var Package[] $packages */ |
||
26 | $packages; |
||
27 | |||
28 | /** |
||
29 | * @internal |
||
30 | * |
||
31 | * @param Shipper $shipper |
||
32 | * |
||
33 | * @return Shipment |
||
34 | */ |
||
35 | public function setShipper(Shipper $shipper) |
||
40 | |||
41 | /** |
||
42 | * Information about the shipper |
||
43 | * @return Shipper |
||
44 | */ |
||
45 | public function getShipper() |
||
49 | |||
50 | /** |
||
51 | * @internal |
||
52 | * |
||
53 | * @param InstructionalAddress $destination |
||
54 | * |
||
55 | * @return Shipment |
||
56 | */ |
||
57 | public function setDestination(InstructionalAddress $destination) |
||
62 | |||
63 | /** |
||
64 | * Delivery destination |
||
65 | * @return InstructionalAddress |
||
66 | */ |
||
67 | public function getDestination() |
||
71 | |||
72 | /** |
||
73 | * @internal |
||
74 | * |
||
75 | * @param Service $service |
||
76 | * |
||
77 | * @return Shipment |
||
78 | */ |
||
79 | public function setService(Service $service) |
||
84 | |||
85 | /** |
||
86 | * Shipping service used |
||
87 | * @return Service |
||
88 | */ |
||
89 | public function getService() |
||
93 | |||
94 | /** |
||
95 | * @internal |
||
96 | * |
||
97 | * @param Package $package |
||
98 | * |
||
99 | * @return Shipment |
||
100 | */ |
||
101 | public function addPackage(Package $package) |
||
110 | |||
111 | /** |
||
112 | * Packages in this shipment |
||
113 | * @return Package[] |
||
114 | */ |
||
115 | public function getPackages() |
||
119 | |||
120 | /** |
||
121 | * @internal |
||
122 | * |
||
123 | * @param \DomDocument $dom |
||
124 | * |
||
125 | * @return \DOMElement |
||
126 | */ |
||
127 | public function toXml(\DomDocument $dom) |
||
152 | |||
153 | /** |
||
154 | * @internal |
||
155 | * |
||
156 | * @param \SimpleXMLElement $xml |
||
157 | * |
||
158 | * @return Shipment |
||
159 | */ |
||
160 | public static function fromXml(\SimpleXMLElement $xml) |
||
185 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: