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

InteractsWithContext::context()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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