Completed
Push — master ( cab007...c861ff )
by Mazarini
02:36
created

DesignController::index()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 5.0035

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 18
cts 19
cp 0.9474
rs 9.0968
c 0
b 0
f 0
cc 5
nc 9
nop 3
crap 5.0035
1
<?php
2
3
/*
4
 * Copyright (C) 2019 Mazarini <[email protected]>.
5
 * This file is part of mazarini/design.
6
 *
7
 * mazarini/design is free software: you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.
11
 *
12
 * mazarini/design is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15
 * more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 */
19
20
namespace Mazarini\DesignBundle\Controller;
21
22
use Mazarini\DesignBundle\Tools\Folder;
23
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\Routing\Annotation\Route;
26
27
class DesignController extends AbstractController
28
{
29
    /**
30
     * @Route("info", name="design_info")
31
     */
32 1
    public function info(Request $request, Folder $folder)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34 1
        $param = [];
35 1
        $param['hasLayout'] = $folder->hasLayout();
36 1
        $param['steps'] = $folder->getSteps();
37
38 1
        return $this->render('@MazariniDesign/information.html.twig', $param);
39
    }
40
41
    /**
42
     * @Route("/{debug}", name="design", methods={"GET","POST"})
43
     */
44 6
    public function index(Request $request, Folder $folder, string $debug = '')
45
    {
46 6
        if (!$folder->hasLayout()) {
47
            return $this->info($request, $folder);
48
        }
49
50 6
        $step = $request->get('step');
51 6
        $page = $request->get('page');
52
53 6
        $steps = $folder->getSteps();
54 6
        if (!isset($steps[$step])) {
55 2
            $step = key($steps);
56
        }
57
58 6
        $pages = $folder->getPages($step);
59 6
        if (!isset($pages[$page])) {
60 4
            $page = key($pages);
61
        }
62
63 6
        if ('' === $debug) {
64 5
            $template = '@MazariniDesign/steps/'.$step.'/'.$page;
65
        } else {
66 1
            $template = '@MazariniDesign/debug.html.twig';
67
        }
68
69 6
        return $this->render($template, [
70 6
            'template' => $template,
71 6
            'current' => ['step' => $step, 'page' => $page],
72 6
            'steps' => $steps,
73 6
            'pages' => $pages,
74
        ]);
75
    }
76
}
77