1 | <?php |
||||||
2 | |||||||
3 | namespace ByTIC\GoogleRecaptcha\Config\Traits; |
||||||
4 | |||||||
5 | use ByTIC\GoogleRecaptcha\Config\Config; |
||||||
6 | use ByTIC\GoogleRecaptcha\Config\ConfigEnv; |
||||||
7 | |||||||
8 | /** |
||||||
9 | * Trait CanInitFromEnviromentTrait |
||||||
10 | * @package ByTIC\GoogleRecaptcha\Config\Traits |
||||||
11 | */ |
||||||
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() |
||||||
29 | { |
||||||
30 | if (empty(static::getEnvVar(ConfigEnv::SITE_KEY))) { |
||||||
31 | return false; |
||||||
32 | } |
||||||
33 | if (empty(static::getEnvVar(ConfigEnv::SECRET_KEY))) { |
||||||
34 | return false; |
||||||
35 | } |
||||||
36 | return true; |
||||||
37 | } |
||||||
38 | |||||||
39 | protected function initFromEnv() |
||||||
40 | { |
||||||
41 | $this->setEnabled(static::getEnvVar(ConfigEnv::ENABLED)); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
42 | $this->setSiteKey(static::getEnvVar(ConfigEnv::SITE_KEY)); |
||||||
0 ignored issues
–
show
It seems like
setSiteKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
43 | $this->setSecretKey(static::getEnvVar(ConfigEnv::SECRET_KEY)); |
||||||
0 ignored issues
–
show
It seems like
setSecretKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
44 | } |
||||||
45 | |||||||
46 | /** |
||||||
47 | * @param string $value |
||||||
48 | * @param null $default |
||||||
0 ignored issues
–
show
|
|||||||
49 | * @return mixed|null |
||||||
50 | */ |
||||||
51 | protected static function getEnvVar($value, $default = null) |
||||||
52 | { |
||||||
53 | if (isset($_ENV[$value])) { |
||||||
54 | return $_ENV[$value]; |
||||||
55 | } |
||||||
56 | return $default; |
||||||
57 | } |
||||||
58 | } |
||||||
59 |