Defaults   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
dl 0
loc 46
rs 10
c 1
b 0
f 1
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A merge() 0 5 1
A offsetUnset() 0 3 1
A offsetExists() 0 3 1
A offsetGet() 0 3 1
A offsetSet() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema;
6
7
use Cycle\ORM\Mapper\Mapper;
8
use Cycle\ORM\SchemaInterface;
9
use Cycle\ORM\Select\Repository;
10
use Cycle\ORM\Select\Source;
11
12
/**
13
 * @implements \ArrayAccess<int, mixed>
14
 */
15
final class Defaults implements \ArrayAccess
16
{
17
    /**
18
     * @param array<int, mixed> $defaults
19
     */
20
    public function __construct(
21
        private array $defaults = [
22
            SchemaInterface::MAPPER => Mapper::class,
23
            SchemaInterface::REPOSITORY => Repository::class,
24
            SchemaInterface::SOURCE => Source::class,
25
            SchemaInterface::SCOPE => null,
26
            SchemaInterface::TYPECAST_HANDLER => null,
27
        ],
28
    ) {}
29
30
    /**
31
     * @param array<int, mixed> $defaults
32
     */
33
    public function merge(array $defaults): self
34
    {
35
        $this->defaults = $defaults + $this->defaults;
36
37
        return $this;
38
    }
39
40
    public function offsetExists(mixed $offset): bool
41
    {
42
        return isset($this->defaults[$offset]);
43
    }
44
45
    public function offsetGet(mixed $offset): mixed
46
    {
47
        return $this->defaults[$offset];
48
    }
49
50
    /**
51
     * @param int $offset
52
     */
53
    public function offsetSet(mixed $offset, mixed $value): void
54
    {
55
        $this->defaults[$offset] = $value;
56
    }
57
58
    public function offsetUnset(mixed $offset): void
59
    {
60
        unset($this->defaults[$offset]);
61
    }
62
}
63