-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Use constructor property promotion in module Sales Rule #37228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Use constructor property promotion in module Sales Rule #37228
Conversation
Replace allmost all properties with constructor property promotion in module Sales rule: 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.
Hi @leonhelmus. Thank you for your contribution! Add the comment under your pull request to deploy test or vanilla Magento instance:
❗ Automated tests can be triggered manually with an appropriate comment:
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't make it through all the changed files in this pull request. Please apply the recurring comments to all affected files.
/** | ||
* @param \Magento\Backend\Block\Context $context | ||
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder | ||
* @param \Magento\Config\Model\Config\Structure\Element\Dependency\FieldFactory $fieldFactory | ||
* @param Context $context | ||
* @param EncoderInterface $jsonEncoder | ||
* @param FieldFactory $fieldFactory | ||
* @param array $data | ||
*/ | ||
public function __construct( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor looks useless. Please can you add a code comment to explain why it should exist?
ReportRule $reportRule, | ||
ResolverInterface $localeResolver, | ||
TimezoneInterface $localeDate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These all look like they should be promoted.
ReportRule $reportRule, | |
ResolverInterface $localeResolver, | |
TimezoneInterface $localeDate | |
protected readonly ReportRule $_reportRule, | |
protected readonly ResolverInterface $_localeResolver, | |
protected readonly TimezoneInterface $_localeDate, |
protected readonly ConditionInterfaceFactory $conditionDataFactory, | ||
protected readonly RuleLabelInterfaceFactory $ruleLabelFactory, | ||
protected readonly DataObjectProcessor $dataObjectProcessor, | ||
private ?Json $serializer = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of this argument has changed by mistake.
private ?Json $serializer = null, | |
private Json $serializer = null, |
protected readonly RuleLabelInterfaceFactory $ruleLabelFactory, | ||
protected readonly DataObjectProcessor $dataObjectProcessor, | ||
private ?Json $serializer = null, | ||
private ?RuleExtensionFactory $extensionFactory = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of this argument has changed by mistake.
private ?RuleExtensionFactory $extensionFactory = null | |
private RuleExtensionFactory $extensionFactory = null, |
public function __construct( | ||
private readonly StoreManagerInterface $storeManager, | ||
private readonly Helper $captchaData, | ||
CustomerSession $session |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not promote this property?
CustomerSession $session | |
private readonly CustomerSession $session, |
\Magento\Rule\Model\Condition\Context $context, | ||
\Magento\SalesRule\Model\Rule\Condition\Product $ruleConditionProduct, | ||
ConditionContext $context, | ||
RuleCondProduct $ruleConditionProduct, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not promote this property?
RuleCondProduct $ruleConditionProduct, | |
protected readonly RuleCondProduct $_ruleConditionProd, |
@@ -60,17 +55,16 @@ public function __construct( | |||
$primaryFieldName, | |||
$requestFieldName, | |||
CollectionFactory $collectionFactory, | |||
\Magento\Framework\Registry $registry, | |||
\Magento\SalesRule\Model\Rule\Metadata\ValueProvider $metadataValueProvider, | |||
Registry $registry, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not promote this property?
Registry $registry, | |
protected readonly Registry $coreRegistry, |
array $meta = [], | ||
array $data = [], | ||
DataPersistorInterface $dataPersistor = null | ||
private ?DataPersistorInterface $dataPersistor = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of this argument seems to have changed by mistake.
private ?DataPersistorInterface $dataPersistor = null | |
private DataPersistorInterface $dataPersistor = null, |
protected readonly SearchCriteriaBuilder $searchCriteriaBuilder, | ||
protected readonly DataObject $objectConverter, | ||
protected readonly RuleFactory $salesRuleFactory, | ||
private ?SimpleActionOptionsProvider $simpleActionOptionsProvider = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of this argument seems to have changed by mistake.
private ?SimpleActionOptionsProvider $simpleActionOptionsProvider = null | |
private SimpleActionOptionsProvider $simpleActionOptionsProvider = null |
protected readonly JoinProcessorInterface $extensionAttributesJoinProcessor, | ||
protected readonly RuleCollectionFactory $ruleCollectionFactory, | ||
protected readonly DataObjectProcessor $dataObjectProcessor, | ||
private ?CollectionProcessorInterface $collectionProcessor = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of this property seems to have changed by mistake.
private ?CollectionProcessorInterface $collectionProcessor = null | |
private CollectionProcessorInterface $collectionProcessor = null |
Description (*)
Replace allmost all properties with constructor property promotion in module Sales rule: https://stitcher.io/blog/constructor-promotion-in-php-8
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.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)