UrlController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 15 3
1
<?php
2
3
namespace App\Controller\Scenario;
4
5
use App\Entity\Scenario;
6
use App\Service\ScenarioService;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\RedirectResponse 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 Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...n\NotFoundHttpException 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...
9
10
use Symfony\Component\Routing\Annotation\Route;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Routing\Annotation\Route 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...
11
12
/**
13
 * Class UrlController
14
 */
15
final class UrlController
16
{
17
    /**
18
     * @var \App\Service\ScenarioService
19
     */
20
    private $scenarioService;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param \App\Service\ScenarioService $scenarioService
26
     */
27
    public function __construct(ScenarioService $scenarioService)
28
    {
29
        $this->scenarioService = $scenarioService;
30
    }
31
32
    /**
33
     * Form
34
     *
35
     * @Route(path="/scenarios/{uuid}/url", methods={"GET"})
36
     * @param string $uuid
37
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
38
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
39
     */
40
    public function get($uuid)
41
    {
42
        $scenario = $this->scenarioService->getRepository()->findOneBy(['uuid' => $uuid]);
43
44
        if (!$scenario) {
45
            throw new NotFoundHttpException('Scenario not found.');
46
        }
47
48
        if (Scenario::TYPE_URL !== $scenario->getType()) {
49
            throw new NotFoundHttpException('Scenario url not found.');
50
        }
51
52
        $response = new RedirectResponse($scenario->getConfig()['url']);
53
54
        return $response;
55
    }
56
}
57