Completed
Push — master ( d22c34...cd27e7 )
by Mārtiņš
02:11
created

Search::findIdentitiesByParentId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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
15
use Palladium\Contract\CanCreateMapper;
16
use Psr\Log\LoggerInterface;
17
18
19
class Search
20
{
21
22
    private $mapperFactory;
23
    private $logger;
24
25
26 7
    public function __construct(CanCreateMapper $mapperFactory, LoggerInterface $logger)
27
    {
28 7
        $this->mapperFactory = $mapperFactory;
29 7
        $this->logger = $logger;
30 7
    }
31
32
33
    /**
34
     * @param string $identifier
35
     */
36 2
    public function findEmailIdenityByIdentifier($identifier)
37
    {
38 2
        $identity = new Entity\EmailIdentity;
39 2
        $identity->setIdentifier($identifier);
40
41 2
        $mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class);
42 2
        $mapper->fetch($identity);
43
44 2 View Code Duplication
        if ($identity->getId() === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
45 1
            $this->logger->warning('identity not found', [
46
                'input' => [
47 1
                    'identifier' => $identifier,
48
                ],
49
            ]);
50
51 1
            throw new IdentityNotFound;
52
        }
53
54 1
        return $identity;
55
    }
56
57
58
    /**
59
     * @param string $token
60
     * @param int $action
61
     */
62 2
    public function findEmailIdenityByToken($token, $action = Entity\Identity::ACTION_ANY)
63
    {
64 2
        $identity = new Entity\EmailIdentity;
65
66 2
        $identity->setToken($token);
67 2
        $identity->setTokenAction($action);
68 2
        $identity->setTokenEndOfLife(time());
69
70 2
        $mapper = $this->mapperFactory->create(Mapper\Identity::class);
71 2
        $mapper->fetch($identity);
72
73 2 View Code Duplication
        if ($identity->getId() === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
74 1
            $this->logger->warning('identity not found', [
75
                'input' => [
76 1
                    'token' => $token,
77
                ],
78
            ]);
79
80 1
            throw new IdentityNotFound;
81
        }
82
83 1
        return $identity;
84
    }
85
86
87
    /**
88
     * @param int $accountId
89
     * @param string $series
90
     */
91 1
    public function findCookieIdenity($accountId, $series)
92
    {
93 1
        $cookie = new Entity\CookieIdentity;
94 1
        $cookie->setStatus(Entity\Identity::STATUS_ACTIVE);
95 1
        $cookie->setAccountId($accountId);
96 1
        $cookie->setSeries($series);
97
98 1
        $mapper = $this->mapperFactory->create(Mapper\CookieIdentity::class);
99 1
        $mapper->fetch($cookie);
100
101 1
        return $cookie;
102
    }
103
104
105 1 View Code Duplication
    public function findIdentitiesByAccountId($accountId, $type = Entity\Identity::TYPE_ANY, $status = Entity\Identity::STATUS_ACTIVE)
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...
106
    {
107 1
        $collection = new Entity\IdentityCollection;
108 1
        $collection->forAccountId($accountId);
109 1
        $collection->forType($type);
110 1
        $collection->forStatus($status);
111
112 1
        $mapper = $this->mapperFactory->create(Mapper\IdentityCollection::class);
113 1
        $mapper->fetch($collection);
114
115 1
        return $collection;
116
    }
117
118
119 1 View Code Duplication
    public function findIdentitiesByParentId($parentId, $status = Entity\Identity::STATUS_ACTIVE)
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...
120
    {
121 1
        $collection = new Entity\IdentityCollection;
122 1
        $collection->forParentId($parentId);
123 1
        $collection->forStatus($status);
124
125 1
        $mapper = $this->mapperFactory->create(Mapper\IdentityCollection::class);
126 1
        $mapper->fetch($collection);
127
128 1
        return $collection;
129
    }
130
}
131