Skip to content

Commit 5b49df3

Browse files
committed
🔥 Legacy App, wipe EM calls, wipe dead code in App
1 parent 4812d14 commit 5b49df3

File tree

5 files changed

+40
-164
lines changed

5 files changed

+40
-164
lines changed

src/Command/Crons/CronAddRecurringPaymentsCommand.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace App\Command\Crons;
44

5-
use App\Controller\Core\Application;
65
use App\Entity\Modules\Payments\MyPaymentsMonthly;
76
use App\Entity\Modules\Payments\MyRecurringPaymentMonthly;
87
use App\Repository\Modules\Payments\MyPaymentsMonthlyRepository;
98
use App\Repository\Modules\Payments\MyRecurringPaymentMonthlyRepository;
109
use DateTime;
10+
use Doctrine\ORM\EntityManagerInterface;
1111
use Exception;
12+
use Psr\Log\LoggerInterface;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,24 +39,19 @@ class CronAddRecurringPaymentsCommand extends Command
3839
*/
3940
private $countOfAddedPayments = 0;
4041

41-
/**
42-
* @var Application $app
43-
*/
44-
private $app;
45-
4642
/**
4743
* @var string $currYearMonth
4844
*/
4945
private $currYearMonth;
5046

5147
public function __construct(
52-
Application $app,
48+
private readonly LoggerInterface $logger,
49+
private readonly EntityManagerInterface $em,
5350
private readonly MyPaymentsMonthlyRepository $paymentsMonthlyRepository,
5451
private readonly MyRecurringPaymentMonthlyRepository $recurringPaymentMonthlyRepository,
5552
string $name = null
5653
) {
5754
parent::__construct($name);
58-
$this->app = $app;
5955
$this->currYearMonth = (new DateTime())->format('Y-m');
6056
}
6157

@@ -89,8 +85,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8985
$this->report($io);
9086

9187
}catch(Exception $e){
92-
$this->app->logger->critical("There was an error while trying to add recurring payments.");
93-
$this->app->logger->critical($e->getMessage());
88+
$this->logger->critical("There was an error while trying to add recurring payments.");
89+
$this->logger->critical($e->getMessage());
9490
return Command::FAILURE;
9591
}
9692

@@ -144,8 +140,8 @@ private function addRecurringPaymentsToDatabase(array $recurringPaymentsToSet):v
144140
$payment->setMoney($recurringPayment->getMoney());
145141
$payment->setType($recurringPayment->getType());
146142

147-
$this->app->em->persist($payment);
148-
$this->app->em->flush();
143+
$this->em->persist($payment);
144+
$this->em->flush();
149145
$this->countOfAddedPayments++;
150146
}
151147

src/Controller/Core/Application.php

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@
33

44

55
use App\Controller\Utils\Utils;
6-
use App\Services\Core\Logger;
76
use App\Services\Core\Translator;
8-
use Doctrine\ORM\EntityManagerInterface;
97
use Psr\Log\LoggerInterface;
108
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
12-
use Symfony\Component\Security\Core\User\UserInterface;
13-
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
149
use Symfony\Contracts\Translation\TranslatorInterface;
1510
use Throwable;
1611

