CommandController::runAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the AMFConsoleBundle.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace AMF\ConsoleBundle\Controller;
11
12
use AMF\ConsoleBundle\Form\Model\ConsoleApplication;
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\HttpFoundation\Request;
16
17
/**
18
 * Controller for handling a command.
19
 *
20
 * @author Amine Fattouch <[email protected]>
21
 */
22
class CommandController extends Controller
23
{
24
    /**
25
     * Runs a command with its arguments.
26
     *
27
     * @param Request $request The current http request.
28
     *
29
     * @return JsonResponse
30
     */
31
    public function runAction(Request $request)
32
    {
33
        $processed = $this->get('amf_console.console_application.form_handler')->process($request, new ConsoleApplication());
34
        if ($processed['success'] === true) {
35
            return new JsonResponse(['output' => $processed['output']]);
36
        }
37
38
        return new JsonResponse(['errors' => $processed['errors']], 400);
39
    }
40
}
41