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

QueryCreatedSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A onQueryCreated() 0 8 1
A __construct() 0 3 1
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\EventListener;
13
14
use BitBag\PluginCommonsPlugin\Event\QueryCreatedEvent;
0 ignored issues
show
Bug introduced by
The type BitBag\PluginCommonsPlugin\Event\QueryCreatedEvent 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...
15
use spec\Sylius\Component\Core\Test\Services\DefaultUnitedStatesChannelFactorySpec;
16
use Sylius\Component\Customer\Model\CustomerGroupInterface;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
use Elastica\Query\BoolQuery;
19
use Elastica\Query\Terms;
20
use App\Context\CustomerGroupContext;
0 ignored issues
show
Bug introduced by
The type App\Context\CustomerGroupContext 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...
21
22
final class QueryCreatedSubscriber implements EventSubscriberInterface, QueryCreatedSubscriberInterface
23
{
24
    /** @var CustomerGroupContext $groupContext */
25
    public $groupContext;
26
27
    public function __construct(CustomerGroupContext $groupContext)
28
    {
29
        $this->groupContext = $groupContext;
30
    }
31
32
    public static function getSubscribedEvents(): array
33
    {
34
        return [
35
            QueryCreatedEvent::NAME => 'onQueryCreated',
36
        ];
37
    }
38
39
    public function onQueryCreated(QueryCreatedEvent $event): void
40
    {
41
        /** @var BoolQuery $query */
42
        $query = $event->getQuery();
43
44
        $userGroupCode = $this->groupContext->getCustomerGroup()->getCode();
45
46
        $query->addMust(new \Elastica\Query\Terms(self::AUTHORIZED_GORUP_KEY,[$userGroupCode]));
47
48
    }
49
}
50