ChangeApiKeyAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 24 2
A __construct() 0 6 1
1
<?php
2
3
namespace ControleOnline\Controller;
4
5
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface 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...
6
use ControleOnline\Service\HydratorService;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\HydratorService 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...
7
use Symfony\Component\HttpFoundation\JsonResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse 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...
8
use ControleOnline\Entity\User;
9
use ControleOnline\Service\UserService;
10
11
class ChangeApiKeyAction
12
{
13
14
  public function __construct(
15
    private EntityManagerInterface $manager,
16
    private UserService $service,
17
    private HydratorService $hydratorService
18
19
  ) {}
20
21
  public function __invoke(User $data)
22
  {
23
24
    try {
25
26
      $user = $this->service->changeApiKey($data);
27
28
      return new JsonResponse(
29
        $this->hydratorService->item(
30
          User::class,
31
          $user->getId(),
32
          "user:read"
33
        )
34
      );
35
    } catch (\Exception $e) {
36
37
      return new JsonResponse([
38
        'response' => [
39
          'data'    => [],
40
          'count'   => 0,
41
          'error'   => $e->getMessage(),
42
          'success' => false,
43
        ],
44
      ], 500);
45
    }
46
  }
47
}
48