string.php ➔ str_is_positive_int()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
if (!function_exists('str_is_positive_int')) {
3
    /**
4
     * Проверяем является ли переданная строка целым числом
5
     *
6
     * @param mixed $string
7
     * @return bool
8
     */
9
    function str_is_positive_int(string $string): bool
10
    {
11
        return preg_match('/^\d+$/', $string) === 1;
12
    }
13
}
14
15
if (!function_exists('comma')) {
16
17
    /**
18
     * Перечисление элементов через запятую
19
     *
20
     * @param array ...$items
21
     * @return string
22
     */
23
    function comma(...$items): string
24
    {
25
        $arr = [];
26
        foreach ($items as $item) {
27
            if (!empty($item)) {
28
                $arr[] = $item;
29
            }
30
        }
31
        return implode(', ', $arr);
32
    }
33
}