Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed Aug 28, 2019
1 parent 40dd15d commit 7cd5a3d
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 195 deletions.
28 changes: 18 additions & 10 deletions Block/Adminhtml/SeoChecker/CheckForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
use Magento\Catalog\Model\ProductFactory;
use Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action\UrlBuilder;
use Magento\Cms\Model\PageFactory;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Json\Helper\Data as JsonData;
use Magento\Framework\Url;
use Magento\Framework\View\Element\Template;
use Magento\Sitemap\Model\ResourceModel\Sitemap\Collection;
use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Seo\Helper\Data as SeoHelperData;

/**
Expand Down Expand Up @@ -129,32 +132,37 @@ public function __construct(
* get link to check
*
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function getLink()
{
$id = $this->_request->getParam('id');
$storeCode = $this->_storeManager->getStore()->getCode();
$storeId = $this->_storeManager->getStore()->getId();
$actionName = $this->_request->getFullActionName();
if ($storeId == "0") {
$storeId = $this->_storeManager->getDefaultStoreView()->getId();
$storeCode = $this->_storeManager->getDefaultStoreView()->getCode();
if ($storeId === 0) {
$defaultStore = $this->_storeManager->getDefaultStoreView();
$storeId = $defaultStore->getId();
$storeCode = $defaultStore->getCode();
}

switch ($actionName) {
case 'catalog_product_edit':
$urlModel = $this->productRepository->getById($id)->getUrlModel();
$product = $this->productFactory->create()->load($id)->setStoreId($storeId);
$url = $urlModel->getUrl($product) . "?___store=" . $storeCode;
$url = $urlModel->getUrl($product, ['_query' => [StoreManagerInterface::PARAM_NAME => $storeCode]]);
break;
case 'catalog_category_edit':
$category = $this->categoryRepository->get($id, $storeId);
$url = $category->getUrl() . "?___store=" . $storeCode;
$url = $category->getUrl(['_query' => [StoreManagerInterface::PARAM_NAME => $storeCode]]);
break;
case 'cms_page_edit':
$pageId = $this->_request->getParam('page_id');
$url = $this->cmsUrl->getUrl($this->cmsPageFactory->create()->load($pageId)->getIdentifier(), $storeId, $storeCode);
$url = $this->cmsUrl->getUrl(
$this->cmsPageFactory->create()->load($pageId)->getIdentifier(),
$storeId,
$storeCode
);
break;
default:
$url = '';
Expand All @@ -167,13 +175,13 @@ public function getLink()
* get site map links
*
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function sitemap()
{
$sitemapLinks = [];

/** @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection $sitemap */
/** @var Collection $sitemap */
$sitemap = $this->sitemapCollection->create();

$storeId = $this->_storeManager->getStore()->getId();
Expand All @@ -192,7 +200,7 @@ public function sitemap()
* get Data to check
*
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws NoSuchEntityException
*/
public function getSeoData()
{
Expand Down
3 changes: 2 additions & 1 deletion Block/Adminhtml/System/Config/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Block\Adminhtml\System\Config;

use Magento\Config\Block\System\Config\Form\Field;
Expand All @@ -42,4 +43,4 @@ public function render(AbstractElement $element)

return parent::render($element);
}
}
}
5 changes: 4 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public function getDuplicateConfig($code = null, $storeId = null)
public function createStructuredData($data, $prefixComment = '', $subfixComment = '')
{
$applicationLdJson = $prefixComment;
$applicationLdJson .= '<script type="application/ld+json">' . json_encode($data, JSON_PRETTY_PRINT) . '</script>';
$applicationLdJson .= '<script type="application/ld+json">' . json_encode(
$data,
JSON_PRETTY_PRINT
) . '</script>';
$applicationLdJson .= $subfixComment;

return $applicationLdJson;
Expand Down
51 changes: 0 additions & 51 deletions Model/Config/Source/AggregateRating.php

This file was deleted.

6 changes: 3 additions & 3 deletions Observer/RemoveSchemaObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Seo\Observer;

use Magento\Framework\Event\Observer;
Expand All @@ -40,9 +41,8 @@ class RemoveSchemaObserver implements ObserverInterface
*
* @param HelperData $helperData
*/
public function __construct(
HelperData $helperData
){
public function __construct(HelperData $helperData)
{
$this->_helperData = $helperData;
}

Expand Down
7 changes: 4 additions & 3 deletions Plugin/Helper/CanUseCanonicalTagForCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Mageplaza\Seo\Plugin\Helper;

use Magento\Catalog\Helper\Category;
use Mageplaza\Seo\Helper\Data as HelperData;

/**
Expand All @@ -30,7 +31,7 @@
class CanUseCanonicalTagForCategories
{
/**
* @var \Mageplaza\Seo\Helper\Data
* @var HelperData
*/
protected $_helper;

Expand All @@ -45,12 +46,12 @@ function __construct(HelperData $helper)
}

/**
* @param \Magento\Catalog\Helper\Category $category
* @param Category $category
* @param $result
*
* @return mixed
*/
public function afterCanUseCanonicalTag(\Magento\Catalog\Helper\Category $category, $result)
public function afterCanUseCanonicalTag(Category $category, $result)
{
if ($this->_helper->isEnabled()) {
return $this->_helper->getDuplicateConfig('category_canonical_tag');
Expand Down
7 changes: 4 additions & 3 deletions Plugin/Helper/CanUseCanonicalTagForProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Mageplaza\Seo\Plugin\Helper;

use Magento\Catalog\Helper\Product;
use Mageplaza\Seo\Helper\Data as HelperData;

/**
Expand All @@ -30,7 +31,7 @@
class CanUseCanonicalTagForProducts
{
/**
* @var \Mageplaza\Seo\Helper\Data
* @var HelperData
*/
protected $_helper;

Expand All @@ -45,12 +46,12 @@ function __construct(HelperData $helper)
}

/**
* @param \Magento\Catalog\Helper\Product $product
* @param Product $product
* @param $result
*
* @return mixed
*/
public function afterCanUseCanonicalTag(\Magento\Catalog\Helper\Product $product, $result)
public function afterCanUseCanonicalTag(Product $product, $result)
{
if ($this->_helper->isEnabled()) {
return $this->_helper->getDuplicateConfig('product_canonical_tag');
Expand Down
5 changes: 2 additions & 3 deletions Plugin/RemoveReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class RemoveReview
*
* @param HelperData $helperData
*/
public function __construct(
HelperData $helperData
) {
public function __construct(HelperData $helperData)
{
$this->_helperData = $helperData;
}

Expand Down
Loading

0 comments on commit 7cd5a3d

Please sign in to comment.