|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Orm\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
|
8
|
|
|
use Override; |
|
|
|
|
|
|
9
|
|
|
use Stu\Module\Message\Lib\ContactListModeEnum; |
|
10
|
|
|
use Stu\Orm\Entity\Contact; |
|
11
|
|
|
use Stu\Orm\Entity\User; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @extends EntityRepository<Contact> |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ContactRepository extends EntityRepository implements ContactRepositoryInterface |
|
17
|
|
|
{ |
|
18
|
|
|
#[Override] |
|
19
|
|
|
public function prototype(): Contact |
|
20
|
|
|
{ |
|
21
|
|
|
return new Contact(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
#[Override] |
|
25
|
|
|
public function save(Contact $post): void |
|
26
|
|
|
{ |
|
27
|
|
|
$em = $this->getEntityManager(); |
|
28
|
|
|
|
|
29
|
|
|
$em->persist($post); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
#[Override] |
|
33
|
|
|
public function delete(Contact $post): void |
|
34
|
|
|
{ |
|
35
|
|
|
$em = $this->getEntityManager(); |
|
36
|
|
|
|
|
37
|
|
|
$em->remove($post); |
|
38
|
|
|
$em->flush(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
3 |
|
#[Override] |
|
42
|
|
|
public function getByUserAndOpponent(int $userId, int $opponentId): ?Contact |
|
43
|
|
|
{ |
|
44
|
3 |
|
return $this->findOneBy([ |
|
45
|
3 |
|
'user_id' => $userId, |
|
46
|
3 |
|
'recipient' => $opponentId, |
|
47
|
3 |
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
#[Override] |
|
51
|
|
|
public function getOrderedByUser(User $user): array |
|
52
|
|
|
{ |
|
53
|
2 |
|
return $this->findBy( |
|
54
|
2 |
|
['user_id' => $user->getId()], |
|
55
|
2 |
|
['recipient' => 'asc'], |
|
56
|
2 |
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
#[Override] |
|
60
|
|
|
public function getRemoteOrderedByUser(User $user): array |
|
61
|
|
|
{ |
|
62
|
1 |
|
return $this->findBy( |
|
63
|
1 |
|
[ |
|
64
|
1 |
|
'recipient' => $user->getId(), |
|
65
|
1 |
|
'mode' => [ContactListModeEnum::FRIEND->value, ContactListModeEnum::ENEMY->value], |
|
66
|
1 |
|
], |
|
67
|
1 |
|
[ |
|
68
|
1 |
|
'mode' => 'asc', |
|
69
|
1 |
|
'user_id' => 'asc', |
|
70
|
1 |
|
], |
|
71
|
1 |
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
#[Override] |
|
75
|
|
|
public function truncateByUser(int $userId): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->getEntityManager()->createQuery( |
|
78
|
|
|
sprintf( |
|
79
|
|
|
'DELETE FROM %s c WHERE c.user_id = :userId', |
|
80
|
|
|
Contact::class |
|
81
|
|
|
), |
|
82
|
|
|
)->setParameters([ |
|
83
|
|
|
'userId' => $userId |
|
84
|
|
|
])->execute(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
#[Override] |
|
88
|
|
|
public function truncateByUserAndOpponent(int $userId, int $opponentId): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->getEntityManager()->createQuery( |
|
91
|
|
|
sprintf( |
|
92
|
|
|
'DELETE FROM %s c WHERE c.user_id = :userId OR c.recipient = :opponentId', |
|
93
|
|
|
Contact::class |
|
94
|
|
|
), |
|
95
|
|
|
)->setParameters([ |
|
96
|
|
|
'userId' => $userId, |
|
97
|
|
|
'opponentId' => $opponentId |
|
98
|
|
|
])->execute(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
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