Created
March 19, 2019 15:08
-
-
Save danielpotthast/f97cea91646b266234bbc3d4f340dedd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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