Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
776 B
1
Indexable
Never
<?php

class NuggetsPacker {
    private $nuggets;
    private $cardboard;
    
    public function __construct(NuggetsCollection $nuggets, Carboard $cardboard)
    {
        $this->nuggets = $nuggets;    
        $this->cardboard = $carboard;
    }
    
    public function pack() 
    {
        return $this->cardboard->pack($nuggets);
    }
}

class OrderController 
{
    public function serve(Collection $burgerWrappers, Collection $nuggetsPacker)
    {
        $wrappedItems = [];
        
        foreach ($burgerWrappers as $burgerWrapper) {
            $wrappedItems[] = $burgerWrapper->wrap();
        }

        foreach ($nuggetsPacker as $nuggetPacker) {
            $wrappedItems[] = $nuggetPacker->pack();
        }        

        return $wrappedItems;
    }
}