title: Top rated products magento 2
body: <p>I want to display top rated products in magento 2</p>
  
  <p>My block Toprated.php</p>
  
  <pre><code>   public function getTesting()
  {
  
      $collection = $this-&gt;_productCollectionFactory-&gt;create();
  
      foreach($collection as $eachColl)
      {
          $storeId = $eachColl-&gt;getStore()-&gt;getId();
          $reviewSum = $this-&gt;reviewSummaryFactory-&gt;create()-&gt;setStoreId($storeId)-&gt;load($eachColl-&gt;getId());
  
          $rated[] = array(
              'rating' =&gt; $reviewSum['rating_summary'],
              'name' =&gt; $eachColl-&gt;getName(),
              'url' =&gt; $eachColl-&gt;getUrlPath(),
              'product_sku' =&gt; $eachColl-&gt;getSku()
          );
          $rateds[$eachColl-&gt;getSku()] = $reviewSum['rating_summary'];
  
      }
    arsort($rateds);
      $rateds = array_slice($rateds, 0, 3);
      $collection = $this-&gt;_productCollectionFactory-&gt;create();
      $collection-&gt;addAttributeToFilter('status', '1');
      $collection-&gt;addAttributeToFilter('rating', array('in' =&gt; implode(",", $rateds)));
  
      return $collection;
  
  }
  </code></pre>
  
  <p>my template toprated.phtml file</p>
  
  <pre><code>&lt;?php
  $_productCollection = $this-&gt;getTesting();
  
  $_helper = $this-&gt;helper('Magento\Catalog\Helper\Output');
  $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  </code></pre>
  
  <p>?></p>
  
  <p>but phtml file not calling any data.what i did mistake here</p>