Passed
Push — master ( 236a58...055c31 )
by Vladimir
07:58
created

InteractsWithContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A context() 0 10 2
A remember() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Traits;
6
7
trait InteractsWithContext
8
{
9
    /**
10
     * Get the whole context or a single value.
11
     *
12
     * @param string|null $key
13
     * @param mixed       $default
14
     *
15
     * @return array|mixed
16
     */
17 2
    protected function context(string $key = null, $default = null)
18
    {
19 2
        $context = context();
20
21 2
        if ($key === null) {
22 1
            return $context;
23
        }
24
25 2
        return $context->get($key, $default);
26
    }
27
28
    /**
29
     * Remember value in context.
30
     *
31
     * @param string $key
32
     * @param mixed  $value
33
     */
34 1
    protected function remember(string $key, $value): void
35
    {
36 1
        $context = context();
37
38 1
        $context->set($key, $value);
39 1
    }
40
}
41