Passed
Push — master ( 489b65...fbecfe )
by Vladislav
02:48 queued 31s
created

ArrayHelper::assign()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Helpers;
4
5
use Carpenstar\ByBitAPI\Core\Enums\WebSocketsIntervalEnum;
6
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException;
7
8
class ArrayHelper
9
{
10
    /**
11
     * Проверка, есть ли в массиве заданное значение
12
     *
13
     * @param string $value
14
     * @param array $stack
15
     * @return void
16
     * @throws SDKException
17
     */
18
    public static function checkValueWithStack(string $value, array $stack): void
19
    {
20
        if (!in_array($value, $stack)) {
21
            throw new SDKException("Value {$value} should be one of " . implode(",", $stack));
22
        }
23
    }
24
25
    /**
26
     * Проверка, массива на то содержится ли в нем минимальное количество элементов
27
     *
28
     * @param array $haystack
29
     * @param int $minCount
30
     * @return bool
31
     */
32
    public static function checkMinValue(array $haystack, int $minCount): bool
33
    {
34
        return count($haystack) >= $minCount;
35
    }
36
37
    /**
38
     * Проверка массива на превышение максимального значения
39
     *
40
     * @param array $haystack
41
     * @param int $maxCount
42
     * @return bool
43
     */
44
    public static function checkMaxValue(array $haystack, int $maxCount): bool
45
    {
46
        return count($haystack) <= $maxCount;
47
    }
48
49
    public static function assign($value, $defaultValue = []): array
50
    {
51
        return $value ?? $defaultValue;
52
    }
53
}
54