Passed
Pull Request — master (#191)
by
unknown
04:50
created

AuthorizedGroupsBuilder::consumeEvent()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
/*
3
4
This file was created by developers working at BitBag
5
6
Do you need more information about us and what we do? Visit our   website!
7
8
We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
9
*/
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
13
14
use Elastica\Document;
15
use FOS\ElasticaBundle\Event\TransformEvent;
16
use App\Entity\Product\ProductInterface;
0 ignored issues
show
Bug introduced by
The type App\Entity\Product\ProductInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
final class AuthorizedGroupsBuilder extends AbstractBuilder
19
{
20
    /** @var string */
21
    private $authorizedCustomerGroup;
22
23
    public function __construct(string $authorizedCustomerGroup)
24
    {
25
        $this->authorizedCustomerGroup = $authorizedCustomerGroup;
26
    }
27
28
    public function consumeEvent(TransformEvent $event): void
29
    {
30
        $this->buildProperty($event, ProductInterface::class,
31
            function (ProductInterface $product, Document $document): void {
32
                $authorizedGroups = [];
33
34
                foreach ($product->getAuthorizedCustomerGroups() as $group) {
35
                    $authorizedGroups[] = $group->getCode();
36
                }
37
38
                $document->set($this->authorizedCustomerGroup, $authorizedGroups);
39
            }
40
        );
41
    }
42
}
43