Completed
Pull Request — master (#4)
by Matthew
03:28
created

InvalidException::invalidSignature()   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 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
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 $message
16
     * @param int $code
17
     * @param Exception $previous
18
     */
19 6
    public function __construct(
20
        $message = 'The token being used is invalid',
21
        $code = 0,
22
        Exception $previous = null
23
    ) {
24 6
        if ($code === 0) {
25 2
            $code = static::CODE;
26 2
        }
27 6
        parent::__construct($message, $code, $previous);
28 6
    }
29
30
    /**
31
     * @param string $token
32
     * @param Exception $previous
33
     */
34 1
    public static function tokenExpired($token, Exception $previous = null)
35
    {
36 1
        throw new static(
37 1
            sprintf('Token expired: %s', $token),
38 1
            static::CODE,
39
            $previous
40 1
        );
41
    }
42
43
    /**
44
     * @param string $token
45
     * @param Exception $previous
46
     */
47 1
    public static function tokenUnparseable($token, Exception $previous = null)
48
    {
49 1
        throw new static(
50 1
            sprintf('Could not parse token: %s', $token),
51 1
            static::CODE,
52
            $previous
53 1
        );
54
    }
55
56
    /**
57
     * @param string $token
58
     * @param Exception $previous
59
     */
60 1
    public static function invalidSignature($token, Exception $previous = null)
61
    {
62 1
        throw new static(
63 1
            sprintf('Token signature is not valid: %s', $token),
64 1
            static::CODE,
65
            $previous
66 1
        );
67
    }
68
69
    /**
70
     * @param string $token
71
     * @param Exception $previous
72
     */
73 1
    public static function invalidToken($token, Exception $previous = null)
74
    {
75 1
        throw new static(
76 1
            sprintf('Token is expired or otherwise invalid: %s', $token),
77 1
            static::CODE,
78
            $previous
79 1
        );
80
    }
81
}
82