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

HasContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContext() 0 3 1
A setContext() 0 5 1
A newContext() 0 5 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
}