Issues (590)

src/Schema/Bag/IndexSet.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bdf\Prime\Schema\Bag;
4
5
use Bdf\Prime\Schema\IndexInterface;
6
use Bdf\Prime\Schema\IndexSetInterface;
7
8
/**
9
 * Index set class
10
 * An index set represents a set of index, with a primary key
11
 * The indexes names are case insensitive
12
 */
13
final class IndexSet implements IndexSetInterface
14
{
15
    /**
16
     * @var IndexInterface[]
17
     */
18
    private $indexes;
19
20
21
    /**
22
     * IndexSet constructor.
23
     *
24
     * @param IndexInterface[] $indexes
25
     */
26 786
    public function __construct(array $indexes)
27
    {
28 786
        $this->indexes = [];
29
30 786
        foreach ($indexes as $index) {
31 723
            $this->indexes[strtolower($index->name())] = $index;
0 ignored issues
show
It seems like $index->name() can also be of type null; however, parameter $string of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            $this->indexes[strtolower(/** @scrutinizer ignore-type */ $index->name())] = $index;
Loading history...
32
        }
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 14
    public function primary(): ?IndexInterface
39
    {
40 14
        foreach ($this->indexes as $index) {
41 13
            if ($index->primary()) {
42 11
                return $index;
43
            }
44
        }
45
46 3
        return null;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 768
    public function all(): array
53
    {
54 768
        return $this->indexes;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 12
    public function get(string $name): IndexInterface
61
    {
62 12
        return $this->indexes[strtolower($name)];
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 8
    public function has(string $name): bool
69
    {
70 8
        return isset($this->indexes[strtolower($name)]);
71
    }
72
}
73