Issues (590)

src/Relations/Util/EntityKeys.php (3 issues)

1
<?php
2
3
namespace Bdf\Prime\Relations\Util;
4
5
/**
6
 * Wrap entity keys for handle composite keys
7
 */
8
class EntityKeys
9
{
10
    /**
11
     * @var list<string>
0 ignored issues
show
The type Bdf\Prime\Relations\Util\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
     */
13
    private $keys = [];
14
15
    /**
16
     * @var mixed
17
     */
18
    private $entity;
19
20
    /**
21
     * @var int|null
22
     */
23
    private $hash = null;
24
25
26
    /**
27
     * EntityKeys constructor.
28
     *
29
     * @param list<string> $keys The entity keys values. Must be an integer index array, not an associative one
30
     * @param mixed $entity The attached entity
31
     */
32 9
    public function __construct(array $keys, $entity = null)
33
    {
34 9
        $this->keys = $keys;
0 ignored issues
show
Documentation Bug introduced by
It seems like $keys of type array is incompatible with the declared type Bdf\Prime\Relations\Util\list of property $keys.

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...
35 9
        $this->entity = $entity;
36
    }
37
38
    /**
39
     * Attach an entity to the keys
40
     *
41
     * @param mixed $entity
42
     */
43 1
    public function attach($entity): void
44
    {
45 1
        $this->entity = $entity;
46
    }
47
48
    /**
49
     * Get the attached entity
50
     *
51
     * @return mixed
52
     */
53 4
    public function get()
54
    {
55 4
        return $this->entity;
56
    }
57
58
    /**
59
     * Compute the hash on keys for make a simple hashmap
60
     *
61
     * @return integer
62
     */
63 5
    public function hash(): int
64
    {
65 5
        if ($this->hash !== null) {
66 3
            return $this->hash;
67
        }
68
69 5
        $hash = 0;
70
71 5
        foreach ($this->keys as $pos => $key) {
72 5
            $hash ^= ($pos + 1) * crc32($key);
73
        }
74
75 5
        return $this->hash = (int) $hash;
76
    }
77
78
    /**
79
     * Check if the two keys are same or not
80
     *
81
     * @param EntityKeys $other
82
     *
83
     * @return bool
84
     */
85 3
    public function equals(EntityKeys $other): bool
86
    {
87 3
        return $this->keys == $other->keys;
88
    }
89
90
    /**
91
     * Get the keys value to array
92
     *
93
     * @return string[]
94
     */
95 5
    public function toArray(): array
96
    {
97 5
        return $this->keys;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->keys returns the type Bdf\Prime\Relations\Util\list which is incompatible with the type-hinted return array.
Loading history...
98
    }
99
}
100