I know this is similar to my last question PHP Static vs Instance
But I didn't want to add it there and confuse that question, I believe it does stand on its own merits as a question
I have three classes Billing Invoice InvoiceItem
The billing class works out the billing and finishes up with the data for the invoice and and array of data from the invoice items $billing and $billingItems
the questions is how do I call the methods needed
In Billing Class
$invoice = new Invoice();
$invoice->createFomBilling($billing, $billingItems);
Do I:
1.
In Invoice Class
public function createFomBilling($billing, $billingItems)
{
foreach($billingItems as $billingItem)
{
$item = new InvoiceItems();
$item->setDataFromBilling($billingItem);
}
}
In InvoiceItem Class
public function setDataFromBilling($billingItem)
{
$this->item1 = $billingItem->item1;
$this->item2 = $billingItem->item2;
$this->item3 = $billingItem->item3;
$this->item4 = $billingItem->item4;
$this->item5 = $billingItem->item5;
$this->save();
}
OR
2.
In Invoice Class
public function createFomBilling($billing, $billingItems)
{
foreach($billingItems as $billingItem)
{
$item = new InvoiceItems();
$item->item1 = $billingItem->item1;
$item->item2 = $billingItem->item2;
$item->item3 = $billingItem->item3;
$item->item4 = $billingItem->item4;
$item->item5 = $billingItem->item5;
$item->save();
}
}
this way i do it all in the invoice class and i dont write code in the invoiceItem class
Any ideas