Passed
Push — master ( c1a8c1...b5fef0 )
by Shahrad
02:24
created

CrossData::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace TelegramBot\Util;
4
5
/**
6
 * Class CrossData
7
 *
8
 * @link    https://github.com/telegram-bot-php/core
9
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
10
 * @license https://github.com/telegram-bot-php/core/blob/master/LICENSE (MIT License)
11
 */
12
class CrossData
13
{
14
15
	/**
16
	 * get CrossData
17
	 *
18
	 * @param string $key
19
	 * @return string|array|bool|null
20
	 */
21
	public static function get(string $key): string|array|bool|null
22
	{
23
		$data = json_decode(getenv('TG_CROSS_DATA'), true);
24
		$block = 'TG_CROSS_DATA' . $key;
25
26
		if (!isset($data[$key])) {
27
			return null;
28
		}
29
30
		return getenv($data[$block]);
31
	}
32
33
	/**
34
	 * put CrossData
35
	 *
36
	 * @param string $key
37
	 * @param mixed $value
38
	 * @return void
39
	 */
40
	public static function put(string $key, mixed $value): void
41
	{
42
		$data = json_decode(getenv('TG_CROSS_DATA'), true);
43
		$data[$key] = 'TG_CROSS_DATA_' . $key;
44
		putenv($data[$key] . '=' . $value);
45
		putenv(json_encode($data));
46
	}
47
48
}