Passed
Push — master ( 1a7a28...c3773f )
by Mikołaj
03:50
created

ProductCreatedAtPropertyBuilder::consumeEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
14
15
use Elastica\Document;
16
use FOS\ElasticaBundle\Event\TransformEvent;
17
use Sylius\Component\Core\Model\ProductInterface;
18
19
final class ProductCreatedAtPropertyBuilder extends AbstractBuilder
20
{
21
    /**
22
     * @var string
23
     */
24
    private $createdAtProperty;
25
26
    /**
27
     * @param string $createdAtProperty
28
     */
29
    public function __construct(string $createdAtProperty)
30
    {
31
        $this->createdAtProperty = $createdAtProperty;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function consumeEvent(TransformEvent $event): void
38
    {
39
        $this->buildProperty($event, ProductInterface::class,
40
            function (ProductInterface $product, Document $document): void {
41
                $createdAt = (int)$product->getCreatedAt()->format('U');
42
43
                $document->set($this->createdAtProperty, $createdAt);
44
            }
45
        );
46
    }
47
}
48