RecoveryTokenService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 5 1
A __construct() 0 2 1
A get() 0 7 2
A identityHasActiveRecoveryToken() 0 10 1
A getFilterOptions() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Service;
20
21
use Pagerfanta\Pagerfanta;
22
use Surfnet\Stepup\Identity\Value\RecoveryTokenId;
23
use Surfnet\StepupMiddleware\ApiBundle\Exception\NotFoundException;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\RecoveryToken;
26
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RecoveryTokenQuery;
27
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RecoveryTokenRepository;
28
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RecoveryTokenStatus;
0 ignored issues
show
Bug introduced by
The type Surfnet\StepupMiddleware...lue\RecoveryTokenStatus was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
/** @extends AbstractSearchService<RecoveryToken> */
31
class RecoveryTokenService extends AbstractSearchService
32
{
33
    public function __construct(private readonly RecoveryTokenRepository $recoveryTokenRepository)
34
    {
35
    }
36
37
    /**
38
     * @return Pagerfanta<RecoveryToken>
39
     */
40
    public function search(RecoveryTokenQuery $query): Pagerfanta
41
    {
42
        $doctrineQuery = $this->recoveryTokenRepository->createSearchQuery($query);
43
44
        return $this->createPaginatorFrom($doctrineQuery, $query);
45
    }
46
47
    public function get(RecoveryTokenId $id): RecoveryToken
48
    {
49
        $recoveryToken = $this->recoveryTokenRepository->find($id);
50
        if (!$recoveryToken) {
51
            throw new NotFoundException(sprintf('Unable to find Recovery Token with id %s', $id));
52
        }
53
        return $recoveryToken;
54
    }
55
56
    public function getFilterOptions(RecoveryTokenQuery $query): array
57
    {
58
        return $this->getFilteredQueryOptions($this->recoveryTokenRepository->createOptionsQuery($query));
59
    }
60
61
    public function identityHasActiveRecoveryToken(Identity $identity): bool
62
    {
63
        $recoveryTokens = $this->recoveryTokenRepository->findBy(
64
            [
65
                'identityId' => $identity->id,
66
                'status' => RecoveryTokenStatus::active(),
67
            ],
68
        );
69
70
        return $recoveryTokens !== [];
71
    }
72
}
73