Skip to content

Commit

Permalink
Merged PR 38244: Code cleanup for coding standards
Browse files Browse the repository at this point in the history
## What's being changed

We've audited the entire module to bring it into line with the latest Magento coding standards. We've also inlined var declarations, made dotblock updates and adopted use statements.

## Why it's being changed

Cleaning up code for a green build on Chat module.

## How to test
1. Enable Chat in Configuration -> Chat
2. Visit home page
3. Wait for chat to load and send message.
4. Log into DD and insure message, profile etc .. are working as expected.
5. Visit Chat studio page from Magento Admin, ensure page is displayed.

Related work items: #178895, #178896, #178897
  • Loading branch information
pvpcookie committed Aug 31, 2022
1 parent 9c6bc88 commit ad737a8
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 74 deletions.
38 changes: 26 additions & 12 deletions Block/Adminhtml/Config/Settings/ButtonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use Dotdigitalgroup\Chat\Model\Config;
use Dotdigitalgroup\Email\Helper\Data;
use Dotdigitalgroup\Email\Helper\OauthValidator;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Button;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\Exception\LocalizedException;

abstract class ButtonField extends \Magento\Config\Block\System\Config\Form\Field
abstract class ButtonField extends Field
{
/**
* @var Config
Expand All @@ -26,14 +30,15 @@ abstract class ButtonField extends \Magento\Config\Block\System\Config\Form\Fiel

/**
* ButtonField constructor.
* @param \Magento\Backend\Block\Template\Context $context
*
* @param Context $context
* @param Config $config
* @param Data $helper
* @param OauthValidator $oauthValidator
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
Context $context,
Config $config,
Data $helper,
OauthValidator $oauthValidator,
Expand All @@ -47,6 +52,7 @@ public function __construct(

/**
* Returns the class name based on API Creds validation
*
* @return string
*/
public function getCssClass()
Expand All @@ -58,20 +64,25 @@ public function getCssClass()
}

/**
* Get Button url
*
* @return string
*/
abstract protected function getButtonUrl();

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* Get HTML element
*
* @param AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function _getElementHtml(AbstractElement $element)
{
return $this->getLayout()
->createBlock(Button::class)
->setType('button')

$block = $this->getLayout()->createBlock(Button::class);
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
return $block->setType('button')
->setLabel(__('Configure'))
->setOnClick(sprintf("window.open('%s','_blank')", $this->getButtonUrl()))
->setData('class', $this->getCssClass())
Expand All @@ -80,17 +91,20 @@ public function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractEle

/**
* Removes use Default Checkbox
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @param AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
public function render(AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* @param $url
* Get Dotdigital authorised url
*
* @param string $url
* @return string
*/
protected function getEcAuthorisedUrl($url)
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Config/Settings/ConfigureTeamsButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ConfigureTeamsButton extends ButtonField
{
/**
* Returns the URL to Configure Chat Teams
*
* @return string
*/
protected function getButtonUrl()
Expand Down
1 change: 1 addition & 0 deletions Block/Adminhtml/Config/Settings/ConfigureWidgetButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ConfigureWidgetButton extends ButtonField
{
/**
* Returns the Url to Configure Chat Widget
*
* @return string
*/
protected function getButtonUrl()
Expand Down
3 changes: 3 additions & 0 deletions Block/Adminhtml/StudioChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class StudioChat extends \Magento\Backend\Block\Template implements EngagementCl

/**
* StudioChat constructor.
*
* @param Context $context
* @param IntegrationSetupFactory $integrationSetupFactory
* @param Data $helper
Expand All @@ -64,6 +65,8 @@ public function __construct(
}

/**
* Get action url for chat
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand Down
31 changes: 25 additions & 6 deletions Controller/Adminhtml/Studio/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
use Dotdigitalgroup\Chat\Model\Config;
use Dotdigitalgroup\Email\Helper\Data;
use Magento\Backend\App\Action;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Result\PageFactory;

class Index extends \Magento\Backend\App\AbstractAction
class Index extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Dotdigitalgroup_Chat::config';
public const ADMIN_RESOURCE = 'Dotdigitalgroup_Chat::config';

/**
* @var PageFactory
*/
protected $resultPageFactory;

/**
* @var Data
Expand All @@ -27,30 +34,42 @@ class Index extends \Magento\Backend\App\AbstractAction

/**
* Index constructor.
*
* @param Action\Context $context
* @param PageFactory $resultPageFactory
* @param Data $helper
* @param Config $config
*/
public function __construct(
Action\Context $context,
PageFactory $resultPageFactory,
Data $helper,
Config $config
) {
$this->resultPageFactory = $resultPageFactory;
$this->helper = $helper;
$this->config = $config;
parent::__construct($context);
}

/**
* Execute method.
*
* @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
* @throws LocalizedException
*/
public function execute()
{
if ($this->helper->isEnabled() && !$this->config->isChatEnabled()) {
return $this->_redirect('adminhtml/system_config/edit/section/chat_api_credentials');
return $this->resultRedirectFactory
->create()
->setPath('adminhtml/system_config/edit/section/chat_api_credentials');
}

$this->_view->loadLayout();
$this->_view->renderLayout();
$resultPage = $this->resultPageFactory->create();
$resultPage
->getConfig()
->getTitle()
->prepend(__('Chat Studio'));
return $resultPage;
}
}
28 changes: 18 additions & 10 deletions Controller/Adminhtml/Studio/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,49 @@
namespace Dotdigitalgroup\Chat\Controller\Adminhtml\Studio;

use Magento\Backend\App\Action;
use Dotdigitalgroup\Chat\Model\Config;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;

class Team extends \Magento\Backend\App\AbstractAction
class Team extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Dotdigitalgroup_Email::iframe';
public const ADMIN_RESOURCE = 'Dotdigitalgroup_Email::iframe';

/**
* @var Config
* @var PageFactory
*/
private $config;
protected $resultPageFactory;

/**
* Index constructor.
*
* @param Action\Context $context
* @param Config $config
* @param PageFactory $resultPageFactory
*/
public function __construct(
Action\Context $context,
Config $config
PageFactory $resultPageFactory
) {
$this->config = $config;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}

/**
* Execute method.
*
* @return Page
*/
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
$resultPage = $this->resultPageFactory->create();
$resultPage
->getConfig()
->getTitle()
->prepend(__('Chat Team / Widget'));
return $resultPage;
}
}
28 changes: 18 additions & 10 deletions Controller/Adminhtml/Studio/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,49 @@
namespace Dotdigitalgroup\Chat\Controller\Adminhtml\Studio;

