Skip to content

Commit 95b9b2c

Browse files
committed
[TASK] Remove ObjectManager usage to reduce technical debt
1 parent 6add6c0 commit 95b9b2c

File tree

76 files changed

+484
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+484
-621
lines changed

Classes/Command/CleanupUnusedUploadsCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
use In2code\Powermail\Domain\Repository\AnswerRepository;
66
use In2code\Powermail\Utility\BasicFileUtility;
7-
use In2code\Powermail\Utility\ObjectUtility;
87
use Symfony\Component\Console\Command\Command;
98
use Symfony\Component\Console\Input\InputArgument;
109
use Symfony\Component\Console\Input\InputInterface;
1110
use Symfony\Component\Console\Output\OutputInterface;
1211
use TYPO3\CMS\Core\Utility\GeneralUtility;
13-
use TYPO3\CMS\Extbase\Object\Exception;
1412

1513
/**
1614
* Class CleanupUnusedUploadsCommand
@@ -32,7 +30,6 @@ public function configure()
3230
* @param InputInterface $input
3331
* @param OutputInterface $output
3432
* @return int
35-
* @throws Exception
3633
*/
3734
public function execute(InputInterface $input, OutputInterface $output): int
3835
{
@@ -56,11 +53,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
5653

5754
/**
5855
* @return array
59-
* @throws Exception
6056
*/
61-
protected function getUsedUploads()
57+
protected function getUsedUploads(): array
6258
{
63-
$answerRepository = ObjectUtility::getObjectManager()->get(AnswerRepository::class);
59+
$answerRepository = GeneralUtility::makeInstance(AnswerRepository::class);
6460
$answers = $answerRepository->findByAnyUpload();
6561
$usedUploads = [];
6662
foreach ($answers as $answer) {

Classes/Command/ExportCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
use In2code\Powermail\Domain\Repository\MailRepository;
66
use In2code\Powermail\Domain\Service\ExportService;
7-
use In2code\Powermail\Utility\ObjectUtility;
87
use Symfony\Component\Console\Command\Command;
98
use Symfony\Component\Console\Input\InputArgument;
109
use Symfony\Component\Console\Input\InputInterface;
1110
use Symfony\Component\Console\Output\OutputInterface;
11+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1212
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
1313
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException;
14-
use TYPO3\CMS\Extbase\Object\Exception;
1514
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
1615

1716
/**
@@ -60,18 +59,17 @@ public function configure()
6059
* @return int
6160
* @throws InvalidConfigurationTypeException
6261
* @throws InvalidExtensionNameException
63-
* @throws Exception
6462
* @throws InvalidQueryException
6563
*/
6664
public function execute(InputInterface $input, OutputInterface $output): int
6765
{
68-
$mailRepository = ObjectUtility::getObjectManager()->get(MailRepository::class);
69-
$exportService = ObjectUtility::getObjectManager()->get(
66+
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
67+
$exportService = GeneralUtility::makeInstance(
7068
ExportService::class,
7169
$mailRepository->findAllInPid(
7270
(int)$input->getArgument('pageUid'),
7371
[],
74-
$this->getFilterVariables($input->getArgument('period'))
72+
$this->getFilterVariables((int)$input->getArgument('period'))
7573
),
7674
$input->getArgument('format'),
7775
['domain' => $input->getArgument('domain')]
@@ -99,7 +97,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
9997
* @param int $period
10098
* @return array
10199
*/
102-
protected function getFilterVariables($period)
100+
protected function getFilterVariables(int $period): array
103101
{
104102
$variables = ['filter' => []];
105103
if ($period > 0) {

Classes/Command/ResetMarkersCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\Command;
44

5+
use Doctrine\DBAL\DBALException;
56
use In2code\Powermail\Domain\Model\Field;
67
use In2code\Powermail\Domain\Service\GetNewMarkerNamesForFormService;
78
use In2code\Powermail\Utility\DatabaseUtility;
8-
use In2code\Powermail\Utility\ObjectUtility;
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputArgument;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
13+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1314
use TYPO3\CMS\Extbase\Object\Exception;
1415

1516
/**
@@ -42,10 +43,11 @@ public function configure()
4243
* @param OutputInterface $output
4344
* @return int
4445
* @throws Exception
46+
* @throws DBALException
4547
*/
4648
public function execute(InputInterface $input, OutputInterface $output): int
4749
{
48-
$markerService = ObjectUtility::getObjectManager()->get(GetNewMarkerNamesForFormService::class);
50+
$markerService = GeneralUtility::makeInstance(GetNewMarkerNamesForFormService::class);
4951
$markers = $markerService->getMarkersForFieldsDependingOnForm(
5052
(int)$input->getArgument('formUid'),
5153
(bool)$input->getArgument('forceReset')

Classes/Controller/AbstractController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ protected function reformatParamsForAction(): void
191191

192192
// edit form: add answer id
193193
if (!empty($arguments['field']['__identity'])) {
194-
$answerRepository = $this->objectManager->get(AnswerRepository::class);
194+
$answerRepository = GeneralUtility::makeInstance(AnswerRepository::class);
195195
$answer = $answerRepository->findByFieldAndMail($fieldUid, $arguments['field']['__identity']);
196196
if ($answer !== null) {
197197
$newArguments['mail']['answers'][$iteration]['__identity'] = $answer->getUid();

Classes/Controller/FormController.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function createAction(Mail $mail, string $hash = ''): ResponseInterface
208208
if ($this->isNoOptin($mail, $hash)) {
209209
$this->sendMailPreflight($mail, $hash);
210210
} else {
211-
$mailPreflight = $this->objectManager->get(
211+
$mailPreflight = GeneralUtility::makeInstance(
212212
SendOptinConfirmationMailPreflight::class,
213213
$this->settings,
214214
$this->conf
@@ -224,7 +224,7 @@ public function createAction(Mail $mail, string $hash = ''): ResponseInterface
224224
$this->signalDispatch(__CLASS__, __FUNCTION__ . 'AfterSubmitView', [$mail, $hash, $this]);
225225
$this->prepareOutput($mail);
226226

227-
$finisherRunner = $this->objectManager->get(FinisherRunner::class);
227+
$finisherRunner = GeneralUtility::makeInstance(FinisherRunner::class);
228228
/** @noinspection PhpUnhandledExceptionInspection */
229229
$finisherRunner->callFinishers(
230230
$mail,
@@ -246,15 +246,15 @@ protected function sendMailPreflight(Mail $mail, string $hash = ''): void
246246
{
247247
try {
248248
if ($this->isSenderMailEnabled() && $this->mailRepository->getSenderMailFromArguments($mail)) {
249-
$mailPreflight = $this->objectManager->get(
249+
$mailPreflight = GeneralUtility::makeInstance(
250250
SendSenderMailPreflight::class,
251251
$this->settings,
252252
$this->conf
253253
);
254254
$mailPreflight->sendSenderMail($mail);
255255
}
256256
if ($this->isReceiverMailEnabled()) {
257-
$mailPreflight = $this->objectManager->get(SendReceiverMailPreflight::class, $this->settings);
257+
$mailPreflight = GeneralUtility::makeInstance(SendReceiverMailPreflight::class, $this->settings);
258258
$isSent = $mailPreflight->sendReceiverMail($mail, $hash);
259259
if ($isSent === false) {
260260
$this->addFlashMessage(
@@ -311,7 +311,7 @@ protected function prepareOutput(Mail $mail): void
311311
*/
312312
protected function saveMail(Mail $mail): void
313313
{
314-
$mailFactory = $this->objectManager->get(MailFactory::class);
314+
$mailFactory = GeneralUtility::makeInstance(MailFactory::class);
315315
$mailFactory->prepareMailForPersistence($mail, $this->settings);
316316
$this->mailRepository->add($mail);
317317
$this->persistenceManager->persistAll();
@@ -370,7 +370,11 @@ public function disclaimerAction(int $mail, string $hash): ResponseInterface
370370
$mail = $this->mailRepository->findByUid($mail);
371371
$status = false;
372372
if ($mail !== null && HashUtility::isHashValid($hash, $mail, 'disclaimer')) {
373-
$mailService = $this->objectManager->get(SendDisclaimedMailPreflight::class, $this->settings, $this->conf);
373+
$mailService = GeneralUtility::makeInstance(
374+
SendDisclaimedMailPreflight::class,
375+
$this->settings,
376+
$this->conf
377+
);
374378
$mailService->sendMail($mail);
375379
$this->mailRepository->removeFromDatabase($mail->getUid());
376380
$status = true;
@@ -415,7 +419,7 @@ public function initializeObject()
415419
{
416420
// @extensionScannerIgnoreLine Seems to be a false positive: getContentObject() is still correct in 9.0
417421
$this->contentObject = $this->configurationManager->getContentObject();
418-
$configurationService = $this->objectManager->get(ConfigurationService::class);
422+
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
419423
$this->conf = $configurationService->getTypoScriptConfiguration();
420424
$this->settings = ConfigurationUtility::mergeTypoScript2FlexForm($this->settings);
421425
if (ArrayUtility::isValidPath($this->settings, 'debug/settings') && $this->settings['debug']['settings']) {

Classes/Controller/ModuleController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,11 @@ public function initializeFixWrongLocalizedPagesAction(): void
318318
/**
319319
* @return void
320320
* @throws StopActionException
321-
* @throws UnsupportedRequestTypeException
322321
* @noinspection PhpUnused
323322
*/
324323
public function fixWrongLocalizedPagesAction(): void
325324
{
326-
$pageRepository = $this->objectManager->get(PageRepository::class);
325+
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
327326
$pageRepository->fixWrongLocalizedPages();
328327
$this->redirect('checkBe');
329328
}
@@ -333,7 +332,6 @@ public function fixWrongLocalizedPagesAction(): void
333332
* If not, forward to tools overview
334333
*
335334
* @return ResponseInterface|null
336-
* @throws StopActionException
337335
*/
338336
protected function checkAdminPermissions(): ?ResponseInterface
339337
{

Classes/DataProcessor/DataProcessorRunner.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\DataProcessor;
44

5+
use Exception;
56
use In2code\Powermail\Domain\Model\Mail;
67
use In2code\Powermail\Exception\ClassDoesNotExistException;
78
use In2code\Powermail\Exception\InterfaceNotImplementedException;
8-
use In2code\Powermail\Utility\ObjectUtility;
99
use In2code\Powermail\Utility\StringUtility;
10+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1011
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1112

1213
/**
1314
* Class DataProcessorRunner
1415
*/
1516
class DataProcessorRunner
1617
{
17-
1818
/**
1919
* @var string
2020
*/
21-
protected $interface = 'In2code\Powermail\DataProcessor\DataProcessorInterface';
21+
protected string $interface = 'In2code\Powermail\DataProcessor\DataProcessorInterface';
2222

2323
/**
2424
* @param Mail $mail
2525
* @param string $actionMethodName
2626
* @param array $settings
2727
* @param ContentObjectRenderer $contentObject
28-
* @throws \Exception
28+
* @throws Exception
2929
*/
3030
public function callDataProcessors(
3131
Mail $mail,
@@ -49,7 +49,7 @@ public function callDataProcessors(
4949
$dpSettings['config'] = (array)$dpSettings['config'];
5050
}
5151
/** @var AbstractDataProcessor $dataProcessor */
52-
$dataProcessor = ObjectUtility::getObjectManager()->get(
52+
$dataProcessor = GeneralUtility::makeInstance(
5353
$dpSettings['class'],
5454
$mail,
5555
$dpSettings['config'],

Classes/DataProcessor/UploadDataProcessor.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22
declare(strict_types = 1);
33
namespace In2code\Powermail\DataProcessor;
44

5+
use Exception;
56
use In2code\Powermail\Domain\Service\UploadService;
6-
use In2code\Powermail\Utility\ObjectUtility;
7-
use TYPO3\CMS\Extbase\Object\Exception;
7+
use TYPO3\CMS\Core\Utility\GeneralUtility;
88

99
/**
1010
* Class UploadDataProcessor
1111
*/
1212
class UploadDataProcessor extends AbstractDataProcessor
1313
{
14-
1514
/**
1615
* @return void
1716
* @throws Exception
18-
* @throws \Exception
1917
*/
2018
public function uploadFilesDataProcessor(): void
2119
{
22-
$uploadService = ObjectUtility::getObjectManager()->get(UploadService::class);
20+
$uploadService = GeneralUtility::makeInstance(UploadService::class);
2321
$uploadService->uploadAllFiles();
2422
}
2523
}

Classes/Domain/Factory/FileFactory.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use In2code\Powermail\Domain\Repository\FieldRepository;
99
use In2code\Powermail\Exception\DeprecatedException;
1010
use In2code\Powermail\Utility\FrontendUtility;
11-
use In2code\Powermail\Utility\ObjectUtility;
1211
use In2code\Powermail\Utility\StringUtility;
1312
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
1413
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
1514
use TYPO3\CMS\Core\Type\File\FileInfo;
15+
use TYPO3\CMS\Core\Utility\GeneralUtility;
1616
use TYPO3\CMS\Extbase\Object\Exception;
1717
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
1818
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException;
@@ -26,7 +26,7 @@ class FileFactory
2626
/**
2727
* @var array
2828
*/
29-
protected $settings = [];
29+
protected array $settings = [];
3030

3131
/**
3232
* @param array $settings
@@ -77,7 +77,7 @@ public function getInstanceFromFilesArray(array $filesArray, string $marker, int
7777
*/
7878
public function getInstanceFromUploadArguments(string $marker, string $value, array $arguments): ?File
7979
{
80-
$fieldRepository = ObjectUtility::getObjectManager()->get(FieldRepository::class);
80+
$fieldRepository = GeneralUtility::makeInstance(FieldRepository::class);
8181
$field = $fieldRepository->findByMarkerAndForm($marker, (int)$arguments['mail']['form']);
8282
if ($field !== null && $field->dataTypeFromFieldType($field->getType()) === 3 && !empty($value)) {
8383
return $this->makeFileInstance($marker, $value, 0, '', '', true);
@@ -110,7 +110,7 @@ public function getInstanceFromExistingAnswerValue(string $fileName, Answer $ans
110110
* @param string $type
111111
* @param string $temporaryName
112112
* @param bool $uploaded
113-
* @param Form $form
113+
* @param ?Form $form
114114
* @return File
115115
* @throws Exception
116116
* @throws ExtensionConfigurationExtensionNotConfiguredException
@@ -128,7 +128,7 @@ protected function makeFileInstance(
128128
bool $uploaded = false,
129129
Form $form = null
130130
): File {
131-
$file = ObjectUtility::getObjectManager()->get(File::class, $marker, $originalName, $temporaryName);
131+
$file = GeneralUtility::makeInstance(File::class, $marker, $originalName, $temporaryName);
132132
$file->setNewName(StringUtility::cleanString($originalName));
133133
$file->setUploadFolder($this->getUploadFolder());
134134
if ($size === 0) {
@@ -142,7 +142,7 @@ protected function makeFileInstance(
142142
$file->setUploaded($uploaded);
143143

144144
/* @var FieldRepository $fieldRepository */
145-
$fieldRepository = ObjectUtility::getObjectManager()->get(FieldRepository::class);
145+
$fieldRepository = GeneralUtility::makeInstance(FieldRepository::class);
146146
$file->setField($fieldRepository->findByMarkerAndForm($marker, $this->getFormUid($form)));
147147
return $file;
148148
}

Classes/Domain/Factory/MailFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use In2code\Powermail\Domain\Repository\UserRepository;
88
use In2code\Powermail\Utility\ConfigurationUtility;
99
use In2code\Powermail\Utility\FrontendUtility;
10-
use In2code\Powermail\Utility\ObjectUtility;
1110
use In2code\Powermail\Utility\SessionUtility;
1211
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
1312
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
@@ -22,7 +21,6 @@
2221
*/
2322
class MailFactory
2423
{
25-
2624
/**
2725
* @param Mail $mail
2826
* @param array $settings
@@ -36,7 +34,7 @@ class MailFactory
3634
*/
3735
public function prepareMailForPersistence(Mail $mail, array $settings): void
3836
{
39-
$mailRepository = ObjectUtility::getObjectManager()->get(MailRepository::class);
37+
$mailRepository = GeneralUtility::makeInstance(MailRepository::class);
4038
$marketingInfos = SessionUtility::getMarketingInfos();
4139
$mail
4240
->setSenderMail($mailRepository->getSenderMailFromArguments($mail))
@@ -64,12 +62,11 @@ public function prepareMailForPersistence(Mail $mail, array $settings): void
6462
/**
6563
* @param Mail $mail
6664
* @return void
67-
* @throws Exception
6865
*/
6966
protected function setFeuser(Mail $mail): void
7067
{
7168
if (FrontendUtility::isLoggedInFrontendUser()) {
72-
$userRepository = ObjectUtility::getObjectManager()->get(UserRepository::class);
69+
$userRepository = GeneralUtility::makeInstance(UserRepository::class);
7370
$feUserUid = FrontendUtility::getPropertyFromLoggedInFrontendUser('uid');
7471
$user = $userRepository->findByUid($feUserUid);
7572
if ($user !== null) {

0 commit comments

Comments
 (0)