Completed
Push — master ( fe4c2e...b05117 )
by Michael
12s
created

KeyFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 2
dl 0
loc 20
rs 10
ccs 5
cts 6
cp 0.8333

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 3
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
namespace Xmf\Jwt;
13
14
use Firebase\JWT\JWT;
15
use Xmf\Key\Basic;
16
use Xmf\Key\FileStorage;
17
18
/**
19
 * Build a key to be used for JSON Web Token processing
20
 *
21
 * @category  Xmf\Jwt\KeyFactory
22
 * @package   Xmf
23
 * @author    Richard Griffith <[email protected]>
24
 * @copyright 2016 XOOPS Project (http://xoops.org)
25
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26
 * @version   Release: 1.0
27
 * @link      http://xoops.org
28
 */
29
class KeyFactory
30
{
31
    /**
32
     * Create a Key object for JWT use based on default choices. If the key has not been
33
     * established, create it.
34
     *
35
     * @param string $keyName name of the key
36
     *
37
     * @return Basic
38
     */
39 1
    public static function build($keyName)
40
    {
41 1
        if (empty($keyName) || !is_string($keyName)) {
42
            throw new \InvalidArgumentException('keyName must be a non-empty string');
43
        }
44 1
        $key = new Basic(new FileStorage(), $keyName);
45 1
        $key->create(); // will automatically skip if key has already been generated
46 1
        return $key;
47
    }
48
}
49