Skip to content

Commit

Permalink
HP-1751 Create configurations for billing types
Browse files Browse the repository at this point in the history
  • Loading branch information
VadymHrechukha committed Dec 9, 2024
1 parent 59a8d47 commit cbc66f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/product/PriceTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class PriceTypeDefinition

private string $invoiceRepresentation;

public function __construct(private readonly PriceTypesCollection $parent)
{
}

public function unit(string $unit): self
{
$this->unit = $unit;
Expand Down Expand Up @@ -45,16 +49,16 @@ public function invoiceRepresentation(string $representationClass): self
public function end(): PriceTypesCollection
{
// Validate the PriceType and lock its state
return new PriceTypesCollection();
return $this->parent;
}

public function documentRepresentation(): InvoiceRepresentationCollection

Check failure on line 55 in src/product/PriceTypeDefinition.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

UndefinedClass

src/product/PriceTypeDefinition.php:55:47: UndefinedClass: Class, interface or enum named hiqdev\billing\registry\invoice\InvoiceRepresentationCollection does not exist (see https://psalm.dev/019)
{
return new InvoiceRepresentationCollection($this);

Check failure on line 57 in src/product/PriceTypeDefinition.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

UndefinedClass

src/product/PriceTypeDefinition.php:57:20: UndefinedClass: Class, interface or enum named hiqdev\billing\registry\invoice\InvoiceRepresentationCollection does not exist (see https://psalm.dev/019)
}

public function measuredWith(\hiqdev\billing\registry\measure\RcpTrafCollector $param)
public function measuredWith(\hiqdev\billing\registry\measure\RcpTrafCollector $param): self

Check failure on line 60 in src/product/PriceTypeDefinition.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

UndefinedClass

src/product/PriceTypeDefinition.php:60:34: UndefinedClass: Class, interface or enum named hiqdev\billing\registry\measure\RcpTrafCollector does not exist (see https://psalm.dev/019)
{

return $this;
}
}
15 changes: 12 additions & 3 deletions src/product/PriceTypesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ class PriceTypesCollection
{
private array $prices = [];

public function __construct(private readonly TariffType $parent)
{
}

public function monthly(string $type): PriceTypeDefinition
{
$priceType = new PriceTypeDefinition();
$priceType = $this->createPriceTypeDefinition();
$this->prices[$type] = $priceType;

return $priceType;
}

private function createPriceTypeDefinition(): PriceTypeDefinition
{
return new PriceTypeDefinition($this);
}

public function overuse(string $type): PriceTypeDefinition
{
$priceType = new PriceTypeDefinition();
$priceType = $this->createPriceTypeDefinition();
$this->prices[$type] = $priceType;

return $priceType;
}

public function end(): TariffType
{
// Return to the parent TariffType context
return $this->parent;
}
}
2 changes: 1 addition & 1 deletion src/product/TariffType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TariffType
public function __construct(string $name)
{
$this->name = $name;
$this->prices = new PriceTypesCollection();
$this->prices = new PriceTypesCollection($this);
}

public function ofProduct(Product $product): self

Check failure on line 23 in src/product/TariffType.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

UndefinedClass

src/product/TariffType.php:23:31: UndefinedClass: Class, interface or enum named hiqdev\billing\registry\product\Product does not exist (see https://psalm.dev/019)
Expand Down

0 comments on commit cbc66f2

Please # to comment.