Skip to content

Instantly share code, notes, and snippets.

@Mwamitovi
Created January 29, 2025 03:52
Show Gist options
  • Save Mwamitovi/a0c01cf7eaf5335f94ded00ab1fddfe2 to your computer and use it in GitHub Desktop.
Save Mwamitovi/a0c01cf7eaf5335f94ded00ab1fddfe2 to your computer and use it in GitHub Desktop.
// The PricedEntree class referencing that namespace:
class PricedEntree extends Entree {
public function __construct($name, $ingredients) {
parent::__construct($name, $ingredients);
foreach ($this->ingredients as $ingredient) {
if (! $ingredient instanceof \Meals\Ingredient) {
throw new Exception('Elements of $ingredients must be Ingredient objects');
}
}
}
public function getCost() {
$cost = 0;
foreach ($this->ingredients as $ingredient) {
$cost += $ingredient->getCost();
}
return $cost;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment