AssistantController::createViewAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
namespace Knp\RadBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class AssistantController extends Controller
9
{
10
    public function missingViewAction($viewName, $viewParams)
11
    {
12
        $viewPath = $this->get('knp_rad.view.path_deducer')->deducePath($viewName);
13
        $viewLogicalName = $this->get('knp_rad.view.path_deducer')->deduceViewLogicalName($viewName);
14
        $viewBody = $this->renderView($viewLogicalName, array(
15
            'viewParams' => $viewParams
16
        ));
17
18
        return $this->render(
19
            'KnpRadBundle:Assistant:missingView.html.twig',
20
            array(
21
                'viewName'   => $viewName,
22
                'viewBody'   => $viewBody,
23
                'viewParams' => $viewParams,
24
                'viewPath'   => $viewPath,
25
            )
26
        );
27
    }
28
29
    public function createViewAction(Request $request)
30
    {
31
        $viewName   = $request->request->get('viewName');
32
        $viewBody   = $request->request->get('viewBody');
33
        $viewPath   = $this->get('knp_rad.view.path_deducer')->deducePath($viewName);
34
        $filesystem = $this->get('filesystem');
35
36
        if ($filesystem->exists($viewPath)) {
37
            return new Response(sprintf(
38
                'File "%s" already exists.', $viewPath
39
            ), 409);
40
        }
41
42
        $filesystem->mkdir(dirname($viewPath));
43
        file_put_contents($viewPath, $viewBody);
44
45
        return new Response(null, 201);
46
    }
47
}
48