HasContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 3
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A stage() 0 6 1
A messageLevel() 0 6 1
A getGroup() 0 4 1
A context() 0 4 1
A group() 0 11 1
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