Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | final class ChannelsPropertyBuilder implements PropertyBuilderInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $channelsProperty; |
||
24 | |||
25 | /** |
||
26 | * @param string $channelsProperty |
||
27 | */ |
||
28 | public function __construct(string $channelsProperty) |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param TransformEvent $event |
||
35 | */ |
||
36 | public function buildProperty(TransformEvent $event): void |
||
37 | { |
||
38 | $product = $event->getObject(); |
||
39 | |||
40 | if (!$product instanceof ProductInterface) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $channels = []; |
||
45 | |||
46 | /** @var ProductInterface $product */ |
||
47 | foreach ($product->getChannels() as $channel) { |
||
48 | $channels[] = $channel->getCode(); |
||
49 | } |
||
50 | |||
51 | $event->getDocument()->set($this->channelsProperty, $channels); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public static function getSubscribedEvents(): array |
||
61 | ]; |
||
62 | } |
||
64 |