MatrixElement example


        for ($points = self::MAX_POINTS; $points > 0; --$points) {
            foreach ($matrix as $rating) {
                $rawRatingKey = (float) $rating->getKey();

                if ($points === (int) round($rawRatingKey)) {
                    $this->pointSum += ($rawRatingKey * $rating->getCount());

                    $this->totalReviewCount += $rating->getCount();

                    $previousCount = isset($this->matrix[$points]) ? $this->matrix[$points]->getCount() : 0;
                    $this->matrix[$points] = new MatrixElement($points$rating->getCount() + $previousCount);
                }
            }

            if (!\array_key_exists($points$this->matrix)) {
                $this->matrix[$points] = new MatrixElement($points, 0);
            }
        }

        array_walk($this->matrix, function DMatrixElement &$rating): void {
            if ($this->totalReviewCount > 0) {
                $rating->setPercent($rating->getCount() / $this->totalReviewCount * 100);
            }
use Shopware\Core\Content\Product\SalesChannel\Review\MatrixElement;

/** * @internal */
class MatrixElementTest extends TestCase
{
    private MatrixElement $element;

    protected function setUp(): void
    {
        $this->element = new MatrixElement(1, 1, 0.3);
    }

    /** * @group reviews */
    public function testConstructor(): void
    {
        $points = 2;
        $count = 3;
        $percent = 1.0;

        
Home | Imprint | This part of the site doesn't use cookies.