Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.64% |
7 / 11 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Commitment | |
63.64% |
7 / 11 |
|
20.00% |
1 / 5 |
7.73 | |
0.00% |
0 / 1 |
| __construct | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
| finalized | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| confirmed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| processed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Attestto\SolanaPhpSdk\Util; |
| 4 | |
| 5 | use Attestto\SolanaPhpSdk\Exceptions\InputValidationException; |
| 6 | |
| 7 | class Commitment |
| 8 | { |
| 9 | const FINALIZED = 'finalized'; |
| 10 | const CONFIRMED = 'confirmed'; |
| 11 | const PROCESSED = 'processed'; |
| 12 | |
| 13 | protected string $commitmentLevel; |
| 14 | |
| 15 | /** |
| 16 | * @param string $commitmentLevel |
| 17 | */ |
| 18 | public function __construct(string $commitmentLevel) |
| 19 | { |
| 20 | if (! in_array($commitmentLevel, [ |
| 21 | self::FINALIZED, |
| 22 | self::CONFIRMED, |
| 23 | self::PROCESSED, |
| 24 | ])) { |
| 25 | throw new InputValidationException('Invalid commitment level.'); |
| 26 | } |
| 27 | |
| 28 | $this->commitmentLevel = $commitmentLevel; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @return static |
| 33 | */ |
| 34 | public static function finalized(): Commitment |
| 35 | { |
| 36 | return new static(static::FINALIZED); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @return static |
| 41 | */ |
| 42 | public static function confirmed(): Commitment |
| 43 | { |
| 44 | return new static(static::CONFIRMED); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return static |
| 49 | */ |
| 50 | public static function processed(): Commitment |
| 51 | { |
| 52 | return new static(static::PROCESSED); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return string |
| 57 | */ |
| 58 | public function __toString() |
| 59 | { |
| 60 | return $this->commitmentLevel; |
| 61 | } |
| 62 | } |