Passed
Push — feature/initial-implementation ( 79751f...3b7c72 )
by Fike
01:53
created

DefaultContext::computeDefaults()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\API\Mapping\Conversion;
6
7
use AmaTeam\ElasticSearch\API\Entity\Mapping\ClassMappingInterface;
8
9
class DefaultContext implements DefaultsProviderContextInterface
10
{
11
    /**
12
     * @var callable
13
     */
14
    private $defaultsProvider;
15
    /**
16
     * @var string[]
17
     */
18
    private $views = [];
19
    private $validate = true;
20
    private $strictMode = false;
21
    /**
22
     * @inheritDoc
23
     */
24
    public function useStrictMode(): bool
25
    {
26
        return $this->strictMode;
27
    }
28
29
    public function setStrictMode(bool $value): DefaultContext
30
    {
31
        $this->strictMode = $value;
32
        return $this;
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function useValidation(): bool
39
    {
40
        return $this->validate;
41
    }
42
43
    public function setValidation(bool $value): DefaultContext
44
    {
45
        $this->validate = $value;
46
        return $this;
47
    }
48
49
    /**
50
     * @param callable $defaultsProvider
51
     * @return $this
52
     */
53
    public function setDefaultsProvider(callable $defaultsProvider)
54
    {
55
        $this->defaultsProvider = $defaultsProvider;
56
        return $this;
57
    }
58
59
    /**
60
     * @param string[] $views
61
     * @return $this
62
     */
63
    public function setViews(array $views)
64
    {
65
        $this->views = $views;
66
        return $this;
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function getViews(): array
73
    {
74
        return $this->views;
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function computeDefaults(string $className, ClassMappingInterface $mapping): array
81
    {
82
        if (!$this->defaultsProvider) {
83
            return [];
84
        }
85
        return call_user_func($this->defaultsProvider, $className, $mapping);
86
    }
87
}
88