Passed
Push — main ( a3578d...cf5a21 )
by Filipe
01:23 queued 31s
created

Changes::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of fswatch
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\FsWatch\Directory;
13
14
use ArrayAccess;
15
use ArrayObject;
16
use IteratorAggregate;
17
use Traversable;
18
19
/**
20
 * Changes
21
 *
22
 * @package Slick\FsWatch\Directory
23
 * @implements IteratorAggregate<string, FileChange>
24
 * @implements ArrayAccess<string, FileChange>
25
 */
26
final class Changes implements IteratorAggregate, ArrayAccess
27
{
28
    /**
29
     * @var array<string, FileChange>|FileChange[]
30
     */
31
    private array $changes = [];
32
33
    /**
34
     * @inheritDoc
35
     */
36 4
    public function getIterator(): Traversable
37
    {
38 4
        return new ArrayObject($this->changes);
39
    }
40
41 5
    public function add(string $string, FileChange $fileChange): Changes
42
    {
43 5
        $this->changes[$string] = $fileChange;
44 5
        return $this;
45
    }
46
47 2
    public function offsetExists(mixed $offset): bool
48
    {
49 2
        return array_key_exists($offset, $this->changes);
50
    }
51
52 2
    public function offsetGet(mixed $offset): FileChange
53
    {
54 2
        return $this->changes[$offset];
55
    }
56
57 1
    public function offsetSet(mixed $offset, mixed $value): void
58
    {
59 1
        $this->add((string) $offset, $value);
60
    }
61
62 1
    public function offsetUnset(mixed $offset): void
63
    {
64 1
        unset($this->changes[$offset]);
65
    }
66
}
67