| Total Complexity | 9 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 15 | trait EnvironmentsTrait |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Admin chat id |
||
| 20 | * |
||
| 21 | * @var int |
||
| 22 | */ |
||
| 23 | protected static int $adminId = -1; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Guesses a possible path to env file |
||
| 27 | * |
||
| 28 | * @return string|null |
||
| 29 | */ |
||
| 30 | protected static function guessEnvPath(): string|null |
||
| 31 | { |
||
| 32 | $defaultEnvPaths = [ |
||
| 33 | getcwd() . '/.env', |
||
| 34 | getcwd() . '/../.env', |
||
| 35 | $_SERVER['DOCUMENT_ROOT'] . '/.env', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | foreach ($defaultEnvPaths as $path) { |
||
| 39 | if (file_exists($path)) { |
||
| 40 | return $path; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | return null; |
||
| 45 | } |
||
| 46 | |||
| 47 | protected static function tryAutoloadEnv(): void { |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Set the admin chat id |
||
| 56 | * |
||
| 57 | * @return int |
||
| 58 | */ |
||
| 59 | public static function getAdminId(): int |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set the admin chat id |
||
| 66 | * |
||
| 67 | * @param int $adminId |
||
| 68 | */ |
||
| 69 | public static function setAdminId(int $adminId): void |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get token from env file. |
||
| 76 | * |
||
| 77 | * @param string $file |
||
| 78 | * @return string|null |
||
| 79 | */ |
||
| 80 | protected function getEnvToken(string $file): string|null |
||
| 87 |