Passed
Pull Request — main (#4)
by Peter
06:10 queued 03:04
created

Collection::allStrings()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Html\Helper;
6
7
use AbterPhp\Framework\Html\INode;
8
9
class Collection
10
{
11
    protected const ERROR_INVALID_ATTRIBUTES = 'invalid attributes (array of string[] and null items)';
12
13
    /**
14
     * @param array  $items
15
     * @param string $className
16
     *
17
     * @return bool
18
     */
19
    public static function allInstanceOf(array $items, string $className): bool
20
    {
21
        if (empty($className)) {
22
            return true;
23
        }
24
25
        foreach ($items as $item) {
26
            if (!($item instanceof $className)) {
27
                return false;
28
            }
29
        }
30
31
        return true;
32
    }
33
34
    /**
35
     * @param array $items
36
     *
37
     * @return bool
38
     */
39
    public static function allNodes(array $items): bool
40
    {
41
        foreach ($items as $item) {
42
            if (!is_scalar($item) && !($item instanceof INode)) {
43
                return false;
44
            }
45
        }
46
47
        return true;
48
    }
49
50
    /**
51
     * @param string[] $items
52
     *
53
     * @return bool
54
     */
55
    public static function allStrings(array $items): bool
56
    {
57
        foreach ($items as $item) {
58
            if (!is_string($item)) {
59
                return false;
60
            }
61
        }
62
63
        return true;
64
    }
65
}
66