use Magento\Backend\App\Action;
use Dotdigitalgroup\Chat\Model\Config;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;

class Widget extends \Magento\Backend\App\AbstractAction
class Widget extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Dotdigitalgroup_Email::iframe';
public const ADMIN_RESOURCE = 'Dotdigitalgroup_Email::iframe';

/**
* @var Config
* @var PageFactory
*/
private $config;
protected $resultPageFactory;

/**
* Index constructor.
*
* @param Action\Context $context
* @param Config $config
* @param PageFactory $resultPageFactory
*/
public function __construct(
Action\Context $context,
Config $config
PageFactory $resultPageFactory
) {
$this->config = $config;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}

/**
* Execute method.
*
* @return Page
*/
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
$resultPage = $this->resultPageFactory->create();
$resultPage
->getConfig()
->getTitle()
->prepend(__('Chat Studio / Widget'));
return $resultPage;
}
}
11 changes: 6 additions & 5 deletions Controller/Profile/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Index extends Action
* Profile constructor
*
* @param Context $context
* @param $chatProfile
* @param UpdateChatProfile $chatProfile
*/
public function __construct(
Context $context,
Expand All @@ -36,9 +36,10 @@ public function __construct(
public function execute()
{
$this->chatProfile->update($this->getRequest()->getParam('profileId'));

return $this->getResponse()
->setHttpResponseCode(204)
->sendHeaders();
/** @var \Magento\Framework\HTTP\PhpEnvironment\Response $response */
$response = $this->getResponse();
$response->setHttpResponseCode(204);
$response->sendHeaders();
return $response;
}
}
1 change: 1 addition & 0 deletions CustomerData/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\UrlInterface;
use Dotdigitalgroup\Email\Helper\Data;
use Magento\TestFramework\Event\Magento;

class Chat implements SectionSourceInterface
{
Expand Down
3 changes: 1 addition & 2 deletions Model/Api/LiveChatApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class LiveChatApiClient
{

/**
* Chat config
*
Expand All @@ -21,7 +20,7 @@ class LiveChatApiClient
/**
* Zend HTTP Client
*
* @var HttpClientFactory
* @var ClientFactory
*/
private $httpClientFactory;

Expand Down
Loading

0 comments on commit ad737a8

Please sign in to comment.