Failed Conditions
Push — v7 ( e44e34...2109ab )
by Florent
04:36
created

AbstractSignatureTest::getJWSBuilderFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Signature\Tests;
15
16
use Jose\Component\Core\JWAManagerFactory;
17
use Jose\Component\Signature\Algorithm;
18
use Jose\Component\Signature\JWSBuilderFactory;
19
use PHPUnit\Framework\TestCase;
20
21
abstract class AbstractSignatureTest extends TestCase
22
{
23
    /**
24
     * @var JWAManagerFactory
25
     */
26
    private $algorithmManagerFactory;
27
28
    /**
29
     * @return JWAManagerFactory
30
     */
31
    protected function getAlgorithmManagerFactory(): JWAManagerFactory
32
    {
33
        if (null === $this->algorithmManagerFactory) {
34
            $this->algorithmManagerFactory = new JWAManagerFactory();
35
            $this->algorithmManagerFactory
36
                ->add('HS256', new Algorithm\HS256())
37
                ->add('HS384', new Algorithm\HS384())
38
                ->add('HS512', new Algorithm\HS512())
39
                ->add('ES256', new Algorithm\ES256())
40
                ->add('ES384', new Algorithm\ES384())
41
                ->add('ES512', new Algorithm\ES512())
42
                ->add('RS256', new Algorithm\RS256())
43
                ->add('RS384', new Algorithm\RS384())
44
                ->add('RS512', new Algorithm\RS512())
45
                ->add('PS256', new Algorithm\PS256())
46
                ->add('PS384', new Algorithm\PS384())
47
                ->add('PS512', new Algorithm\PS512())
48
                ->add('none', new Algorithm\None())
49
                ->add('EdDSA', new Algorithm\EdDSA());
50
        }
51
52
        return $this->algorithmManagerFactory;
53
    }
54
55
    /**
56
     * @var JWSBuilderFactory
57
     */
58
    private $jwsBuilderFactory;
59
60
    /**
61
     * @return JWSBuilderFactory
62
     */
63
    protected function getJWSBuilderFactory(): JWSBuilderFactory
64
    {
65
        if (null === $this->jwsBuilderFactory) {
66
            $this->jwsBuilderFactory = new JWSBuilderFactory(
67
                $this->getAlgorithmManagerFactory()
68
            );
69
        }
70
71
        return $this->jwsBuilderFactory;
72
    }
73
}
74