Passed
Push — master ( fbb13e...d759f2 )
by Milad
02:55
created

Algorithm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A keySize() 0 7 1
A name() 0 3 1
A algorithm() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace MiladRahimi\Jwt\Cryptography\Algorithms\Ecdsa;
4
5
/**
6
 * Automatic algorithm-based value generator
7
 */
8
trait Algorithm
9
{
10
    protected static string $name;
11
12
    /**
13
     * @inheritdoc
14
     */
15
    public function name(): string
16
    {
17
        return static::$name;
18
    }
19
20
    protected function algorithm(): int
21
    {
22
        return [
23
            'ES256' => OPENSSL_ALGO_SHA256,
24
            'ES256K' => OPENSSL_ALGO_SHA256,
25
            'ES384' => OPENSSL_ALGO_SHA512,
26
        ][$this->name()];
27
    }
28
29
    protected function keySize(): int
30
    {
31
        return [
32
            'ES256' => 256,
33
            'ES256K' => 256,
34
            'ES384' => 384,
35
        ][static::$name];
36
    }
37
}
38