1 <?php
 2  3  4 
 5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy\Product;
 6 
 7 use Team3\PayU\Order\Model\Products\Product;
 8 use Team3\PayU\Order\Model\Products\ProductInterface;
 9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\PropertyExtractor\ExtractorInterface;
11 use Team3\PayU\PropertyExtractor\ExtractorResult;
12 
13 class SingleProductTransformer
14 {
15     16 17 
18     private $extractor;
19 
20     21 22 
23     public function __construct(ExtractorInterface $extractor)
24     {
25         $this->extractor = $extractor;
26     }
27 
28     29 30 31 32 
33     public function transform($userProduct)
34     {
35         $product = new Product();
36 
37         foreach ($this->getExtractedAnnotations($userProduct) as $extractionResult) {
38             $this->transformParameter($product, $extractionResult);
39         }
40 
41         return $product;
42     }
43 
44     45 46 47 48 
49     private function getExtractedAnnotations($userProduct)
50     {
51         return $this
52             ->extractor
53             ->extract($userProduct);
54     }
55 
56     57 58 59 
60     private function transformParameter(
61         ProductInterface $product,
62         ExtractorResult $extractionResult
63     ) {
64         switch ($extractionResult->getPropertyName()) {
65             case TransformerProperties::PRODUCT_UNIT_PRICE:
66                 $product->setUnitPrice($extractionResult->getValue());
67                 break;
68             case TransformerProperties::PRODUCT_QUANTITY:
69                 $product->setQuantity($extractionResult->getValue());
70                 break;
71             case TransformerProperties::PRODUCT_NAME:
72                 $product->setName($extractionResult->getValue());
73                 break;
74             default:
75         }
76     }
77 }
78