Issues (590)

src/Schema/Bag/Index.php (2 issues)

1
<?php
2
3
namespace Bdf\Prime\Schema\Bag;
4
5
use Bdf\Prime\Schema\Adapter\AbstractIndex;
6
use Bdf\Prime\Schema\IndexInterface;
7
8
/**
9
 * Index using simple array of fields
10
 *
11
 * @psalm-immutable
12
 */
13
final class Index extends AbstractIndex
14
{
15
    /**
16
     * @var array<string, array>
17
     */
18
    private $fields;
19
20
    /**
21
     * @var IndexInterface::TYPE_*
22
     */
23
    private $type;
24
25
    /**
26
     * @var string|null
27
     */
28
    private $name;
29
30
    /**
31
     * @var array
32
     */
33
    private $options;
34
35
36
    /**
37
     * ArrayIndex constructor.
38
     *
39
     * @param array<string,array> $fields The fields as key, and option as value
40
     * @param IndexInterface::TYPE_* $type
41
     * @param string|null $name
42
     * @param array $options
43
     */
44 745
    public function __construct(array $fields, int $type = self::TYPE_SIMPLE, ?string $name = null, array $options = [])
45
    {
46 745
        $this->fields = $fields;
47 745
        $this->type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type of type integer is incompatible with the declared type Bdf\Prime\Schema\IndexInterface of property $type.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48 745
        $this->name = $name;
49 745
        $this->options = $options;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 749
    public function name(): ?string
56
    {
57 749
        return $this->name;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 744
    public function type(): int
64
    {
65 744
        return $this->type;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->type returns the type Bdf\Prime\Schema\IndexInterface which is incompatible with the type-hinted return integer.
Loading history...
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 738
    public function fields(): array
72
    {
73 738
        return array_keys($this->fields);
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 708
    public function options(): array
80
    {
81 708
        return $this->options;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 708
    public function fieldOptions(string $field): array
88
    {
89 708
        return $this->fields[$field] ?? [];
90
    }
91
}
92