Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpotthast/f97cea91646b266234bbc3d4f340dedd to your computer and use it in GitHub Desktop.
Save danielpotthast/f97cea91646b266234bbc3d4f340dedd to your computer and use it in GitHub Desktop.
class ProductList
{
private $products = [];
public function __construct(array $productList)
{
foreach ($productList as $product) {
$this->addProduct($product);
}
}
public function addProduct(ProductListInterface $product)
{
array_push($this->products, $product);
}
public function getListedProducts()
{
return array_filter(
$this->products,
function (ProductListInterface $product) {
return $product->isListed();
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment