Completed
Pull Request — master (#2)
by Tomáš
09:55
created

isExpiredRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\ForgotPassword\Exception;
6
7
use SixtyEightPublishers;
8
9
final class PasswordRequestProcessException extends SixtyEightPublishers\User\Common\Exception\RuntimeException
10
{
11
	const   CODE_MISSING_REQUEST = 2001,
12
			CODE_EXPIRED_REQUEST = 2002;
13
14
	/** @var mixed  */
15
	private $uid;
16
17
	/** @var mixed  */
18
	private $rid;
19
20
	/**
21
	 * @param mixed           $uid
22
	 * @param mixed           $rid
23
	 * @param string          $message
24
	 * @param int             $code
25
	 * @param \Throwable|null $previous
26
	 */
27
	public function __construct($uid, $rid, string $message, int $code = 0, \Throwable $previous = NULL)
28
	{
29
		parent::__construct($message, $code, $previous);
30
31
		$this->uid = $uid;
32
		$this->rid = $rid;
33
	}
34
35
	/**
36
	 * @param mixed $uid
37
	 * @param mixed $rid
38
	 *
39
	 * @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestProcessException
40
	 */
41
	public static function missingRequest($uid, $rid): self
42
	{
43
		return new static($uid, $rid, sprintf(
44
			'Missing request for UID %s and RID %s',
45
			(string) $uid,
46
			(string) $rid
47
		), self::CODE_MISSING_REQUEST);
48
	}
49
50
	/**
51
	 * @param mixed $uid
52
	 * @param mixed $rid
53
	 *
54
	 * @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestProcessException
55
	 */
56
	public static function expiredRequest($uid, $rid): self
57
	{
58
		return new static($uid, $rid, sprintf(
59
			'Request for UID %s and RID %s is already expired',
60
			(string) $uid,
61
			(string) $rid
62
		), self::CODE_EXPIRED_REQUEST);
63
	}
64
65
	/**
66
	 * @return mixed
67
	 */
68
	public function getUid()
69
	{
70
		return $this->uid;
71
	}
72
73
	/**
74
	 * @return mixed
75
	 */
76
	public function getRid()
77
	{
78
		return $this->rid;
79
	}
80
81
	/**
82
	 * @return bool
83
	 */
84
	public function isMissingRequest(): bool
85
	{
86
		return $this->code === self::CODE_MISSING_REQUEST;
87
	}
88
89
	/**
90
	 * @return bool
91
	 */
92
	public function isExpiredRequest(): bool
93
	{
94
		return $this->code === self::CODE_EXPIRED_REQUEST;
95
	}
96
}
97