Skip to content

Commit 84e1628

Browse files
authored
ENGCOM-7022: Cleanup ObjectManager usage - Magento_AsynchronousOperations #27083
2 parents b06ac44 + c489601 commit 84e1628

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

app/code/Magento/AsynchronousOperations/Model/BulkManagement.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\AsynchronousOperations\Model;
79

8-
use Magento\Framework\App\ObjectManager;
9-
use Magento\Framework\App\ResourceConnection;
1010
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
1111
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory;
1212
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
13-
use Magento\Framework\MessageQueue\BulkPublisherInterface;
14-
use Magento\Framework\EntityManager\EntityManager;
15-
use Magento\Framework\EntityManager\MetadataPool;
1613
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\CollectionFactory;
1714
use Magento\Authorization\Model\UserContextInterface;
15+
use Magento\Framework\App\ResourceConnection;
16+
use Magento\Framework\Bulk\BulkManagementInterface;
17+
use Magento\Framework\EntityManager\EntityManager;
18+
use Magento\Framework\EntityManager\MetadataPool;
19+
use Magento\Framework\MessageQueue\BulkPublisherInterface;
20+
use Psr\Log\LoggerInterface;
1821

1922
/**
20-
* Class BulkManagement
21-
*
22-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
23+
* Asynchronous Bulk Management
2324
*/
24-
class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
25+
class BulkManagement implements BulkManagementInterface
2526
{
2627
/**
2728
* @var EntityManager
@@ -54,12 +55,12 @@ class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
5455
private $resourceConnection;
5556

5657
/**
57-
* @var \Magento\Authorization\Model\UserContextInterface
58+
* @var UserContextInterface
5859
*/
5960
private $userContext;
6061

6162
/**
62-
* @var \Psr\Log\LoggerInterface
63+
* @var LoggerInterface
6364
*/
6465
private $logger;
6566

@@ -71,7 +72,7 @@ class BulkManagement implements \Magento\Framework\Bulk\BulkManagementInterface
7172
* @param BulkPublisherInterface $publisher
7273
* @param MetadataPool $metadataPool
7374
* @param ResourceConnection $resourceConnection
74-
* @param \Psr\Log\LoggerInterface $logger
75+
* @param LoggerInterface $logger
7576
* @param UserContextInterface $userContext
7677
*/
7778
public function __construct(
@@ -81,8 +82,8 @@ public function __construct(
8182
BulkPublisherInterface $publisher,
8283
MetadataPool $metadataPool,
8384
ResourceConnection $resourceConnection,
84-
\Psr\Log\LoggerInterface $logger,
85-
UserContextInterface $userContext = null
85+
LoggerInterface $logger,
86+
UserContextInterface $userContext
8687
) {
8788
$this->entityManager = $entityManager;
8889
$this->bulkSummaryFactory= $bulkSummaryFactory;
@@ -91,7 +92,7 @@ public function __construct(
9192
$this->resourceConnection = $resourceConnection;
9293
$this->publisher = $publisher;
9394
$this->logger = $logger;
94-
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
95+
$this->userContext = $userContext;
9596
}
9697

9798
/**

app/code/Magento/AsynchronousOperations/Model/MassConsumer.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\AsynchronousOperations\Model;
109

11-
use Magento\Framework\Registry;
1210
use Magento\Framework\MessageQueue\CallbackInvokerInterface;
1311
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
12+
use Magento\Framework\MessageQueue\ConsumerInterface;
1413
use Magento\Framework\MessageQueue\EnvelopeInterface;
1514
use Magento\Framework\MessageQueue\QueueInterface;
16-
use Magento\Framework\MessageQueue\ConsumerInterface;
15+
use Magento\Framework\Registry;
1716

1817
/**
1918
* Class Consumer used to process OperationInterface messages.
@@ -28,19 +27,19 @@ class MassConsumer implements ConsumerInterface
2827
private $invoker;
2928

3029
/**
31-
* @var \Magento\Framework\MessageQueue\ConsumerConfigurationInterface
30+
* @var ConsumerConfigurationInterface
3231
*/
3332
private $configuration;
3433

3534
/**
36-
* @var Registry
35+
* @var MassConsumerEnvelopeCallbackFactory
3736
*/
38-
private $registry;
37+
private $massConsumerEnvelopeCallback;
3938

4039
/**
41-
* @var MassConsumerEnvelopeCallbackFactory
40+
* @var Registry
4241
*/
43-
private $massConsumerEnvelopeCallback;
42+
private $registry;
4443

4544
/**
4645
* Initialize dependencies.
@@ -54,13 +53,12 @@ public function __construct(
5453
CallbackInvokerInterface $invoker,
5554
ConsumerConfigurationInterface $configuration,
5655
MassConsumerEnvelopeCallbackFactory $massConsumerEnvelopeCallback,
57-
Registry $registry = null
56+
Registry $registry
5857
) {
5958
$this->invoker = $invoker;
6059
$this->configuration = $configuration;
6160
$this->massConsumerEnvelopeCallback = $massConsumerEnvelopeCallback;
62-
$this->registry = $registry ?? \Magento\Framework\App\ObjectManager::getInstance()
63-
->get(Registry::class);
61+
$this->registry = $registry;
6462
}
6563

6664
/**

app/code/Magento/AsynchronousOperations/Model/MassSchedule.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\AsynchronousOperations\Model;
109

11-
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\DataObject\IdentityGeneratorInterface;
13-
use Magento\Framework\Exception\LocalizedException;
14-
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory;
1510
use Magento\AsynchronousOperations\Api\Data\AsyncResponseInterface;
1611
use Magento\AsynchronousOperations\Api\Data\AsyncResponseInterfaceFactory;
1712
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterface;
18-
use Magento\Framework\Bulk\BulkManagementInterface;
19-
use Magento\Framework\Exception\BulkException;
20-
use Psr\Log\LoggerInterface;
13+
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory;
2114
use Magento\AsynchronousOperations\Model\ResourceModel\Operation\OperationRepository;
2215
use Magento\Authorization\Model\UserContextInterface;
16+
use Magento\Framework\Bulk\BulkManagementInterface;
17+
use Magento\Framework\DataObject\IdentityGeneratorInterface;
2318
use Magento\Framework\Encryption\Encryptor;
19+
use Magento\Framework\Exception\BulkException;
20+
use Magento\Framework\Exception\LocalizedException;
21+
use Psr\Log\LoggerInterface;
2422

2523
/**
2624
* Class MassSchedule used for adding multiple entities as Operations to Bulk Management with the status tracking
@@ -30,7 +28,7 @@
3028
class MassSchedule
3129
{
3230
/**
33-
* @var \Magento\Framework\DataObject\IdentityGeneratorInterface
31+
* @var IdentityGeneratorInterface
3432
*/
3533
private $identityService;
3634

@@ -45,7 +43,7 @@ class MassSchedule
4543
private $itemStatusInterfaceFactory;
4644

4745
/**
48-
* @var \Magento\Framework\Bulk\BulkManagementInterface
46+
* @var BulkManagementInterface
4947
*/
5048
private $bulkManagement;
5149

@@ -60,7 +58,7 @@ class MassSchedule
6058
private $operationRepository;
6159

6260
/**
63-
* @var \Magento\Authorization\Model\UserContextInterface
61+
* @var UserContextInterface
6462
*/
6563
private $userContext;
6664

@@ -79,7 +77,7 @@ class MassSchedule
7977
* @param LoggerInterface $logger
8078
* @param OperationRepository $operationRepository
8179
* @param UserContextInterface $userContext
82-
* @param Encryptor|null $encryptor
80+
* @param Encryptor $encryptor
8381
*/
8482
public function __construct(
8583
IdentityGeneratorInterface $identityService,
@@ -88,17 +86,17 @@ public function __construct(
8886
BulkManagementInterface $bulkManagement,
8987
LoggerInterface $logger,
9088
OperationRepository $operationRepository,
91-
UserContextInterface $userContext = null,
92-
Encryptor $encryptor = null
89+
UserContextInterface $userContext,
90+
Encryptor $encryptor
9391
) {
9492
$this->identityService = $identityService;
9593
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
9694
$this->asyncResponseFactory = $asyncResponseFactory;
9795
$this->bulkManagement = $bulkManagement;
9896
$this->logger = $logger;
9997
$this->operationRepository = $operationRepository;
100-
$this->userContext = $userContext ?: ObjectManager::getInstance()->get(UserContextInterface::class);
101-
$this->encryptor = $encryptor ?: ObjectManager::getInstance()->get(Encryptor::class);
98+
$this->userContext = $userContext;
99+
$this->encryptor = $encryptor;
102100
}
103101

104102
/**

0 commit comments

Comments
 (0)