HasConfig::tokenType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Alish\LaravelOtp\Drivers;
5
6
7
use Illuminate\Support\Arr;
8
9
trait HasConfig
10
{
11
12
    protected function tokenType(): string
13
    {
14
        return $this->getConfig('type', 'alphanumeric');
15
    }
16
17
    protected function tokenLength(): int
18
    {
19
        return $this->getConfig('length', 6);
20
    }
21
22
    protected function timeout(): ?int
23
    {
24
        return $this->getConfig('timeout', null);
25
    }
26
27
    protected function customSet(): ?string
28
    {
29
        return $this->getConfig('custom', null);
30
    }
31
32
    protected function shouldHash(): bool
33
    {
34
        return Arr::get($this->config, 'hash', false);
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
    }
36
37
    protected function sensitiveCase()
38
    {
39
        return Arr::get($this->config, 'case-sensitive', true);
40
    }
41
42
    protected function getConfig(string $key, $default)
43
    {
44
        return property_exists($this, 'config') ?
45
            Arr::get($this->config, $key, $default) :
46
            $default;
47
    }
48
49
}
50