HasContext::stage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\FlareClient\Concerns;
4
5
trait HasContext
6
{
7
    /** @var string|null */
8
    private $messageLevel;
9
10
    /** @var string|null */
11
    private $stage;
12
13
    /** @var array */
14
    private $userProvidedContext = [];
15
16
    public function stage(?string $stage)
17
    {
18
        $this->stage = $stage;
19
20
        return $this;
21
    }
22
23
    public function messageLevel(?string $messageLevel)
24
    {
25
        $this->messageLevel = $messageLevel;
26
27
        return $this;
28
    }
29
30
    public function getGroup(string $groupName = 'context', $default = []): array
31
    {
32
        return $this->userProvidedContext[$groupName] ?? $default;
33
    }
34
35
    public function context($key, $value)
36
    {
37
        return $this->group('context', [$key => $value]);
38
    }
39
40
    public function group(string $groupName, array $properties)
41
    {
42
        $group = $this->userProvidedContext[$groupName] ?? [];
43
44
        $this->userProvidedContext[$groupName] = array_merge_recursive_distinct(
45
            $group,
46
            $properties
47
        );
48
49
        return $this;
50
    }
51
}
52