Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
10 / 10 |
ProductCollection | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
10 / 10 |
__construct(array $products = []) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
isFilled() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
addProduct(ProductInterface $product) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
getProducts() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
setProducts(array $products) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
count() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getIterator() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
/** | |
* @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
*/ | |
namespace Team3\PayU\Order\Model\Products; | |
use Symfony\Component\Validator\Constraints as Assert; | |
class ProductCollection implements ProductCollectionInterface | |
{ | |
/** | |
* @var ProductInterface[] | |
* @Assert\Count(min="1") | |
*/ | |
protected $products; | |
/** | |
* @param ProductInterface[] $products | |
*/ | |
public function __construct(array $products = []) | |
{ | |
$this->products = $products; | |
} | |
/** | |
* Return true if given object is filled | |
* | |
* @return bool | |
*/ | |
public function isFilled() | |
{ | |
return 0 < count($this->products); | |
} | |
/** | |
* @param ProductInterface $product | |
* | |
* @return $this | |
*/ | |
public function addProduct(ProductInterface $product) | |
{ | |
$this->products[] = $product; | |
return $this; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function getProducts() | |
{ | |
return $this->products; | |
} | |
/** | |
* @param array $products | |
* | |
* @return ProductCollection | |
*/ | |
public function setProducts(array $products) | |
{ | |
$this->products = array_values($products); | |
return $this; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function count() | |
{ | |
return count($this->getProducts()); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function getIterator() | |
{ | |
return new \ArrayIterator($this->getProducts()); | |
} | |
} |