Completed
Push — master ( 8e3fe7...23d229 )
by Matthew
02:24
created

InvalidException::tokenExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
namespace Equip\Auth\Exception;
3
4
use Exception;
5
6
/**
7
 * Exception that occurs when a user specifies an authentication token that is
8
 * invalid.
9
 */
10
class InvalidException extends AuthException
11
{
12
    const CODE = 403;
13
14
    /**
15
     * @param string $token
16
     * @param Exception $previous
17
     */
18 2
    public static function tokenExpired($token, Exception $previous = null)
19
    {
20 2
        return new static(
21 2
            sprintf('Provided auth token `%s` is expired', $token),
22 2
            static::CODE,
23
            $previous
24 2
        );
25
    }
26
27
    /**
28
     * @param string $token
29
     * @param Exception $previous
30
     */
31 2
    public static function tokenUnparseable($token, Exception $previous = null)
32
    {
33 2
        return new static(
34 2
            sprintf('Provided auth token `%s` could not be parsed', $token),
35 2
            static::CODE,
36
            $previous
37 2
        );
38
    }
39
40
    /**
41
     * @param string $token
42
     * @param Exception $previous
43
     */
44 2
    public static function invalidSignature($token, Exception $previous = null)
45
    {
46 2
        return new static(
47 2
            sprintf('Signature of provided auth token `%s` is not valid', $token),
48 2
            static::CODE,
49
            $previous
50 2
        );
51
    }
52
53
    /**
54
     * @param string $token
55
     * @param Exception $previous
56
     */
57 2
    public static function invalidToken($token, Exception $previous = null)
58
    {
59 2
        return new static(
60 2
            sprintf('Provided auth token `%s` is expired or otherwise invalid', $token),
61 2
            static::CODE,
62
            $previous
63 2
        );
64
    }
65
}
66