diff --git a/app/code/Magento/Review/Block/Customer/View.php b/app/code/Magento/Review/Block/Customer/View.php index 65e87940fd196..da5aff1f4d2f8 100644 --- a/app/code/Magento/Review/Block/Customer/View.php +++ b/app/code/Magento/Review/Block/Customer/View.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Review\Block\Customer; use Magento\Catalog\Model\Product; @@ -202,7 +203,7 @@ public function dateFormat($date) } /** - * @return string + * @inheritDoc */ protected function _toHtml() { diff --git a/app/code/Magento/Review/Block/Product/ReviewRenderer.php b/app/code/Magento/Review/Block/Product/ReviewRenderer.php index 59c385e4698eb..0fd6327e1f777 100644 --- a/app/code/Magento/Review/Block/Product/ReviewRenderer.php +++ b/app/code/Magento/Review/Block/Product/ReviewRenderer.php @@ -44,8 +44,8 @@ class ReviewRenderer extends \Magento\Framework\View\Element\Template implements /** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Review\Model\ReviewFactory $reviewFactory - * @param ReviewSummaryFactory $reviewSummaryFactory * @param array $data + * @param ReviewSummaryFactory $reviewSummaryFactory */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, @@ -54,7 +54,8 @@ public function __construct( ReviewSummaryFactory $reviewSummaryFactory = null ) { $this->_reviewFactory = $reviewFactory; - $this->reviewSummaryFactory = $reviewSummaryFactory ?? ObjectManager::getInstance()->get(ReviewSummaryFactory::class); + $this->reviewSummaryFactory = $reviewSummaryFactory ?? + ObjectManager::getInstance()->get(ReviewSummaryFactory::class); parent::__construct($context, $data); } @@ -94,7 +95,7 @@ public function getReviewsSummaryHtml( ); } - if (!$product->getRatingSummary() && !$displayIfNoReviews) { + if (null === $product->getRatingSummary() && !$displayIfNoReviews) { return ''; } // pick template among available diff --git a/app/code/Magento/Review/Model/ResourceModel/Review/Summary.php b/app/code/Magento/Review/Model/ResourceModel/Review/Summary.php index 153e0ae4da192..f18bc2094930a 100644 --- a/app/code/Magento/Review/Model/ResourceModel/Review/Summary.php +++ b/app/code/Magento/Review/Model/ResourceModel/Review/Summary.php @@ -79,15 +79,15 @@ public function reAggregate($summary) * Append review summary fields to product collection * * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection - * @param $storeId - * @param $entityCode + * @param string $storeId + * @param string $entityCode * @return Summary * @throws \Magento\Framework\Exception\LocalizedException */ public function appendSummaryFieldsToCollection( \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection, - $storeId, - $entityCode + string $storeId, + string $entityCode ) { if (!$productCollection->isLoaded()) { $summaryEntitySubSelect = $this->getConnection()->select(); @@ -99,7 +99,10 @@ public function appendSummaryFieldsToCollection( 'entity_code = ?', $entityCode ); - $joinCond = new \Zend_Db_Expr("e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = {$storeId} AND review_summary.entity_type = ({$summaryEntitySubSelect})"); + $joinCond = new \Zend_Db_Expr( + "e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = {$storeId}" + . " AND review_summary.entity_type = ({$summaryEntitySubSelect})" + ); $productCollection->getSelect() ->joinLeft( ['review_summary' => $this->getMainTable()], diff --git a/app/code/Magento/Review/Model/Review.php b/app/code/Magento/Review/Model/Review.php index 2c8a794dbc0e1..0c581f570ef0c 100644 --- a/app/code/Magento/Review/Model/Review.php +++ b/app/code/Magento/Review/Model/Review.php @@ -318,7 +318,7 @@ public function appendSummary($collection) $entityIds[] = $item->getEntityId(); } - if (sizeof($entityIds) == 0) { + if (count($entityIds) === 0) { return $this; } diff --git a/app/code/Magento/Review/Model/ReviewSummary.php b/app/code/Magento/Review/Model/ReviewSummary.php index c00294d40a93a..46851339ae6d7 100644 --- a/app/code/Magento/Review/Model/ReviewSummary.php +++ b/app/code/Magento/Review/Model/ReviewSummary.php @@ -10,6 +10,9 @@ use Magento\Framework\Model\AbstractModel; use Magento\Review\Model\ResourceModel\Review\Summary\CollectionFactory as SummaryCollectionFactory; +/** + * ReviewSummary model. + */ class ReviewSummary { /** @@ -17,6 +20,9 @@ class ReviewSummary */ private $summaryCollectionFactory; + /** + * @param SummaryCollectionFactory $sumColFactory + */ public function __construct( SummaryCollectionFactory $sumColFactory ) { @@ -27,18 +33,20 @@ public function __construct( * Append review summary data to product * * @param AbstractModel $object - * @param $storeId + * @param int $storeId * @param int $entityType */ - public function appendSummaryDataToObject(AbstractModel $object, $storeId, $entityType = 1): void + public function appendSummaryDataToObject(AbstractModel $object, int $storeId, int $entityType = 1): void { $summary = $this->summaryCollectionFactory->create() ->addEntityFilter($object->getId(), $entityType) ->addStoreFilter($storeId) ->getFirstItem(); - $object->addData([ - 'reviews_count' => $summary->getData('reviews_count'), - 'rating_summary' => $summary->getData('rating_summary') - ]); + $object->addData( + [ + 'reviews_count' => $summary->getData('reviews_count'), + 'rating_summary' => $summary->getData('rating_summary') + ] + ); } } diff --git a/app/code/Magento/Review/Observer/CatalogProductListCollectionAppendSummaryFieldsObserver.php b/app/code/Magento/Review/Observer/CatalogProductListCollectionAppendSummaryFieldsObserver.php index 5d29bb46a92eb..bb69284b5f0b8 100644 --- a/app/code/Magento/Review/Observer/CatalogProductListCollectionAppendSummaryFieldsObserver.php +++ b/app/code/Magento/Review/Observer/CatalogProductListCollectionAppendSummaryFieldsObserver.php @@ -12,6 +12,9 @@ use Magento\Review\Model\ResourceModel\Review\SummaryFactory; use Magento\Store\Model\StoreManagerInterface; +/** + * Append review summary to product list collection. + */ class CatalogProductListCollectionAppendSummaryFieldsObserver implements ObserverInterface { /** @@ -53,6 +56,7 @@ public function execute(EventObserver $observer) $this->storeManager->getStore()->getId(), \Magento\Review\Model\Review::ENTITY_PRODUCT_CODE ); + return $this; } } diff --git a/app/code/Magento/Review/Test/Unit/Model/ReviewSummaryTest.php b/app/code/Magento/Review/Test/Unit/Model/ReviewSummaryTest.php index ed998776961c4..9723ece0c4904 100644 --- a/app/code/Magento/Review/Test/Unit/Model/ReviewSummaryTest.php +++ b/app/code/Magento/Review/Test/Unit/Model/ReviewSummaryTest.php @@ -10,6 +10,9 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use PHPUnit\Framework\MockObject\MockObject; +/** + * Test for Magento\Review\Model\ReviewSummary class. + */ class ReviewSummaryTest extends \PHPUnit\Framework\TestCase { /**