1 | <?php |
||
7 | class ProductUom extends AbstractService |
||
8 | { |
||
9 | protected $entityMapper = 'speckcatalog_product_uom_mapper'; |
||
10 | protected $availabilityService; |
||
11 | protected $uomService; |
||
12 | protected $productService; |
||
13 | |||
14 | 1 | public function getByProductId($productId, $populate = false, $recursive = false) |
|
15 | { |
||
16 | 1 | $productUoms = $this->getEntityMapper()->getByProductId($productId); |
|
17 | 1 | if ($populate) { |
|
18 | 1 | foreach ($productUoms as $productUom) { |
|
19 | 1 | $this->populate($productUom, $recursive); |
|
20 | 1 | } |
|
21 | 1 | } |
|
22 | 1 | return $productUoms; |
|
23 | } |
||
24 | |||
25 | public function cheapestUom(array $uoms) |
||
39 | |||
40 | 2 | public function populate($productUom, $recursive = false, $children = true) |
|
63 | |||
64 | /** |
||
65 | * @return availabilityService |
||
66 | */ |
||
67 | 4 | public function getAvailabilityService() |
|
74 | |||
75 | /** |
||
76 | * @param $availabilityService |
||
77 | * @return self |
||
78 | */ |
||
79 | 3 | public function setAvailabilityService($availabilityService) |
|
84 | |||
85 | /** |
||
86 | * @return uomService |
||
87 | */ |
||
88 | 4 | public function getUomService() |
|
95 | |||
96 | /** |
||
97 | * @param $uomService |
||
98 | * @return self |
||
99 | */ |
||
100 | 3 | public function setUomService($uomService) |
|
105 | |||
106 | public function update($data, array $where = null) |
||
122 | |||
123 | 2 | public function insert($productUom) |
|
147 | |||
148 | /** |
||
149 | * @return productService |
||
150 | */ |
||
151 | public function getProductService() |
||
158 | |||
159 | /** |
||
160 | * @param $productService |
||
161 | * @return self |
||
162 | */ |
||
163 | public function setProductService($productService) |
||
168 | } |
||
169 |
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: