|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Palladium\Service; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class for finding indentities based on various conditions |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
use Palladium\Mapper as Mapper; |
|
11
|
|
|
use Palladium\Entity as Entity; |
|
12
|
|
|
use Palladium\Exception\UserNotFound; |
|
13
|
|
|
use Palladium\Exception\IdentityNotFound; |
|
14
|
|
|
use Palladium\Exception\TokenNotFound; |
|
15
|
|
|
|
|
16
|
|
|
use Palladium\Contract\CanCreateMapper; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class Search |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
private $mapperFactory; |
|
24
|
|
|
private $logger; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
public function __construct(CanCreateMapper $mapperFactory, LoggerInterface $logger) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->mapperFactory = $mapperFactory; |
|
30
|
|
|
$this->logger = $logger; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function findEmailIdenityByIdentifier($identifier) |
|
35
|
|
|
{ |
|
36
|
|
|
$identity = new Entity\EmailIdentity; |
|
37
|
|
|
$identity->setIdentifier($identifier); |
|
38
|
|
|
|
|
39
|
|
|
$mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class); |
|
40
|
|
|
$mapper->fetch($identity); |
|
41
|
|
|
|
|
42
|
|
|
if ($identity->getId() === null) { |
|
43
|
|
|
$this->logger->warning('acount not found', [ |
|
44
|
|
|
'input' => [ |
|
45
|
|
|
'identifier' => $identifier, |
|
46
|
|
|
], |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
throw new IdentityNotFound; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $identity; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
View Code Duplication |
public function findCookieIdenity($userId, $series) |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
$cookie = new Entity\CookieIdentity; |
|
60
|
|
|
$cookie->setStatus(Entity\Identity::STATUS_ACTIVE); |
|
61
|
|
|
$cookie->setUserId($userId); |
|
62
|
|
|
$cookie->setSeries($series); |
|
63
|
|
|
|
|
64
|
|
|
$mapper = $this->mapperFactory->create(Mapper\CookieIdentity::class); |
|
65
|
|
|
$mapper->fetch($cookie); |
|
66
|
|
|
|
|
67
|
|
|
return $cookie; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.