Collection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A offsetExists() 0 3 1
A offsetSet() 0 7 2
A offsetUnset() 0 3 1
A offsetGet() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sunrise\Hydrator\Tests\Fixture;
6
7
use ArrayAccess;
8
use Countable;
9
use OverflowException;
10
use ReturnTypeWillChange;
11
12
use function count;
13
14
/**
15
 * @implements ArrayAccess<TKey, TValue>
16
 *
17
 * @template TKey as array-key
18
 * @template TValue as mixed
19
 */
20
class Collection implements ArrayAccess, Countable
21
{
22
    /**
23
     * @var int<-1, max>
24
     */
25
    protected const LIMIT = -1;
26
27
    /**
28
     * @var array<TKey, TValue>
29
     */
30
    public array $elements = [];
31
32
    /**
33
     * @param TKey $offset
0 ignored issues
show
Bug introduced by
The type Sunrise\Hydrator\Tests\Fixture\TKey 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...
34
     *
35
     * @return bool
36
     */
37
    public function offsetExists($offset): bool
38
    {
39
        return isset($this->elements[$offset]);
40
    }
41
42
    /**
43
     * @param TKey $offset
44
     *
45
     * @return TValue|null
0 ignored issues
show
Bug introduced by
The type Sunrise\Hydrator\Tests\Fixture\TValue 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...
46
     */
47
    #[ReturnTypeWillChange]
48
    public function offsetGet($offset)
49
    {
50
        return $this->elements[$offset] ?? null;
51
    }
52
53
    /**
54
     * @param TKey $offset
55
     * @param TValue $value
56
     *
57
     * @return void
58
     *
59
     * @throws OverflowException
60
     */
61
    public function offsetSet($offset, $value): void
62
    {
63
        if ($this->count() === static::LIMIT) {
64
            throw new OverflowException();
65
        }
66
67
        $this->elements[$offset] = $value;
68
    }
69
70
    /**
71
     * @param TKey $offset
72
     *
73
     * @return void
74
     */
75
    public function offsetUnset($offset): void
76
    {
77
        unset($this->elements[$offset]);
78
    }
79
80
    /**
81
     * @return int<0, max>
82
     */
83
    public function count(): int
84
    {
85
        return count($this->elements);
86
    }
87
}
88