1712
class Application extends AbstractController {
1813

19-
/**
20-
* @var EntityManagerInterface
21-
*/
22-
public $em;
23-
2414
/**
2515
* @var \App\Services\Core\Translator $translator
2616
*/
@@ -31,49 +21,19 @@ class Application extends AbstractController {
3121
*/
3222
public $logger;
3323

34-
/**
35-
* @var Logger $customLoggers
36-
*/
37-
public $customLoggers;
38-
39-
/**
40-
* @deprecated should no longer be used, needs to be checked if there is some old service to be removed / replaced
41-
*/
42-
public $translations;
43-
4424
/**
4525
* @var ConfigLoaders $configLoaders
4626
*/
4727
public $configLoaders;
4828

49-
/**
50-
* @var TokenStorageInterface $tokenStorage
51-
*/
52-
private TokenStorageInterface $tokenStorage;
53-
5429
public function __construct(
55-
EntityManagerInterface $em,
5630
LoggerInterface $logger,
57-
Logger $customLoggers,
5831
TranslatorInterface $translator,
5932
ConfigLoaders $configLoaders,
60-
TokenStorageInterface $tokenStorage
6133
) {
62-
$this->customLoggers = $customLoggers;
6334
$this->logger = $logger;
64-
$this->em = $em;
6535
$this->translator = new Translator($translator);
6636
$this->configLoaders = $configLoaders;
67-
$this->tokenStorage = $tokenStorage;
68-
}
69-
70-
/**
71-
* Adds green box message on front
72-
* @param $message
73-
*/
74-
public function addSuccessFlash($message)
75-
{
76-
$this->addFlash(Utils::FLASH_TYPE_SUCCESS, $message);
7737
}
7838

7939
/**
@@ -85,28 +45,6 @@ public function addDangerFlash($message)
8545
$this->addFlash(Utils::FLASH_TYPE_DANGER, $message);
8646
}
8747

88-
/**
89-
* @param string $camelString
90-
* @return string
91-
*/
92-
public static function camelCaseToSnakeCaseConverter(string $camelString)
93-
{
94-
$camelCaseToSnakeConverter = new CamelCaseToSnakeCaseNameConverter(null, true);
95-
$snakeString = $camelCaseToSnakeConverter->normalize($camelString);
96-
return $snakeString;
97-
}
98-
99-
/**
100-
* @param string $snakeCase
101-
* @return string
102-
*/
103-
public static function snakeCaseToCamelCaseConverter(string $snakeCase)
104-
{
105-
$camelCaseToSnakeConverter = new CamelCaseToSnakeCaseNameConverter(null, true);
106-
$camelString = $camelCaseToSnakeConverter->denormalize($snakeCase);
107-
return $camelString;
108-
}
109-
11048
/**
11149
* Logs the standard exception data
11250
* @param Throwable $throwable
@@ -124,44 +62,4 @@ public function logExceptionWasThrown(Throwable $throwable, array $dataBag = [])
12462
]);
12563
}
12664

127-
/**
128-
* Returns currently logged in user
129-
* @return object|UserInterface|null
130-
*/
131-
public function getCurrentlyLoggedInUser()
132-
{
133-
return $this->getUser();
134-
}
135-
136-
/**
137-
* Will force logout from system
138-
*/
139-
public function logoutCurrentlyLoggedInUser()
140-
{
141-
$this->tokenStorage->setToken(null);
142-
}
143-
144-
/**
145-
* Begins a transaction
146-
*/
147-
public function beginTransaction(): void
148-
{
149-
$this->em->beginTransaction();
150-
}
151-
152-
/**
153-
* Commits the transaction
154-
*/
155-
public function commitTransaction(): void
156-
{
157-
$this->em->commit();
158-
}
159-
160-
/**
161-
* Rollback the transaction
162-
*/
163-
public function rollbackTransaction(): void
164-
{
165-
$this->em->rollback();
166-
}
16765
}

src/DataFixtures/Modules/Issues/MyIssues.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\DataFixtures\Modules\Issues;
44

5-
use App\Controller\Core\Application;
65
use App\DataFixtures\Providers\Modules\Issues;
76
use App\Entity\Modules\Issues\MyIssue;
87
use App\Entity\Modules\Issues\MyIssueContact;
@@ -11,6 +10,7 @@
1110
use DateTime;
1211
use Doctrine\Bundle\FixturesBundle\Fixture;
1312
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
13+
use Doctrine\ORM\EntityManagerInterface;
1414
use Doctrine\Persistence\ObjectManager;
1515
use Doctrine\DBAL\DBALException;
1616
use Faker\Factory;
@@ -22,17 +22,11 @@ class MyIssues extends Fixture implements OrderedFixtureInterface
2222
*/
2323
private $faker;
2424

25-
/**
26-
* @var Application $app
27-
*/
28-
private $app;
29-
3025
public function __construct(
31-
Application $app,
26+
private readonly EntityManagerInterface $em,
3227
private readonly MyIssueRepository $myIssueRepository
3328
) {
3429
$this->faker = Factory::create('en');
35-
$this->app = $app;
3630
}
3731

3832
/**
@@ -116,7 +110,7 @@ private function addAllIssuesProgress(ObjectManager $manager)
116110
*/
117111
private function resetIssuesIndex()
118112
{
119-
$connection = $this->app->em->getConnection();
113+
$connection = $this->em->getConnection();
120114

121115
$sql = "
122116
ALTER TABLE my_issue AUTO_INCREMENT = 1

src/DataFixtures/SettingFixtures.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace App\DataFixtures;
44

5-
use App\Controller\Core\Application;
65
use App\DataFixtures\Providers\SettingProvider;
76
use App\DTO\Settings\Finances\SettingsCurrencyDTO;
87
use App\DTO\Settings\Finances\SettingsFinancesDTO;
98
use App\Services\Exceptions\ExceptionValueNotAllowed;
109
use App\Services\Settings\SettingsLoader;
1110
use Doctrine\Bundle\FixturesBundle\Fixture;
11+
use Doctrine\ORM\EntityManagerInterface;
1212
use Doctrine\Persistence\ObjectManager;
1313
use Doctrine\DBAL\DBALException;
1414

@@ -25,17 +25,9 @@ class SettingFixtures extends Fixture
2525
const ROLES = 'ROLE_SUPER_ADMIN';
2626
const USERNAME = 'admin';
2727

28-
/**
29-
* @var Application $app
30-
*/
31-
private $app;
32-
33-
/**
34-
* SettingFixtures constructor.
35-
* @param Application $app
36-
*/
37-
public function __construct(Application $app) {
38-
$this->app = $app;
28+
public function __construct(
29+
private readonly EntityManagerInterface $em,
30+
) {
3931
}
4032

4133
/**
@@ -117,6 +109,6 @@ private function insertCurrenciesIntoDb(SettingsFinancesDTO $financesSettingsDto
117109
VALUES(2, '{$settingType}', '{$json}')
118110
";
119111

120-
$this->app->em->getConnection()->executeQuery($sql);
112+
$this->em->getConnection()->executeQuery($sql);
121113
}
122114
}

0 commit comments

Comments
 (0)