| Total Complexity | 6 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 11 | class ApiToken implements LazyExportableOption, FromEnvLazyFactory |
||
| 12 | { |
||
| 13 | const DIGITAL_OCEAN_API_TOKEN = 'DIGITAL_OCEAN_API_TOKEN'; |
||
| 14 | const OPTION_NAME = 'digital-ocean-api-token'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | private $value; |
||
| 20 | |||
| 21 | public function __construct(string $value) |
||
| 22 | { |
||
| 23 | Assertion::notEmpty($value, "The API token is empty."); |
||
| 24 | $this->value = $value; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param Env $env |
||
| 29 | * @return LazyEnvironmentValue|ApiToken |
||
| 30 | */ |
||
| 31 | public static function fromEnv(Env $env): LazyEnvironmentValue |
||
| 32 | { |
||
| 33 | return new self($env->get(self::DIGITAL_OCEAN_API_TOKEN, "")); |
||
|
|
|||
| 34 | } |
||
| 35 | |||
| 36 | public static function toEnv(string $value, Env $env): void |
||
| 37 | { |
||
| 38 | $env->put(self::DIGITAL_OCEAN_API_TOKEN, $value); |
||
| 39 | } |
||
| 40 | |||
| 41 | public static function optionName(): string |
||
| 42 | { |
||
| 43 | return self::OPTION_NAME; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function toString(): string |
||
| 49 | } |
||
| 50 | |||
| 51 | public function __toString() |
||
| 52 | { |
||
| 53 | return $this->toString(); |
||
| 57 |