Skip to content

Commit 50f2380

Browse files
committed
NTR - Code quality
1 parent aa8ca4e commit 50f2380

File tree

62 files changed

+456
-344
lines changed

Some content is hidden

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

62 files changed

+456
-344
lines changed

composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
"shopware\/administration": "v6.1.*",
4747
"shopware\/storefront": "v6.1.*",
4848
"shopware\/elasticsearch": "v6.1.*",
49-
"shopware\/recovery": "v6.1.*"
49+
"shopware\/recovery": "v6.1.*",
50+
"ext-json": "*",
51+
"ext-openssl": "*"
5052
},
5153
"require-dev": {
5254
"ext-tokenizer": "*",

config/services/defaults.xml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
</service>
3333
<service id="Shopware\Production\Command\SystemUpdatePrepareCommand">
3434
<argument type="service" id="service_container" />
35+
<argument type="service" id="event_dispatcher"/>
3536
<tag name="console.command"/>
3637
</service>
3738

src/Command/SystemGenerateJwtSecretCommand.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44

55
namespace Shopware\Production\Command;
66

7-
use Doctrine\DBAL\Configuration;
8-
use Doctrine\DBAL\DriverManager;
9-
use Doctrine\DBAL\FetchMode;
10-
use Shopware\Core\Framework\Adapter\Console\ShopwareStyle;
11-
use Shopware\Production\Kernel;
127
use Symfony\Component\Console\Command\Command;
13-
use Symfony\Component\Console\Input\ArrayInput;
148
use Symfony\Component\Console\Input\InputInterface;
159
use Symfony\Component\Console\Input\InputOption;
1610
use Symfony\Component\Console\Output\OutputInterface;
@@ -43,7 +37,7 @@ protected function configure(): void
4337
public function execute(InputInterface $input, OutputInterface $output): int
4438
{
4539
$io = new SymfonyStyle($input, $output);
46-
if (!extension_loaded('openssl')) {
40+
if (!\extension_loaded('openssl')) {
4741
$io->error('extension openssl is required');
4842

4943
return 1;
@@ -74,6 +68,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
7468
$key = openssl_pkey_new([
7569
'digest_alg' => 'aes256',
7670
'private_key_type' => OPENSSL_KEYTYPE_RSA,
71+
'private_key_bits' => 4096,
7772
'encrypt_key' => $passphrase,
7873
'encrypt_key_cipher' => OPENSSL_CIPHER_AES_256_CBC
7974
]);

src/Command/SystemInstallCommand.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9696

9797
$tables = $connection->query('SHOW TABLES')->fetchAll(FetchMode::COLUMN);
9898

99-
if (!in_array('migration', $tables, true)) {
99+
if (!\in_array('migration', $tables, true)) {
100100
$output->writeln('Importing base schema.sql');
101101
$connection->exec($this->getBaseSchema());
102102
}
@@ -146,14 +146,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146146
];
147147
}
148148

149-
$commands = array_merge($commands, [
150-
[
151-
'command' => 'assets:install',
152-
'--no-cleanup' => true,
153-
],
154-
[
155-
'command' => 'cache:clear'
156-
]
149+
array_push($commands, [
150+
'command' => 'assets:install',
151+
'--no-cleanup' => true,
152+
], [
153+
'command' => 'cache:clear'
157154
]);
158155

159156
$this->runCommands($commands, $output);
@@ -170,8 +167,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
170167
private function runCommands(array $commands, OutputInterface $output): int
171168
{
172169
foreach($commands as $parameters) {
173-
$output->writeln('');
174-
175170
$command = $this->getApplication()->find($parameters['command']);
176171
unset($parameters['command']);
177172
$returnCode = $command->run(new ArrayInput($parameters, $command->getDefinition()), $output);

src/Command/SystemSetupCommand.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8585

8686
$this->generateJwt($input, $io);
8787

88-
$key = Key::createNewRandomKey();
89-
$env['APP_SECRET'] = $key->saveToAsciiSafeString();
88+
$env['APP_SECRET'] = Key::createNewRandomKey()->saveToAsciiSafeString();
9089
$env['INSTANCE_ID'] = $this->generateInstanceId();
9190

9291
$io->section('Database information');
@@ -217,11 +216,7 @@ private function generateJwt(InputInterface $input, OutputStyle $io): int
217216
$parameters['--jwt-passphrase'] = $input->getOption('jwt-passphrase');
218217
}
219218

220-
$ret = $command->run(new ArrayInput($parameters, $command->getDefinition()), $io);
221-
222-
223-
224-
return $ret;
219+
return $command->run(new ArrayInput($parameters, $command->getDefinition()), $io);
225220
}
226221

227222
private function generateInstanceId(): string

src/Command/SystemUpdateFinishCommand.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
21+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2122

2223
class SystemUpdateFinishCommand extends Command
2324
{
@@ -55,17 +56,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5556
$containerWithoutPlugins = $this->rebootKernelWithoutPlugins();
5657

5758
$context = Context::createDefaultContext();
58-
$oldVersion = (string)$this->container->get(SystemConfigService::class)
59-
->get(UpdateController::UPDATE_PREVIOUS_VERSION_KEY);
59+
/** @var SystemConfigService $systemConfigService */
60+
$systemConfigService = $this->container->get(SystemConfigService::class);
61+
$oldVersion = (string)$systemConfigService->get(UpdateController::UPDATE_PREVIOUS_VERSION_KEY);
6062

6163
$newVersion = $containerWithoutPlugins->getParameter('kernel.shopware_version');
62-
$containerWithoutPlugins->get('event_dispatcher')
63-
->dispatch(new UpdatePreFinishEvent($context, $oldVersion, $newVersion));
64+
/** @var EventDispatcherInterface $eventDispatcher */
65+
$eventDispatcher = $containerWithoutPlugins->get('event_dispatcher');
66+
$eventDispatcher->dispatch(new UpdatePreFinishEvent($context, $oldVersion, $newVersion));
6467

6568
$this->runMigrations($input, $output);
6669

6770
$updateEvent = new UpdatePostFinishEvent($context, $oldVersion, $newVersion);
68-
$this->container->get('event_dispatcher')->dispatch($updateEvent);
71+
/** @var EventDispatcherInterface $eventDispatcher */
72+
$eventDispatcher = $this->container->get('event_dispatcher');
73+
$eventDispatcher->dispatch($updateEvent);
6974

7075
$this->installAssets($input, $output);
7176

src/Command/SystemUpdatePrepareCommand.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
use Shopware\Core\Framework\Update\Event\UpdatePrePrepareEvent;
1212
use Shopware\Production\Kernel;
1313
use Symfony\Component\Console\Command\Command;
14-
use Symfony\Component\Console\Input\ArrayInput;
1514
use Symfony\Component\Console\Input\InputInterface;
16-
use Symfony\Component\Console\Input\InputOption;
1715
use Symfony\Component\Console\Output\OutputInterface;
1816
use Symfony\Component\DependencyInjection\ContainerInterface;
1917
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@@ -27,10 +25,16 @@ class SystemUpdatePrepareCommand extends Command
2725
*/
2826
private $container;
2927

30-
public function __construct(ContainerInterface $container)
28+
/**
29+
* @var EventDispatcherInterface
30+
*/
31+
private $eventDispatcher;
32+
33+
public function __construct(ContainerInterface $container, EventDispatcherInterface $eventDispatcher)
3134
{
3235
parent::__construct();
3336
$this->container = $container;
37+
$this->eventDispatcher = $eventDispatcher;
3438
}
3539

3640
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -50,13 +54,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5054
// TODO: get new version (from composer.lock?)
5155
$newVersion = '';
5256

53-
$eventDispatcher = $this->container->get('event_dispatcher');
54-
$eventDispatcher->dispatch(new UpdatePrePrepareEvent($context, $currentVersion, $newVersion));
55-
56-
$containerWithoutPlugins = $this->rebootKernelWithoutPlugins();
57+
$this->eventDispatcher->dispatch(new UpdatePrePrepareEvent($context, $currentVersion, $newVersion));
5758

5859
/** @var EventDispatcherInterface $eventDispatcher */
59-
$eventDispatcher = $containerWithoutPlugins->get('event_dispatcher');
60+
$eventDispatcher = $this->rebootKernelWithoutPlugins()->get('event_dispatcher');
6061

6162
// @internal plugins are deactivated
6263
$eventDispatcher->dispatch(new UpdatePostPrepareEvent($context, $currentVersion, $newVersion));

src/HttpKernel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Shopware\Production;
44

src/Kernel.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
namespace Shopware\Production;
66

7-
use Doctrine\DBAL\Connection;
8-
use Doctrine\DBAL\FetchMode;
9-
use Shopware\Core\Framework\Migration\MigrationStep;
10-
use Shopware\Core\Framework\Plugin\KernelPluginLoader\KernelPluginLoader;
11-
use Shopware\Production\LocalDelivery\LocalDeliveryBundle;
7+
use ReflectionMethod;
8+
use Shopware\Core\Profiling\Doctrine\DebugStack;
129
use Shopware\Production\Merchants\MerchantBundle;
1310
use Shopware\Production\Portal\PortalBundle;
14-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
15-
use Symfony\Component\HttpKernel\Bundle\Bundle;
16-
use Symfony\Component\Routing\RouteCollectionBuilder;
11+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1712

1813
class Kernel extends \Shopware\Core\Kernel
1914
{
@@ -22,7 +17,7 @@ class Kernel extends \Shopware\Core\Kernel
2217
public function __construct(
2318
string $environment,
2419
bool $debug,
25-
KernelPluginLoader $pluginLoader,
20+
BundleInterface $pluginLoader,
2621
?string $cacheId = null,
2722
?string $version = self::SHOPWARE_FALLBACK_VERSION
2823
) {
@@ -42,13 +37,13 @@ protected function initializeDatabaseConnectionVariables(): void
4237

4338
if ($this->getEnvironment() === 'dev') {
4439
self::getConnection()->getConfiguration()->setSQLLogger(
45-
new \Shopware\Core\Profiling\Doctrine\DebugStack()
40+
new DebugStack()
4641
);
4742
}
4843

49-
$reflection = new \ReflectionMethod(\Shopware\Core\Kernel::class, 'initializeDatabaseConnectionVariables');
44+
$reflection = new ReflectionMethod(\Shopware\Core\Kernel::class, 'initializeDatabaseConnectionVariables');
5045
if (!$reflection->isPrivate()) {
51-
call_user_func('parent::initializeDatabaseConnectionVariables');
46+
parent::initializeDatabaseConnectionVariables();
5247
}
5348
}
5449

src/LocalDelivery/Content/Storefront/Controller/DeliveryPackageController.php

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Shopware\Production\LocalDelivery\Content\Storefront\Controller;
44

@@ -7,26 +7,12 @@
77
use Symfony\Component\HttpFoundation\Request;
88
use Symfony\Component\HttpFoundation\Response;
99
use Symfony\Component\Routing\Annotation\Route;
10-
use Twig\Environment;
1110

1211
/**
1312
* @RouteScope(scopes={"storefront"})
1413
*/
1514
class DeliveryPackageController extends StorefrontController
1615
{
17-
/**
18-
* @var Environment
19-
*/
20-
private $twig;
21-
22-
23-
public function __construct(
24-
Environment $twig
25-
)
26-
{
27-
$this->twig = $twig;
28-
}
29-
3016
/**
3117
* @Route(name="storefront.delivery-packages", path="/delivery-packages")
3218
*/
@@ -35,16 +21,16 @@ public function packages(Request $request): Response
3521
$packages = [
3622
[
3723
'status' => 'ok cool',
38-
'zipCode' => "23333",
39-
'city' => "hamburg",
40-
'street' => "abc 123",
24+
'zipCode' => '23333',
25+
'city' => 'hamburg',
26+
'street' => 'abc 123',
4127
'content' => 'gunther'
4228
],
4329
[
4430
'status' => 'ok nich so cool',
45-
'zipCode' => "69420",
46-
'city' => "kekistan",
47-
'street' => "moin joachim 14",
31+
'zipCode' => '69420',
32+
'city' => 'kekistan',
33+
'street' => 'moin joachim 14',
4834
'content' => 'Frühlingsrollen'
4935
]
5036
];

src/LocalDelivery/Controller/DeliveryBoyStorefrontController.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@
1313
use Shopware\Production\LocalDelivery\Services\DeliveryBoyRegisterService;
1414
use Shopware\Production\LocalDelivery\Services\DeliveryPackageService;
1515
use Shopware\Storefront\Controller\StorefrontController;
16-
use Shopware\Storefront\Framework\Routing\Router;
1716
use Symfony\Component\HttpFoundation\RedirectResponse;
1817
use Symfony\Component\HttpFoundation\Request;
1918
use Symfony\Component\HttpFoundation\Response;
2019
use Symfony\Component\Routing\Annotation\Route;
21-
use Twig\Environment;
20+
use Symfony\Component\Routing\RouterInterface;
2221

2322
/**
2423
* @RouteScope(scopes={"storefront"})
2524
*/
2625
class DeliveryBoyStorefrontController extends StorefrontController
2726
{
28-
/**
29-
* @var Environment
30-
*/
31-
private $twig;
32-
3327
/**
3428
* @var DeliveryBoyRegisterService
3529
*/
@@ -41,7 +35,7 @@ class DeliveryBoyStorefrontController extends StorefrontController
4135
private $deliverBoyLoginService;
4236

4337
/**
44-
* @var Router
38+
* @var RouterInterface
4539
*/
4640
private $router;
4741

@@ -51,13 +45,11 @@ class DeliveryBoyStorefrontController extends StorefrontController
5145
private $deliveryPackageService;
5246

5347
public function __construct(
54-
Environment $twig,
5548
DeliveryBoyRegisterService $deliveryBoyRegisterService,
5649
DeliveryBoyLoginService $deliverBoyLoginService,
5750
DeliveryPackageService $deliveryPackageService,
58-
Router $router
51+
RouterInterface $router
5952
) {
60-
$this->twig = $twig;
6153
$this->deliveryBoyRegisterService = $deliveryBoyRegisterService;
6254
$this->deliverBoyLoginService = $deliverBoyLoginService;
6355
$this->router = $router;
@@ -96,7 +88,7 @@ public function deliveryBoyLogin(Request $request, SalesChannelContext $salesCha
9688
$loginData = $this->deliverBoyLoginService->getLoginDataFromRequest($request);
9789
$violations = $this->deliverBoyLoginService->validateLoginData($loginData);
9890

99-
if (count($violations) > 0) {
91+
if (\count($violations) > 0) {
10092
unset($loginData['password']);
10193

10294
return new Response(
@@ -140,7 +132,7 @@ public function deliveryBoyRegistration(Request $request, SalesChannelContext $s
140132
$data = $this->deliveryBoyRegisterService->getDeliveryBoyDataFromRequest($request);
141133
$violations = $this->deliveryBoyRegisterService->validateDeliveryBoyData($data);
142134

143-
if (count($violations) > 0) {
135+
if (\count($violations) > 0) {
144136
$errorMessages = $this->deliveryBoyRegisterService->getViolationMessages($violations);
145137

146138
unset($data['password'], $data['password_confirm']);
@@ -160,7 +152,7 @@ public function deliveryBoyRegistration(Request $request, SalesChannelContext $s
160152
/**
161153
* @Route("/deliveryboy/packageoverview", name="delivery.boy.package.overview", methods={"GET"})
162154
*/
163-
public function deliveryBoyPackageOverview(Request $request, SalesChannelContext $salesChannelContext)
155+
public function deliveryBoyPackageOverview(SalesChannelContext $salesChannelContext)
164156
{
165157
if (!$this->deliverBoyLoginService->isDeliveryBoyLoggedIn($salesChannelContext->getContext())) {
166158
return new RedirectResponse(

0 commit comments

Comments
 (0)