Passed
Push — master ( b6588e...364135 )
by Vladislav
10:17 queued 08:02
created

ArrayHelper::checkValueWithStack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 2
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
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