Completed
Push — master ( b9a5c4...4587ca )
by Mārtiņš
02:02
created

Search::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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 4
    public function __construct(CanCreateMapper $mapperFactory, LoggerInterface $logger)
28
    {
29 4
        $this->mapperFactory = $mapperFactory;
30 4
        $this->logger = $logger;
31 4
    }
32
33
34 2
    public function findEmailIdenityByIdentifier($identifier)
35
    {
36 2
        $identity = new Entity\EmailIdentity;
37 2
        $identity->setIdentifier($identifier);
38
39 2
        $mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class);
40 2
        $mapper->fetch($identity);
41
42 2
        if ($identity->getId() === null) {
43 1
            $this->logger->warning('acount not found', [
44
                'input' => [
45 1
                    'identifier' => $identifier,
46
                ],
47
            ]);
48
49 1
            throw new IdentityNotFound;
50
        }
51
52 1
        return $identity;
53
    }
54
55
56 1
    public function findEmailIdenityByToken($token, $action = Entity\Identity::ACTION_ANY)
57
    {
58 1
        $identity = new Entity\EmailIdentity;
59
60 1
        $identity->setToken($token);
61 1
        $identity->setTokenAction($action);
62 1
        $identity->setTokenEndOfLife(time());
63
64 1
        $mapper = $this->mapperFactory->create(Mapper\Identity::class);
65 1
        $mapper->fetch($identity);
66
67 1
        return $identity;
68
    }
69
70
71 1
    public function findCookieIdenity($userId, $series)
72
    {
73 1
        $cookie = new Entity\CookieIdentity;
74 1
        $cookie->setStatus(Entity\Identity::STATUS_ACTIVE);
75 1
        $cookie->setUserId($userId);
76 1
        $cookie->setSeries($series);
77
78 1
        $mapper = $this->mapperFactory->create(Mapper\CookieIdentity::class);
79 1
        $mapper->fetch($cookie);
80
81 1
        return $cookie;
82
    }
83
}
84