Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e710f3
commit a80202b
Showing
6 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace hiqdev\php\billing\usage; | ||
|
||
use DateTimeImmutable; | ||
use hiqdev\php\billing\target\TargetInterface; | ||
use hiqdev\php\billing\type\TypeInterface; | ||
use hiqdev\php\units\Quantity; | ||
|
||
/** | ||
* Class Usage represents a consumption of some metered resource $type at $time | ||
* by the $target with the given $amount. | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
*/ | ||
class Usage implements UsageInterface | ||
{ | ||
private TargetInterface $target; | ||
private DateTimeImmutable $time; | ||
private TypeInterface $type; | ||
private Quantity $amount; | ||
|
||
public function __construct(TargetInterface $target, DateTimeImmutable $time, TypeInterface $type, Quantity $amount) | ||
{ | ||
$this->target = $target; | ||
$this->time = $time; | ||
$this->type = $type; | ||
$this->amount = $amount; | ||
} | ||
|
||
public function target(): TargetInterface | ||
{ | ||
return $this->target; | ||
} | ||
|
||
public function time(): DateTimeImmutable | ||
{ | ||
return $this->time; | ||
} | ||
|
||
public function type(): TypeInterface | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function amount(): Quantity | ||
{ | ||
return $this->amount; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace hiqdev\php\billing\usage; | ||
|
||
use DateTimeImmutable; | ||
use hiqdev\php\billing\target\TargetInterface; | ||
use hiqdev\php\billing\type\TypeInterface; | ||
use hiqdev\php\units\Quantity; | ||
|
||
interface UsageInterface | ||
{ | ||
public function target(): TargetInterface; | ||
|
||
public function time(): DateTimeImmutable; | ||
|
||
public function type(): TypeInterface; | ||
|
||
public function amount(): Quantity; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace hiqdev\php\billing\usage; | ||
|
||
use hiqdev\php\billing\Exception\RuntimeException; | ||
|
||
interface UsageRecorderInterface | ||
{ | ||
/** | ||
* @throws RuntimeException when unable to record the passed usage | ||
*/ | ||
public function record(Usage $usage): void; | ||
} |
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
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
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