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

PasswordRequestCreationException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

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