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

TokenFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 3
nc 1
nop 3
crap 1
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
/**
15
 * Build a token
16
 *
17
 * @category  Xmf\Jwt\TokenFactory
18
 * @package   Xmf
19
 * @author    Richard Griffith <[email protected]>
20
 * @copyright 2016 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @version   Release: 1.0
23
 * @link      http://xoops.org
24
 */
25
class TokenFactory
26
{
27
    /**
28
     * Create a JSON Web Token string
29
     *
30
     * @param string            $keyName          name of the key to use to sign the token
31
     * @param array|Traversable $payload          traversable set of claims, claim => value
32
     * @param int               $expirationOffset seconds from now that token will expire. If not specified,
33
     *                                             an "exp" claim will not be added or updated
34
     *
35
     * @return string a token string returned from JsonWebToken::create()
36
     *
37
     * @throws \DomainException;
38
     * @throws \InvalidArgumentException;
39
     * @throws \UnexpectedValueException;
40
     */
41 1
    public static function build($keyName, $payload, $expirationOffset = 0)
42
    {
43 1
        $token = new JsonWebToken(KeyFactory::build($keyName));
44 1
        return $token->create($payload, $expirationOffset);
45
    }
46
}
47