Skip to content

Commit 04cc29d

Browse files
author
thisismeonmounteverest
committed
Cleanup (remove ManagerTrait in favor of dependency injection).
1 parent 3e48422 commit 04cc29d

23 files changed

+163
-175
lines changed

src/Controller/GroupController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use App\Model\WikiModel;
1919
use App\Repository\GroupRepository;
2020
use App\Repository\WikiRepository;
21-
use App\Utilities\ManagerTrait;
2221
use App\Utilities\TranslatedFlashTrait;
2322
use App\Utilities\TranslatorTrait;
2423
use App\Utilities\UniqueFilenameTrait;
@@ -47,13 +46,13 @@
4746
*/
4847
class GroupController extends AbstractController
4948
{
50-
use ManagerTrait;
5149
use TranslatedFlashTrait;
5250
use TranslatorTrait;
5351
use UniqueFilenameTrait;
5452

55-
public function __construct(private GroupModel $groupModel)
56-
{
53+
public function __construct(
54+
private GroupModel $groupModel,
55+
) {
5756
}
5857

5958
/**

src/Controller/MemberController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\Logger\Logger;
88
use App\Model\MemberModel;
99
use App\Utilities\ChangeProfilePictureGlobals;
10-
use App\Utilities\ManagerTrait;
1110
use App\Utilities\ProfileSubmenu;
1211
use App\Utilities\TranslatedFlashTrait;
1312
use App\Utilities\TranslatorTrait;
@@ -31,12 +30,13 @@
3130
*/
3231
class MemberController extends AbstractController
3332
{
34-
use ManagerTrait;
3533
use TranslatedFlashTrait;
3634
use TranslatorTrait;
3735

38-
public function __construct(private ProfileSubmenu $profileSubmenu, private ChangeProfilePictureGlobals $globals)
39-
{
36+
public function __construct(
37+
private ProfileSubmenu $profileSubmenu,
38+
private ChangeProfilePictureGlobals $globals,
39+
) {
4040
}
4141

4242
#[Route(path: '/mydata', name: 'profile_personal_data_redirect')]

src/Controller/PasswordController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use App\Repository\MemberRepository;
1212
use App\Service\Mailer;
1313
use App\Utilities\ChangeProfilePictureGlobals;
14-
use App\Utilities\ManagerTrait;
1514
use App\Utilities\ProfileSubmenu;
1615
use App\Utilities\TranslatedFlashTrait;
1716
use App\Utilities\TranslatorTrait;
@@ -27,12 +26,13 @@
2726

2827
class PasswordController extends AbstractController
2928
{
30-
use ManagerTrait;
3129
use TranslatedFlashTrait;
3230
use TranslatorTrait;
3331

34-
public function __construct(private PasswordModel $passwordModel, private EntityManagerInterface $entityManager)
35-
{
32+
public function __construct(
33+
private PasswordModel $passwordModel,
34+
private EntityManagerInterface $entityManager,
35+
) {
3636
}
3737

3838
/**

src/Controller/RequestController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use App\Service\Mailer;
1717
use App\Utilities\AllowContactCheck;
1818
use App\Utilities\ConversationThread;
19-
use App\Utilities\ManagerTrait;
2019
use App\Utilities\TranslatorTrait;
2120
use Doctrine\ORM\EntityManagerInterface;
2221
use Symfony\Component\Form\Form;
@@ -34,7 +33,6 @@
3433
*/
3534
class RequestController extends BaseRequestAndInvitationController
3635
{
37-
use ManagerTrait;
3836
use TranslatorTrait;
3937

4038
public function __construct(

src/Entity/GroupMembership.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ class GroupMembership
5656
* @var Member
5757
*/
5858
#[ORM\JoinColumn(name: 'IdMember', referencedColumnName: 'id', nullable: false)]
59-
#[ORM\ManyToOne(targetEntity: \Member::class, inversedBy: 'groupMemberships')]
59+
#[ORM\ManyToOne(targetEntity: Member::class, inversedBy: 'groupMemberships')]
6060
private $member;
6161

6262
/**
6363
* @var Group
6464
*/
6565
#[ORM\JoinColumn(name: 'IdGroup', referencedColumnName: 'id', nullable: false)]
66-
#[ORM\ManyToOne(targetEntity: \Group::class, inversedBy: 'groupMemberships')]
66+
#[ORM\ManyToOne(targetEntity: Group::class, inversedBy: 'groupMemberships')]
6767
private $group;
6868

6969
/**

src/Model/ActivityModel.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,41 @@
44

55
use App\Entity\Activity;
66
use App\Repository\ActivityRepository;
7-
use App\Utilities\ManagerTrait;
7+
use Doctrine\ORM\EntityManagerInterface;
8+
use Pagerfanta\Pagerfanta;
89

910
class ActivityModel
1011
{
11-
use ManagerTrait;
12+
public function __construct(
13+
private EntityManagerInterface $entityManager,
14+
) {
15+
}
1216

13-
public function getLatest($page, $limit)
17+
public function getLatest($page, $limit): Pagerfanta
1418
{
1519
/** @var ActivityRepository $repository */
16-
$repository = $this->getManager()->getRepository(Activity::class);
20+
$repository = $this->entityManager->getRepository(Activity::class);
1721

1822
return $repository->findLatest($page, $limit);
1923
}
2024

21-
public function getProblematicActivities($page, $limit)
25+
public function getProblematicActivities($page, $limit): Pagerfanta
2226
{
2327
/** @var ActivityRepository $repository */
24-
$repository = $this->getManager()->getRepository(Activity::class);
28+
$repository = $this->entityManager->getRepository(Activity::class);
2529

2630
return $repository->findProblematicActivities($page, $limit);
2731
}
2832

29-
public function deleteAsSpamByChecker($activityIds)
33+
public function deleteAsSpamByChecker($activityIds): void
3034
{
3135
// delete all activities based on there ids
32-
$em = $this->getManager();
3336
/** @var ActivityRepository $activityRepository */
34-
$activityRepository = $em->getRepository(Activity::class);
37+
$activityRepository = $this->entityManager->getRepository(Activity::class);
3538
$activities = $activityRepository->findBy(['id' => $activityIds]);
3639
foreach ($activities as $activity) {
37-
$em->remove($activity);
40+
$this->entityManager->remove($activity);
3841
}
39-
$em->flush();
42+
$this->entityManager->flush();
4043
}
4144
}

src/Model/Admin/CommentModel.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Entity\Comment;
66
use App\Entity\Member;
77
use App\Repository\CommentRepository;
8-
use App\Utilities\ManagerTrait;
98
use Pagerfanta\Pagerfanta;
109

1110
/**
@@ -16,8 +15,6 @@
1615
*/
1716
class CommentModel
1817
{
19-
use ManagerTrait;
20-
2118
/**
2219
* @param int $page
2320
* @param int $limit
@@ -27,7 +24,7 @@ class CommentModel
2724
public function getComments($page = 1, $limit = 10)
2825
{
2926
/** @var CommentRepository $repository */
30-
$repository = $this->getManager()->getRepository(Comment::class);
27+
$repository = $this->entityManager->getRepository(Comment::class);
3128

3229
return $repository->pageAll($page, $limit);
3330
}
@@ -41,7 +38,7 @@ public function getComments($page = 1, $limit = 10)
4138
public function getCommentsForMember(Member $member, $page = 1, $limit = 10)
4239
{
4340
/** @var CommentRepository $repository */
44-
$repository = $this->getManager()->getRepository(Comment::class);
41+
$repository = $this->entityManager->getRepository(Comment::class);
4542

4643
return $repository->pageAllForMember($member, $page, $limit);
4744
}
@@ -55,7 +52,7 @@ public function getCommentsForMember(Member $member, $page = 1, $limit = 10)
5552
public function getCommentsFromMember(Member $member, $page = 1, $limit = 10)
5653
{
5754
/** @var CommentRepository $repository */
58-
$repository = $this->getManager()->getRepository(Comment::class);
55+
$repository = $this->entityManager->getRepository(Comment::class);
5956

6057
return $repository->pageAllFromMember($member, $page, $limit);
6158
}
@@ -69,7 +66,7 @@ public function getCommentsFromMember(Member $member, $page = 1, $limit = 10)
6966
public function getCommentsByQuality($quality, $page = 1, $limit = 10)
7067
{
7168
/** @var CommentRepository $repository */
72-
$repository = $this->getManager()->getRepository(Comment::class);
69+
$repository = $this->entityManager->getRepository(Comment::class);
7370

7471
return $repository->pageAllByQuality($quality, $page, $limit);
7572
}
@@ -83,7 +80,7 @@ public function getCommentsByQuality($quality, $page = 1, $limit = 10)
8380
public function getCommentsByAdminAction($action, $page = 1, $limit = 10)
8481
{
8582
/** @var CommentRepository $repository */
86-
$repository = $this->getManager()->getRepository(Comment::class);
83+
$repository = $this->entityManager->getRepository(Comment::class);
8784

8885
return $repository->pageAllByAdmiNAction($action, $page, $limit);
8986
}

src/Model/CommunityNewsModel.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use App\Entity\CommunityNewsComment;
1414
use App\Repository\CommunityNewsCommentRepository;
1515
use App\Repository\NotificationRepository;
16-
use App\Utilities\ManagerTrait;
16+
use Doctrine\ORM\EntityManagerInterface;
1717
use Pagerfanta\Doctrine\Collections\CollectionAdapter;
1818
use Pagerfanta\Pagerfanta;
1919

@@ -22,7 +22,10 @@
2222
*/
2323
class CommunityNewsModel
2424
{
25-
use ManagerTrait;
25+
public function __construct(
26+
private readonly EntityManagerInterface $entityManager,
27+
) {
28+
}
2629

2730
/**
2831
* @param int $page
@@ -33,7 +36,7 @@ class CommunityNewsModel
3336
public function getPaginator($page, $limit)
3437
{
3538
/** @var NotificationRepository $repository */
36-
$repository = $this->getManager()->getRepository(CommunityNews::class);
39+
$repository = $this->entityManager->getRepository(CommunityNews::class);
3740

3841
return $repository->pagePublic($page, $limit);
3942
}
@@ -47,15 +50,15 @@ public function getPaginator($page, $limit)
4750
public function getAdminPaginator($page, $limit)
4851
{
4952
/** @var NotificationRepository $repository */
50-
$repository = $this->getManager()->getRepository(CommunityNews::class);
53+
$repository = $this->entityManager->getRepository(CommunityNews::class);
5154

5255
return $repository->pageAll($page, $limit);
5356
}
5457

5558
public function getLatest()
5659
{
5760
/** @var NotificationRepository $repository */
58-
$repository = $this->getManager()->getRepository(CommunityNews::class);
61+
$repository = $this->entityManager->getRepository(CommunityNews::class);
5962

6063
return $repository->getLatest();
6164
}
@@ -74,15 +77,15 @@ public function getCommentsPaginator(CommunityNews $communityNews, $page, $limit
7477
public function getLatestCommunityNewsComments($page, $limit)
7578
{
7679
/** @var CommunityNewsCommentRepository $repository */
77-
$repository = $this->getManager()->getRepository(CommunityNewsComment::class);
80+
$repository = $this->entityManager->getRepository(CommunityNewsComment::class);
7881

7982
return $repository->findLatestCommunityNewsComments($page, $limit);
8083
}
8184

8285
public function deleteAsSpamByChecker($commentIds)
8386
{
8487
// delete all activities based on there ids
85-
$em = $this->getManager();
88+
$em = $this->entityManager;
8689
/** @var CommunityNewsCommentRepository $repository */
8790
$communityNewsCommentRepository = $em->getRepository(CommunityNewsComment::class);
8891
$comments = $communityNewsCommentRepository->findBy(['id' => $commentIds]);

src/Model/DonateModel.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace App\Model;
44

55
use App\Entity\Params;
6-
use App\Utilities\ManagerTrait;
76
use Carbon\Carbon;
7+
use Doctrine\ORM\EntityManagerInterface;
88

99
class DonateModel
1010
{
11-
use ManagerTrait;
11+
public function __construct(
12+
private readonly EntityManagerInterface $entityManager,
13+
) {
14+
}
1215

1316
public function getStatForDonations()
1417
{
@@ -26,7 +29,7 @@ public function getStatForDonations()
2629
WHERE
2730
created > '" . $campaignValue['campaignstartdate']->format('Y-m-d H:i:s') . "'
2831
";
29-
$connection = $this->getManager()->getConnection();
32+
$connection = $this->entityManager->getConnection();
3033
$rowYear = $connection->executeQuery($sql)->fetchAssociative();
3134
switch ($rowYear['quarter']) {
3235
case 1:
@@ -79,7 +82,7 @@ public function getStatForDonations()
7982
public function getCampaignValues()
8083
{
8184
$query = $this
82-
->getManager()
85+
->entityManager
8386
->getRepository(Params::class)
8487
->createQueryBuilder('d')
8588
->select([

src/Model/FaqModel.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
use App\Entity\Faq;
66
use App\Entity\FaqCategory;
77
use App\Repository\FaqRepository;
8-
use App\Utilities\ManagerTrait;
98
use Doctrine\DBAL\ParameterType;
9+
use Doctrine\ORM\EntityManagerInterface;
1010
use Doctrine\ORM\EntityRepository;
1111
use Pagerfanta\Pagerfanta;
1212

1313
class FaqModel
1414
{
15-
use ManagerTrait;
15+
public function __construct(
16+
private readonly EntityManagerInterface $entityManager,
17+
) {
18+
}
1619

1720
/**
1821
* Returns a Pagerfanta object that contains the currently selected logs.
@@ -25,14 +28,14 @@ class FaqModel
2528
public function getFilteredFaqs($page, $limit)
2629
{
2730
/** @var FaqRepository $repository */
28-
$repository = $this->getManager()->getRepository(Faq::class);
31+
$repository = $this->entityManager->getRepository(Faq::class);
2932

3033
return $repository->findLatest($page, $limit);
3134
}
3235

3336
public function getFaqsForCategory(FaqCategory $faqCategory): mixed
3437
{
35-
$connection = $this->getManager()->getConnection();
38+
$connection = $this->entityManager->getConnection();
3639
$stmt = $connection->prepare(
3740
"SELECT
3841
f.*
@@ -59,7 +62,7 @@ public function getFaqsForCategory(FaqCategory $faqCategory): mixed
5962
public function getFaqCategories()
6063
{
6164
/** @var EntityRepository $repository */
62-
$repository = $this->getManager()->getRepository(FaqCategory::class);
65+
$repository = $this->entityManager->getRepository(FaqCategory::class);
6366

6467
return $repository->findBy([], ['sortOrder' => 'ASC']);
6568
}

0 commit comments

Comments
 (0)