Passed
Push — master ( b10d98...f9cd93 )
by Julito
08:57
created

IndexController::classic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 19
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Controller;
8
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
class IndexController extends BaseController
15
{
16
    /**
17
     * @Route("/", name="index", methods={"GET", "POST"}, options={"expose"=true})
18
     * @Route("/home", name="home", methods={"GET", "POST"}, options={"expose"=true})
19
     * @Route("/login", name="login", methods={"GET", "POST"}, options={"expose"=true})
20
     *
21
     * @Route("/course/{cid}/home", name="chamilo_core_course_home")
22
     * @Route("/courses", name="courses", methods={"GET", "POST"}, options={"expose"=true})
23
     *
24
     * @Route("/sessions", name="sessions", methods={"GET", "POST"}, options={"expose"=true})
25
     * @Route("/catalog/{slug}", name="catalog", methods={"GET", "POST"}, options={"expose"=true})
26
     * @Route("/resources/document/{nodeId}/manager", methods={"GET"}, name="resources_filemanager")
27
     * @Route("/account/home", name="account", options={"expose"=true}, name="chamilo_core_account_home")
28
     */
29
    public function indexAction(): Response
30
    {
31
        return $this->render('@ChamiloCore/Index/vue.html.twig');
32
    }
33
34
    /**
35
     * Toggle the student view action.
36
     *
37
     * @Route("/toggle_student_view", methods={"GET"})
38
     *
39
     * @Security("is_granted('ROLE_TEACHER')")
40
     */
41
    public function toggleStudentViewAction(Request $request): Response
42
    {
43
        if (!api_is_allowed_to_edit(false, false, false, false)) {
44
            throw $this->createAccessDeniedException();
45
        }
46
47
        $studentView = $request->getSession()->get('studentview');
48
        if (empty($studentView) || 'studentview' === $studentView) {
49
            $content = 'teacherview';
50
            $request->getSession()->set('studentview', $content);
51
        } else {
52
            $content = 'studentview';
53
            $request->getSession()->set('studentview', $content);
54
        }
55
56
        return new Response($content);
57
    }
58
59
    /**
60
     * Use only in PHPUnit tests.
61
     */
62
    public function classic($name): Response
63
    {
64
        if (1 !== (int) $_ENV['APP_DEBUG']) {
65
            exit;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
66
        }
67
68
        $rootDir = $this->getParameter('kernel.project_dir');
69
70
        $mainPath = $rootDir.'/public/main/';
71
        $fileToLoad = $mainPath.$name;
72
73
        ob_start();
74
        require_once $fileToLoad;
75
        $content = ob_get_contents();
76
        ob_end_clean();
77
78
        return $this->render(
79
            '@ChamiloCore/Layout/layout_one_col.html.twig',
80
            ['content' => $content]
81
        );
82
    }
83
}
84