Skip to content

Commit f220f77

Browse files
HP-1751 added possibility to count elements in PriceTypeDefinitionCollection
1 parent 96cf778 commit f220f77

3 files changed

+16
-2
lines changed

src/product/price/PriceTypeDefinitionCollection.php

+5
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public function end(): TariffTypeDefinitionInterface
4949
{
5050
return $this->parent;
5151
}
52+
53+
public function count(): int
54+
{
55+
return $this->storage->count();
56+
}
5257
}

src/product/price/PriceTypeDefinitionCollectionInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;
66
use hiqdev\php\billing\type\TypeInterface;
77

8-
interface PriceTypeDefinitionCollectionInterface extends \IteratorAggregate
8+
interface PriceTypeDefinitionCollectionInterface extends \IteratorAggregate, \Countable
99
{
1010
/**
1111
* @return PriceTypeDefinition[]

src/product/price/PriceTypeStorage.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55
use hiqdev\php\billing\type\TypeInterface;
66

7-
class PriceTypeStorage
7+
class PriceTypeStorage implements \Countable
88
{
99
private array $pricesGroupedByPriceType = [];
1010

11+
private int $i = 0;
12+
1113
public function add(TypeInterface $type, PriceTypeDefinition $priceTypeDefinition): void
1214
{
1315
$this->pricesGroupedByPriceType[$type->getName()][] = $priceTypeDefinition;
16+
17+
$this->i++;
1418
}
1519

1620
/**
@@ -27,4 +31,9 @@ public function getAll(): array
2731

2832
return $allPrices;
2933
}
34+
35+
public function count(): int
36+
{
37+
return $this->i;
38+
}
3039
}

0 commit comments

Comments
 (0)