Skip to content

Commit be007f7

Browse files
HP-1751 added consumption classes
1 parent 27b606f commit be007f7

File tree

6 files changed

+132
-4
lines changed

6 files changed

+132
-4
lines changed

src/product/ConsumptionColumn.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
namespace hiqdev\php\billing\product;
44

5+
use hiqdev\billing\registry\product\PriceType;
6+
57
class ConsumptionColumn
68
{
79
private bool $isConvertible = false;
810

911
private bool $isOverMax = false;
1012

13+
public function __construct(
14+
private readonly ConsumptionColumnCollection $parent,
15+
private readonly PriceType $priceType
16+
)
17+
{
18+
}
19+
1120
public function convertible(): self
1221
{
1322
$this->isConvertible = true;
@@ -31,4 +40,14 @@ public function isOverMax(): bool
3140
{
3241
return $this->isOverMax;
3342
}
43+
44+
public function priceType(): PriceType
45+
{
46+
return $this->priceType;
47+
}
48+
49+
public function end(): ConsumptionColumnCollection
50+
{
51+
return $this->parent;
52+
}
3453
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace hiqdev\php\billing\product;
4+
5+
use hiqdev\billing\registry\product\PriceType;
6+
7+
class ConsumptionColumnCollection implements \IteratorAggregate
8+
{
9+
/** @var ConsumptionColumn[] */
10+
private array $columns = [];
11+
12+
public function __construct(private readonly ConsumptionDefinition $parent)
13+
{
14+
}
15+
16+
/**
17+
* @return ConsumptionColumn[]
18+
*/
19+
public function getIterator(): \Traversable
20+
{
21+
return new \ArrayIterator($this->columns);
22+
}
23+
24+
public function column(PriceType $priceType): ConsumptionColumn
25+
{
26+
$column = new ConsumptionColumn($this, $priceType);
27+
28+
$this->columns[] = $column;
29+
30+
return $column;
31+
}
32+
33+
public function end(): ConsumptionDefinition
34+
{
35+
return $this->parent;
36+
}
37+
}

src/product/ConsumptionDefinition.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
class ConsumptionDefinition
66
{
77
private ConsumptionColumnCollection $columnCollection;
8+
private ConsumptionGroupCollection $groupCollection;
89

910
public function __construct(private readonly TariffType $parent)
1011
{
1112
$this->columnCollection = new ConsumptionColumnCollection($this);
13+
$this->groupCollection = new ConsumptionGroupCollection($this);
1214
}
1315

1416
public function columns(): ConsumptionColumnCollection
1517
{
1618
return $this->columnCollection;
1719
}
1820

19-
public function groups()
21+
public function groups(): ConsumptionGroupCollection
2022
{
21-
23+
return $this->groupCollection;
2224
}
2325

2426
public function end(): TariffType

src/product/ConsumptionGroup.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace hiqdev\php\billing\product;
4+
5+
use hiqdev\billing\registry\product\PriceType;
6+
7+
class ConsumptionGroup implements \IteratorAggregate
8+
{
9+
private array $group;
10+
11+
public function __construct(
12+
private readonly ConsumptionGroupCollection $parent,
13+
)
14+
{
15+
}
16+
17+
/**
18+
* @return PriceType[]
19+
*/
20+
public function getIterator(): \Traversable
21+
{
22+
return new \ArrayIterator($this->group);
23+
}
24+
25+
public function add(PriceType $priceType): self
26+
{
27+
$this->group[] = $priceType;
28+
29+
return $this;
30+
}
31+
32+
public function end(): ConsumptionGroupCollection
33+
{
34+
return $this->parent;
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace hiqdev\php\billing\product;
4+
5+
class ConsumptionGroupCollection implements \IteratorAggregate
6+
{
7+
/** @var ConsumptionGroup[] */
8+
private array $groups = [];
9+
10+
public function __construct(private readonly ConsumptionDefinition $parent)
11+
{
12+
}
13+
14+
/**
15+
* @return ConsumptionColumn[]
16+
*/
17+
public function getIterator(): \Traversable
18+
{
19+
return new \ArrayIterator($this->groups);
20+
}
21+
22+
public function group(): ConsumptionGroup
23+
{
24+
$group = new ConsumptionGroup($this);
25+
26+
$this->groups[] = $group;
27+
28+
return $group;
29+
}
30+
31+
public function end(): ConsumptionDefinition
32+
{
33+
return $this->parent;
34+
}
35+
}

src/product/PriceTypeDefinition.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class PriceTypeDefinition
2828
public function __construct(
2929
private readonly PriceTypesCollection $parent,
3030
private readonly TypeInterface $type,
31-
private readonly QuantityFormatterFactory $quantityFormatterFactory,
3231
) {
3332
$this->invoiceCollection = new InvoiceRepresentationCollection($this);
3433
$this->behaviorCollection = new BehaviorCollection($this);
@@ -71,7 +70,7 @@ public function quantityFormatter(string $formatterClass, $fractionUnit = null):
7170
public function createQuantityFormatter(
7271
FractionQuantityData $data,
7372
): QuantityFormatterInterface {
74-
return $this->quantityFormatterFactory->create(
73+
return QuantityFormatterFactory::create(
7574
$this->getUnit(),
7675
$this->quantityFormatterDefinition,
7776
$data,

0 commit comments

Comments
 (0)