| Total Complexity | 7 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | trait CanInitFromEnviromentTrait |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @return static|Config |
||
| 17 | */ |
||
| 18 | public static function fromEnv() |
||
| 19 | { |
||
| 20 | $config = new static(); |
||
| 21 | $config->initFromEnv(); |
||
| 22 | return $config; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return bool |
||
| 27 | */ |
||
| 28 | public static function canInitFromEnv() |
||
| 37 | } |
||
| 38 | |||
| 39 | protected function initFromEnv() |
||
| 40 | { |
||
| 41 | $this->setEnabled(static::getEnvVar(ConfigEnv::ENABLED)); |
||
|
|
|||
| 42 | $this->setSiteKey(static::getEnvVar(ConfigEnv::SITE_KEY)); |
||
| 43 | $this->setSecretKey(static::getEnvVar(ConfigEnv::SECRET_KEY)); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $value |
||
| 48 | * @param null $default |
||
| 49 | * @return mixed|null |
||
| 50 | */ |
||
| 51 | protected static function getEnvVar($value, $default = null) |
||
| 57 | } |
||
| 58 | } |
||
| 59 |