Completed
Push — master ( afc88d...d0e6e6 )
by Mārtiņš
02:23
created

Locator::retrieveIdenitiesByUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 0
cts 10
cp 0
rs 9.4285
nc 1
cc 1
eloc 8
nop 3
crap 2
1
<?php
2
3
namespace Palladium\Service;
4
5
/**
6
 * Purely written dumping grownd for shared methods of Serive\Authentication namespace
7
 */
8
9
use Palladium\Component\CanCreateMapper;
10
use Palladium\Mapper\Authentication as Mapper;
11
use Palladium\Entity\Authentication as Entity;
12
13
use Monolog\Logger;
14
15
16
abstract class Locator
17
{
18
19
    protected $mapperFactory;
20
    protected $logger;
21
22
23
    public function __construct(CanCreateMapper $mapperFactory, Psr\Log\LoggerInterface $logger)
24
    {
25
        $this->mapperFactory = $mapperFactory;
26
        $this->logger = $logger;
27
    }
28
29
30 View Code Duplication
    protected function retrieveIdenityByToken(Entity\Identity $identity, $token, $action = Entity\Identity::ACTION_ANY)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
31
    {
32
        $identity->setToken($token);
33
        $identity->setTokenAction($action);
34
        $identity->setTokenEndOfLife(time());
35
36
        $mapper = $this->mapperFactory->create(Mapper\Identity::class);
37
        $mapper->fetch($identity);
38
39
        return $identity;
40
    }
41
42
43
    protected function retrieveEmailIdenityByIdentifier($identifier)
44
    {
45
        $identity = new Entity\EmailIdentity;
46
        $mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class);
47
48
        $identity->setIdentifier($identifier);
49
50
        $mapper->fetch($identity);
51
52
        return $identity;
53
    }
54
55
56
    protected function discardAllUserCookies($userId)
57
    {
58
        /**
59
         * @NOTE: this operation might require transaction
60
         * or a change in how store() is implemnted in IdentityCollection mapper
61
         */
62
        $list = $this->retrieveIdenitiesByUserId($userId, Entity\Identity::TYPE_COOKIE);
63
64
        foreach ($list as $identity) {
65
            $identity->setStatus(Entity\Identity::STATUS_DISCARDED);
66
        }
67
68
        $mapper = $this->mapperFactory->create(Mapper\IdentityCollection::class);
69
        $mapper->store($list);
70
    }
71
72
73
    protected function retrieveIdenitiesByUserId($userId, $type = Entity\Identity::TYPE_ANY, $status = Entity\Identity::STATUS_ACTIVE)
74
    {
75
        $collection = new Entity\IdentityCollection;
76
        $collection->forUserId($userId);
77
        $collection->forType($type);
78
        $collection->forStatus($status);
79
80
        $mapper = $this->mapperFactory->create(Mapper\IdentityCollection::class);
81
        $mapper->fetch($collection);
82
83
        return $collection;
84
    }
85
}
86