1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Module\Authentication\TokenVerification\Repository; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Database\Exception\PersistenceRecordNotFoundException; |
6
|
|
|
use App\Infrastructure\Database\QueryFactory; |
|
|
|
|
7
|
|
|
use App\Module\Authentication\Data\UserVerificationData; |
8
|
|
|
use App\Module\User\Data\UserData; |
9
|
|
|
|
10
|
|
|
// Class cannot be readonly as it's mocked (doubled) in tests |
11
|
|
|
// https://stackoverflow.com/questions/75128424/troubles-with-mocking-new-php-8-2-readonly-classes-with-phpunit-test-doubles |
12
|
|
|
class VerificationTokenFinderRepository |
13
|
|
|
{ |
14
|
19 |
|
public function __construct( |
15
|
|
|
private readonly QueryFactory $queryFactory, |
16
|
|
|
) { |
17
|
19 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Search and return user verification entry with token. |
21
|
|
|
* |
22
|
|
|
* @param int $id |
23
|
|
|
* |
24
|
|
|
* @return UserVerificationData |
25
|
|
|
*/ |
26
|
16 |
|
public function findUserVerification(int $id): UserVerificationData |
27
|
|
|
{ |
28
|
16 |
|
$query = $this->queryFactory->selectQuery()->select(['*'])->from('user_verification')->where( |
29
|
16 |
|
['deleted_at IS' => null, 'id' => $id] |
30
|
16 |
|
); |
31
|
16 |
|
$userVerificationRow = $query->execute()->fetch('assoc') ?: []; |
32
|
|
|
|
33
|
16 |
|
return new UserVerificationData($userVerificationRow); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param int $verificationId |
38
|
|
|
* |
39
|
|
|
* @throws PersistenceRecordNotFoundException |
40
|
|
|
* |
41
|
|
|
* @return int |
42
|
|
|
*/ |
43
|
4 |
|
public function getUserIdFromVerification(int $verificationId): int |
44
|
|
|
{ |
45
|
4 |
|
$query = $this->queryFactory->selectQuery()->select(['user_id'])->from('user_verification')->where( |
46
|
4 |
|
['deleted_at IS' => null, 'id' => $verificationId] |
47
|
4 |
|
); |
48
|
|
|
// Cake query builder return value is string |
49
|
4 |
|
$userId = $query->execute()->fetch('assoc')['user_id']; |
50
|
4 |
|
if (!$userId) { |
51
|
|
|
throw new PersistenceRecordNotFoundException('user_verification'); |
52
|
|
|
} |
53
|
|
|
|
54
|
4 |
|
return (int)$userId; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Search and return user details of given verification entry |
59
|
|
|
* even if user_verification was deleted. |
60
|
|
|
* |
61
|
|
|
* @param int $verificationId |
62
|
|
|
* |
63
|
|
|
* @return UserData |
64
|
|
|
*/ |
65
|
3 |
|
public function findUserDetailsByVerificationIncludingDeleted(int $verificationId): UserData |
66
|
|
|
{ |
67
|
3 |
|
$query = $this->queryFactory->selectQuery()->from('user_verification'); |
68
|
|
|
|
69
|
3 |
|
$query->select( |
70
|
3 |
|
[ |
71
|
3 |
|
'id' => 'user_verification.user_id', |
72
|
3 |
|
'email' => 'user.email', |
73
|
3 |
|
] |
74
|
3 |
|
)->join( |
75
|
3 |
|
['table' => 'user', 'conditions' => 'user_verification.user_id = user.id'] |
76
|
3 |
|
)->andWhere( |
77
|
3 |
|
['user_verification.id' => $verificationId] |
78
|
3 |
|
); |
79
|
3 |
|
$resultRows = $query->execute()->fetch('assoc') ?: []; |
80
|
|
|
|
81
|
3 |
|
return new UserData($resultRows); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths