Skip to content

Commit 2afd74c

Browse files
Use constructor property promotion in module send friend graph ql
Replace allmost all properties with constructor property promotion in module send friend graph ql: https://stitcher.io/blog/constructor-promotion-in-php-8 Readable code * Make Magento less complex by removing properties which take up a lot of lines. * Imported all classes to make code more readable. I think the code would be a lot cleaner if all modules start using constructor promotions, since of 2.4.6 php 7.4 is dropped we can now make use of it. So let's start on it right now.
1 parent aab3ee6 commit 2afd74c

File tree

5 files changed

+19
-69
lines changed

5 files changed

+19
-69
lines changed

app/code/Magento/SendFriendGraphQl/Model/Provider/GetVisibleProduct.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,14 @@
1818
*/
1919
class GetVisibleProduct
2020
{
21-
/** @var ProductRepositoryInterface */
22-
private $productRepository;
23-
24-
/** @var Visibility */
25-
private $visibility;
26-
2721
/**
2822
* @param ProductRepositoryInterface $productRepository
2923
* @param Visibility $visibility
3024
*/
3125
public function __construct(
32-
ProductRepositoryInterface $productRepository,
33-
Visibility $visibility
26+
private readonly ProductRepositoryInterface $productRepository,
27+
private readonly Visibility $visibility
3428
) {
35-
$this->productRepository = $productRepository;
36-
$this->visibility = $visibility;
3729
}
3830

3931
/**

app/code/Magento/SendFriendGraphQl/Model/Resolver/SendEmailToFriend.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,14 @@
2121
*/
2222
class SendEmailToFriend implements ResolverInterface
2323
{
24-
/**
25-
* @var SendFriendHelper
26-
*/
27-
private $sendFriendHelper;
28-
29-
/**
30-
* @var SendEmail
31-
*/
32-
private $sendEmail;
33-
3424
/**
3525
* @param SendEmail $sendEmail
3626
* @param SendFriendHelper $sendFriendHelper
3727
*/
3828
public function __construct(
39-
SendEmail $sendEmail,
40-
SendFriendHelper $sendFriendHelper
29+
private readonly SendEmail $sendEmail,
30+
private readonly SendFriendHelper $sendFriendHelper
4131
) {
42-
$this->sendEmail = $sendEmail;
43-
$this->sendFriendHelper = $sendFriendHelper;
4432
}
4533

4634
/**

app/code/Magento/SendFriendGraphQl/Model/Resolver/SendFriendConfiguration.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@
1717
*/
1818
class SendFriendConfiguration implements ResolverInterface
1919
{
20-
/**
21-
* @var SendFriendHelper
22-
*/
23-
private $sendFriendHelper;
24-
2520
/**
2621
* @param SendFriendHelper $sendFriendHelper
2722
*/
28-
public function __construct(SendFriendHelper $sendFriendHelper)
29-
{
30-
$this->sendFriendHelper = $sendFriendHelper;
23+
public function __construct(
24+
private readonly SendFriendHelper $sendFriendHelper
25+
) {
3126
}
3227

3328
/**

app/code/Magento/SendFriendGraphQl/Model/SendFriend/SendEmail.php

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Framework\DataObjectFactory;
1313
use Magento\Framework\Event\ManagerInterface;
14+
use Magento\Framework\Exception\LocalizedException;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1617
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
@@ -23,31 +24,6 @@
2324
*/
2425
class SendEmail
2526
{
26-
/**
27-
* @var DataObjectFactory
28-
*/
29-
private $dataObjectFactory;
30-
31-
/**
32-
* @var ProductRepositoryInterface
33-
*/
34-
private $productRepository;
35-
36-
/**
37-
* @var SendFriendFactory
38-
*/
39-
private $sendFriendFactory;
40-
41-
/**
42-
* @var ManagerInterface
43-
*/
44-
private $eventManager;
45-
46-
/**
47-
* @var GetVisibleProduct
48-
*/
49-
private $visibleProductProvider;
50-
5127
/**
5228
* SendEmail constructor.
5329
* @param DataObjectFactory $dataObjectFactory
@@ -57,17 +33,12 @@ class SendEmail
5733
* @param GetVisibleProduct $visibleProductProvider
5834
*/
5935
public function __construct(
60-
DataObjectFactory $dataObjectFactory,
61-
ProductRepositoryInterface $productRepository,
62-
SendFriendFactory $sendFriendFactory,
63-
ManagerInterface $eventManager,
64-
GetVisibleProduct $visibleProductProvider
36+
private readonly DataObjectFactory $dataObjectFactory,
37+
private readonly ProductRepositoryInterface $productRepository,
38+
private readonly SendFriendFactory $sendFriendFactory,
39+
private readonly ManagerInterface $eventManager,
40+
private readonly GetVisibleProduct $visibleProductProvider
6541
) {
66-
$this->dataObjectFactory = $dataObjectFactory;
67-
$this->productRepository = $productRepository;
68-
$this->sendFriendFactory = $sendFriendFactory;
69-
$this->eventManager = $eventManager;
70-
$this->visibleProductProvider = $visibleProductProvider;
7142
}
7243

7344
/**
@@ -78,7 +49,7 @@ public function __construct(
7849
* @param array $recipientsData
7950
* @throws GraphQlInputException
8051
* @throws GraphQlNoSuchEntityException
81-
* @throws \Magento\Framework\Exception\LocalizedException
52+
* @throws LocalizedException
8253
*/
8354
public function execute(int $productId, array $senderData, array $recipientsData): void
8455
{

app/code/Magento/SendFriendGraphQl/registration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77

88
use Magento\Framework\Component\ComponentRegistrar;
99

10-
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_SendFriendGraphQl', __DIR__);
10+
ComponentRegistrar::register(
11+
ComponentRegistrar::MODULE,
12+
'Magento_SendFriendGraphQl',
13+
__DIR__
14+
);

0 commit comments

Comments
 (0)