Skip to content

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

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/
namespace Magento\SalesRule\Block\Adminhtml\Promo;

use Magento\Backend\Block\Widget\Grid\Container;

/**
* Catalog price rules
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
* @since 100.0.2
*/
class Quote extends \Magento\Backend\Block\Widget\Grid\Container
class Quote extends Container
{
/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,31 @@

namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit;

use Magento\Backend\Block\Widget\Context as WidgetContext;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\SalesRule\Model\RegistryConstants;

class GenericButton
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
* @var UrlInterface
*/
protected $urlBuilder;

/**
* Registry
*
* @var \Magento\Framework\Registry
*/
protected $registry;

/**
* Constructor
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param WidgetContext $context
* @param Registry $registry Registry
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
WidgetContext $context,
protected readonly Registry $registry
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}

/**
Expand All @@ -52,9 +47,9 @@ public function getRuleId()
/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,38 @@
*/
namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab;

use Magento\Backend\Block\Template\Context as TemplateContext;
use Magento\Backend\Block\Widget\Form\Renderer\Fieldset;
use Magento\Backend\Block\Widget\Form\Renderer\Fieldset as RendererFieldset;
use Magento\Config\Model\Config\Source\Yesno;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Data\Form as FormData;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Rule\Block\Actions as BlockActions;
use Magento\Rule\Model\Condition\AbstractCondition;
use Magento\SalesRule\Model\RegistryConstants;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Model\RuleFactory;

class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements
\Magento\Ui\Component\Layout\Tabs\TabInterface
{
/**
* Core registry
*
* @var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset
* @var RendererFieldset
*/
protected $_rendererFieldset;

/**
* @var \Magento\Rule\Block\Actions
* @var BlockActions
*/
protected $_ruleActions;

/**
* @var \Magento\Config\Model\Config\Source\Yesno
* @var Yesno
* @deprecated 100.1.0
*/
protected $_sourceYesno;
Expand All @@ -34,38 +46,33 @@ class Actions extends \Magento\Backend\Block\Widget\Form\Generic implements
*/
protected $_nameInLayout = 'actions_apply_to';

/**
* @var \Magento\SalesRule\Model\RuleFactory
*/
private $ruleFactory;

/**
* Constructor
*
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Config\Model\Config\Source\Yesno $sourceYesno
* @param \Magento\Rule\Block\Actions $ruleActions
* @param \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset
* @param TemplateContext $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Yesno $sourceYesno
* @param BlockActions $ruleActions
* @param RendererFieldset $rendererFieldset
* @param array $data
* @param \Magento\SalesRule\Model\RuleFactory|null $ruleFactory
* @param RuleFactory|null $ruleFactory
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Config\Model\Config\Source\Yesno $sourceYesno,
\Magento\Rule\Block\Actions $ruleActions,
\Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
TemplateContext $context,
Registry $registry,
FormFactory $formFactory,
Yesno $sourceYesno,
BlockActions $ruleActions,
RendererFieldset $rendererFieldset,
array $data = [],
\Magento\SalesRule\Model\RuleFactory $ruleFactory = null
private ?RuleFactory $ruleFactory = null
) {
$this->_rendererFieldset = $rendererFieldset;
$this->_ruleActions = $ruleActions;
$this->_sourceYesno = $sourceYesno;
$this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
->get(\Magento\SalesRule\Model\RuleFactory::class);
->get(RuleFactory::class);
parent::__construct($context, $registry, $formFactory, $data);
}

Expand Down Expand Up @@ -132,7 +139,7 @@ public function isHidden()
*/
protected function _prepareForm()
{
$model = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE);
$model = $this->_coreRegistry->registry(RegistryConstants::CURRENT_SALES_RULE);
$form = $this->addTabToForm($model);
$this->setForm($form);

Expand All @@ -142,11 +149,11 @@ protected function _prepareForm()
/**
* Handles addition of actions tab to supplied form.
*
* @param \Magento\SalesRule\Model\Rule $model
* @param Rule $model
* @param string $fieldsetId
* @param string $formName
* @return \Magento\Framework\Data\Form
* @throws \Magento\Framework\Exception\LocalizedException
* @return FormData
* @throws LocalizedException
*/
protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formName = 'sales_rule_form')
{
Expand All @@ -163,7 +170,7 @@ protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formN
['form_namespace' => $formName]
);

/** @var \Magento\Framework\Data\Form $form */
/** @var FormData $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('rule_');

Expand Down Expand Up @@ -221,11 +228,11 @@ protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formN
/**
* Handles addition of form name to action and its actions.
*
* @param \Magento\Rule\Model\Condition\AbstractCondition $actions
* @param AbstractCondition $actions
* @param string $formName
* @return void
*/
private function setActionFormName(\Magento\Rule\Model\Condition\AbstractCondition $actions, $formName)
private function setActionFormName(AbstractCondition $actions, $formName)
{
$actions->setFormName($formName);
if ($actions->getActions() && is_array($actions->getActions())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,37 @@

namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab;

use Magento\Backend\Block\Template\Context as TemplateContext;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Framework\App\ObjectManager;
use Magento\Backend\Block\Widget\Form\Renderer\Fieldset;
use Magento\Framework\Data\Form as FormData;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Rule\Block\Conditions as BlockConditions;
use Magento\Rule\Model\Condition\AbstractCondition;
use Magento\SalesRule\Model\RegistryConstants;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Model\RuleFactory;
use Magento\Ui\Component\Layout\Tabs\TabInterface;

/**
* Block for rendering Conditions tab on Sales Rules creation page.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements
\Magento\Ui\Component\Layout\Tabs\TabInterface
class Conditions extends Generic implements TabInterface
{
/**
* Core registry
*
* @var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset
* @var Fieldset
*/
protected $_rendererFieldset;

/**
* @var \Magento\Rule\Block\Conditions
* @var BlockConditions
*/
protected $_conditions;

Expand All @@ -37,32 +47,32 @@ class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements
protected $_nameInLayout = 'conditions_apply_to';

/**
* @var \Magento\SalesRule\Model\RuleFactory
* @var RuleFactory
*/
private $ruleFactory;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\Rule\Block\Conditions $conditions
* @param \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset
* @param TemplateContext $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param BlockConditions $conditions
* @param Fieldset $rendererFieldset
* @param array $data
* @param \Magento\SalesRule\Model\RuleFactory|null $ruleFactory
* @param RuleFactory|null $ruleFactory
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Rule\Block\Conditions $conditions,
\Magento\Backend\Block\Widget\Form\Renderer\Fieldset $rendererFieldset,
TemplateContext $context,
Registry $registry,
FormFactory $formFactory,
BlockConditions $conditions,
Fieldset $rendererFieldset,
array $data = [],
\Magento\SalesRule\Model\RuleFactory $ruleFactory = null
RuleFactory $ruleFactory = null
) {
$this->_rendererFieldset = $rendererFieldset;
$this->_conditions = $conditions;
$this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
->get(\Magento\SalesRule\Model\RuleFactory::class);
->get(RuleFactory::class);
parent::__construct($context, $registry, $formFactory, $data);
}

Expand Down Expand Up @@ -131,7 +141,7 @@ public function isHidden()
*/
protected function _prepareForm()
{
$model = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE);
$model = $this->_coreRegistry->registry(RegistryConstants::CURRENT_SALES_RULE);
$form = $this->addTabToForm($model);
$this->setForm($form);

Expand All @@ -144,8 +154,8 @@ protected function _prepareForm()
* @param Rule $model
* @param string $fieldsetId
* @param string $formName
* @return \Magento\Framework\Data\Form
* @throws \Magento\Framework\Exception\LocalizedException
* @return FormData
* @throws LocalizedException
*/
protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
{
Expand All @@ -160,7 +170,7 @@ protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $fo
['form_namespace' => $formName]
);

/** @var \Magento\Framework\Data\Form $form */
/** @var FormData $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('rule_');

Expand Down Expand Up @@ -207,11 +217,11 @@ protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $fo
/**
* Handles addition of form name to condition and its conditions.
*
* @param \Magento\Rule\Model\Condition\AbstractCondition $conditions
* @param AbstractCondition $conditions
* @param string $formName
* @return void
*/
private function setConditionFormName(\Magento\Rule\Model\Condition\AbstractCondition $conditions, $formName)
private function setConditionFormName(AbstractCondition $conditions, $formName)
{
$conditions->setFormName($formName);
if ($conditions->getConditions() && is_array($conditions->getConditions())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
*/
namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab;

use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Framework\View\Element\Template;

/**
* "Manage Coupons Codes" Tab
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Coupons extends \Magento\Framework\View\Element\Template implements \Magento\Backend\Block\Widget\Tab\TabInterface
class Coupons extends Template implements TabInterface
{
/**
* {@inheritdoc}
Expand Down
Loading