Passed
Pull Request — master (#191)
by
unknown
10:08
created

AuthorizedGroupsBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A consumeEvent() 0 11 2
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 Sylius\Component\Core\Model\ProductInterface;
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) {
0 ignored issues
show
Bug introduced by
The method getAuthorizedCustomerGroups() does not exist on Sylius\Component\Core\Model\ProductInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                foreach ($product->/** @scrutinizer ignore-call */ getAuthorizedCustomerGroups() as $group) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
                    $authorizedGroups[] = $group->getCode();
36
                }
37
38
                $document->set($this->authorizedCustomerGroup, $authorizedGroups);
39
            }
40
        );
41
    }
42
}
43