| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Iris\Mapping; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class ShippedFromVenture extends Base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |     public function assign(array $externalData) | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |         $postPaymentCollection = new \Iris\Transfer\PostPayment\PostPaymentCollection; | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |         foreach ($externalData as $data) { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |             $postPaymentCollection[] = new \Iris\Transfer\PostPayment\PostPayment([ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |                 'deliveryType'       => $data['deliveryType'], | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |                 'shippingProvider'   => $data['shippingProvider'], | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |                 'trackingCode'       => $data['trackingCode'], | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |                 'trackingUrl'        => $data['trackingUrl'], | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |                 'nfeKey'             => $data['nfeKey'], | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |                 'ventureOrderNumber' => $data['ventureOrderNumber'], | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |                 'ventureOrderItemId' => $data['ventureOrderItemId'] | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |             ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         return $postPaymentCollection; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function map($internalData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $externalData = ['items' => []]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         foreach ($internalData as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $externalData['items'][] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 'deliveryType'       => $item->getDeliveryType(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 'shippingProvider'   => $item->getShippingProvider(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 'trackingCode'       => $item->getTrackingCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 'trackingUrl'        => $item->getTrackingUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 'nfeKey'             => $item->getNfeKey(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'ventureOrderNumber' => $item->getVentureOrderNumber(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'ventureOrderItemId' => $item->getVentureOrderItemId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         return $externalData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  | 
            
                        
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.