Passed
Pull Request — master (#79)
by Mohannad
11:37
created

HasContext::setContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BeyondCode\QueryDetector\Concerns;
4
5
use Illuminate\Support\Str;
6
7
trait HasContext
8
{
9
    /** @var string */
10
    protected $context = 'querydetector';
11
12
    /**
13
     * Set specific context for the executed queries.
14
     *
15
     * @param string $context
16
     * @return self
17
     */
18
    public function setContext(string $context): self
19
    {
20
        $this->context = $context;
21
22
        return $this;
23
    }
24
25
    /**
26
     * Get the current context name
27
     *
28
     * @param string $context
29
     * @return self
30
     */
31
    public function getContext(): string
32
    {
33
        return $this->context;
34
    }
35
36
    /**
37
     * Generate a new context for the executed queries.
38
     *
39
     * @return self
40
     */
41
    public function newContext(): self
42
    {
43
        $this->setContext(Str::random());
44
45
        return $this;
46
    }
47
}