AdminScoreController::indexAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller;
6
7
use App\Model\AdminScore;
8
use App\Repository\AdminScoreRepository;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * The AdminScoreController serves the search form and results page of the AdminScore tool.
14
 */
15
class AdminScoreController extends XtoolsController
16
{
17
    /**
18
     * @inheritDoc
19
     * @codeCoverageIgnore
20
     */
21
    public function getIndexRoute(): string
22
    {
23
        return 'AdminScore';
24
    }
25
26
    /**
27
     * Display the AdminScore search form.
28
     * @Route("/adminscore", name="AdminScore")
29
     * @Route("/adminscore/index.php", name="AdminScoreIndexPhp")
30
     * @Route("/scottywong tools/adminscore.php", name="AdminScoreLegacy")
31
     * @Route("/adminscore/{project}", name="AdminScoreProject")
32
     * @return Response
33
     */
34
    public function indexAction(): Response
35
    {
36
        // Redirect if we have a project and user.
37
        if (isset($this->params['project']) && isset($this->params['username'])) {
38
            return $this->redirectToRoute('AdminScoreResult', $this->params);
39
        }
40
41
        return $this->render('adminscore/index.html.twig', [
42
            'xtPage' => 'AdminScore',
43
            'xtPageTitle' => 'tool-adminscore',
44
            'xtSubtitle' => 'tool-adminscore-desc',
45
            'project' => $this->project,
46
        ]);
47
    }
48
49
    /**
50
     * Display the AdminScore results.
51
     * @Route("/adminscore/{project}/{username}", name="AdminScoreResult")
52
     * @param AdminScoreRepository $adminScoreRepo
53
     * @return Response
54
     * @codeCoverageIgnore
55
     */
56
    public function resultAction(AdminScoreRepository $adminScoreRepo): Response
57
    {
58
        $adminScore = new AdminScore($adminScoreRepo, $this->project, $this->user);
0 ignored issues
show
Bug introduced by
It seems like $this->user can also be of type null; however, parameter $user of App\Model\AdminScore::__construct() does only seem to accept App\Model\User, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
        $adminScore = new AdminScore($adminScoreRepo, $this->project, /** @scrutinizer ignore-type */ $this->user);
Loading history...
59
60
        return $this->getFormattedResponse('adminscore/result', [
61
            'xtPage' => 'AdminScore',
62
            'xtTitle' => $this->user->getUsername(),
0 ignored issues
show
Bug introduced by
The method getUsername() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
            'xtTitle' => $this->user->/** @scrutinizer ignore-call */ getUsername(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            'as' => $adminScore,
64
        ]);
65
    }
66
}
67