Passed
Push — develop ( 888544...81b1bd )
by Laurent
02:19
created

PostUsersController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Administration\Infrastructure\User\Controller;
15
16
use Administration\Domain\User\Command\CreateUser;
17
use Core\Domain\Common\Model\VO\EmailField;
18
use Core\Domain\Common\Model\VO\NameField;
19
use Core\Infrastructure\Common\MessengerCommandBus;
20
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
0 ignored issues
show
Bug introduced by
The type Symfony\Bundle\Framework...ller\AbstractController 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
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request 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...
22
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response 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...
23
24
class PostUsersController extends AbstractController
25
{
26
    private MessengerCommandBus $commandBus;
27
28
    public function __construct(MessengerCommandBus $commandBus)
29
    {
30
        $this->commandBus = $commandBus;
31
    }
32
33
    /**
34
     * @throws \JsonException
35
     */
36
    public function __invoke(Request $request): Response
37
    {
38
        $user = \json_decode($request->getContent(), true, 512, \JSON_THROW_ON_ERROR);
39
40
        try {
41
            $command = new CreateUser(
42
                NameField::fromString($user['username']),
43
                EmailField::fromString($user['email']),
44
                $user['password'],
45
                $user['roles']
46
            );
47
            $this->commandBus->dispatch($command);
48
        } catch (\DomainException $exception) {
49
            throw new \DomainException($exception->getMessage());
50
        }
51
52
        return new Response('User created start!', Response::HTTP_CREATED);
53
    }
54
}
55