Completed
Pull Request — master (#277)
by Beñat
05:05
created

UsersByIdsAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 24 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\IdentityAccess\Infrastructure\Symfony\HttpAction;
16
17
use Kreta\IdentityAccess\Application\Query\UsersOfIdsQuery;
18
use Kreta\IdentityAccess\Application\Query\UsersOfSearchStringQuery;
19
use Kreta\SharedKernel\Application\QueryBus;
20
use Symfony\Component\HttpFoundation\JsonResponse;
21
use Symfony\Component\HttpFoundation\Request;
22
23
class UsersByIdsAction
24
{
25
    private $queryBus;
26
27
    public function __construct(QueryBus $queryBus)
28
    {
29
        $this->queryBus = $queryBus;
30
    }
31
32
    public function __invoke(Request $request) : JsonResponse
33
    {
34
35
        if ($request->query->get('ids')) {
36
          $ids = explode(',', $request->query->get('ids'));
37
          $this->queryBus->handle(
38
              new UsersOfIdsQuery($ids),
39
              $result
40
          );
41
42
          return new JsonResponse($result);
43
        }
44
45
        $search = $request->query->get('query');
46
        $excludedIds = $request->query->get('excludedIds');
47
48
        $this->queryBus->handle(
49
            new UsersOfSearchStringQuery($search, explode(',',$excludedIds)),
50
            $result
51
        );
52
53
        return new JsonResponse($result);
54
55
    }
56
}
57