ProductReviewViewFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Factory;
6
7
use Sylius\Component\Core\Model\ProductReview;
8
use Sylius\ShopApiPlugin\View\ProductReviewView;
9
10
final class ProductReviewViewFactory implements ProductReviewViewFactoryInterface
11
{
12
    /** @var string */
13
    private $productReviewViewClass;
14
15
    public function __construct(string $productReviewViewClass)
16
    {
17
        $this->productReviewViewClass = $productReviewViewClass;
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(ProductReview $productReview): ProductReviewView
24
    {
25
        /** @var ProductReviewView $productReviewView */
26
        $productReviewView = new $this->productReviewViewClass();
27
28
        $productReviewView->author = $productReview->getAuthor()->getEmail();
29
        $productReviewView->comment = $productReview->getComment();
30
        $productReviewView->rating = $productReview->getRating();
31
        $productReviewView->title = $productReview->getTitle();
32
33
        return $productReviewView;
34
    }
35
}
36