SigningTokens   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createSigner() 0 18 3
1
<?php
2
3
namespace Framgia\Jwt;
4
5
use Lcobucci\JWT\Signer;
6
use Illuminate\Support\Str;
7
use InvalidArgumentException;
8
9
trait SigningTokens
10
{
11
    protected function createSigner($algorithm = 'sha256', $type = null)
12
    {
13
        if (is_null($type)) {
14
            $type = class_basename($this);
15
        } else {
16
            $type = Str::studly($type);
17
        }
18
19
        $algorithm = Str::studly($algorithm);
20
21
        // Check if provided class exists and extends BaseVerifier
22
        // to avoid possible code injections
23
        if (is_subclass_of($class = Signer::class.'\\'.$type.'\\'.$algorithm, Signer\BaseSigner::class)) {
24
            return new $class;
25
        }
26
27
        throw new InvalidArgumentException('['.$algorithm.'] is not supported in ['.$type.'] verifier.');
28
    }
29
}
30