PasswordRequestCreationException::from()   A
last analyzed

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\ForgotPassword\Exception;
6
7
use Throwable;
8
use SixtyEightPublishers\User\Common\Exception\RuntimeException;
9
10
final class PasswordRequestCreationException extends RuntimeException
11
{
12
	public const CODE_NOT_REGISTERED_EMAIL = 1001;
13
14
	/**
15
	 * @param string $email
16
	 *
17
	 * @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestCreationException
18
	 */
19
	public static function notRegisteredEmail(string $email): self
20
	{
21
		return new static(sprintf(
22
			'Email "%s" is not registered',
23
			$email
24
		), self::CODE_NOT_REGISTERED_EMAIL);
25
	}
26
27
	/**
28
	 * @param \Throwable $e
29
	 *
30
	 * @return \SixtyEightPublishers\User\ForgotPassword\Exception\PasswordRequestCreationException
31
	 */
32
	public static function from(Throwable $e): self
33
	{
34
		return !$e instanceof self ? new static($e->getMessage(), $e->getCode(), $e) : $e;
35
	}
36
37
	/**
38
	 * @return bool
39
	 */
40
	public function isNotRegisteredEmail(): bool
41
	{
42
		return $this->getCode() === self::CODE_NOT_REGISTERED_EMAIL;
43
	}
44
}
45