ArrayAccessible   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 8
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A offsetGet() 0 3 1
A offsetExists() 0 3 1
A offsetUnset() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InShore\Bookwhen\Responses\Concerns;
6
7
use BadMethodCallException;
8
9
/**
10
 * @template TArray of array
11
 *
12
 * @mixin Response<TArray>
13
 */
14
trait ArrayAccessible
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function offsetExists(mixed $offset): bool
20
    {
21
        return array_key_exists($offset, $this->toArray());
0 ignored issues
show
Bug introduced by
It seems like toArray() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        return array_key_exists($offset, $this->/** @scrutinizer ignore-call */ toArray());
Loading history...
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function offsetGet(mixed $offset): mixed
28
    {
29
        return $this->toArray()[$offset];
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function offsetSet(mixed $offset, mixed $value): never
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

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

35
    public function offsetSet(/** @scrutinizer ignore-unused */ mixed $offset, mixed $value): never

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

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

35
    public function offsetSet(mixed $offset, /** @scrutinizer ignore-unused */ mixed $value): never

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        throw new BadMethodCallException('Cannot set response attributes.');
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function offsetUnset(mixed $offset): never
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

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

43
    public function offsetUnset(/** @scrutinizer ignore-unused */ mixed $offset): never

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        throw new BadMethodCallException('Cannot unset response attributes.');
46
    }
47
}
48