Passed
Push — 2.x ( b60830...92ccd4 )
by Aleksei
13:13
created

Defaults::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 9
rs 10
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
final class Defaults implements \ArrayAccess
13
{
14
    /**
15
     * @param array<int, mixed> $defaults
16
     */
17
    public function __construct(
18
        private array $defaults = [
19
            SchemaInterface::MAPPER => Mapper::class,
20
            SchemaInterface::REPOSITORY => Repository::class,
21
            SchemaInterface::SOURCE => Source::class,
22
            SchemaInterface::SCOPE => null,
23
            SchemaInterface::TYPECAST_HANDLER => null,
24
        ]
25
    ) {
26
    }
27
28
    /**
29
     * @param array<int, mixed> $defaults
30
     */
31
    public function merge(array $defaults): self
32
    {
33
        $this->defaults = $defaults + $this->defaults;
34
35
        return $this;
36
    }
37
38
    public function offsetExists(mixed $offset): bool
39
    {
40
        return isset($this->defaults[$offset]);
41
    }
42
43
    public function offsetGet(mixed $offset): mixed
44
    {
45
        return $this->defaults[$offset];
46
    }
47
48
    public function offsetSet(mixed $offset, mixed $value): void
49
    {
50
        $this->defaults[$offset] = $value;
51
    }
52
53
    public function offsetUnset(mixed $offset): void
54
    {
55
        unset($this->defaults[$offset]);
56
    }
57
}
58