Passed
Push — master ( 317eaf...21e5db )
by Dāvis
03:10
created

ControllerTrait::runApp()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 3
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Console\Application;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
9
trait ControllerTrait
10
{
11
    public $container;
12
13
    private function result()
14
    {
15
        return new JsonResponse(['success' => 1], 200, [
16
            'Cache-Control' => 'no-cache',
17
        ]);
18
    }
19
20
    private function runApp($command, $params = [], $return = true)
21
    {
22
        $data = [
23
            'command' => $command,
24
        ];
25
        if (!empty($params)) {
26
            $data = array_merge($data, $params);
27
        }
28
29
        $application = new Application($this->container->get('kernel'));
30
        $application->setAutoExit(false);
31
        $input = new ArrayInput($data);
32
        $application->run($input);
33
34
        if ($return === true) {
35
            return $this->result();
36
        }
37
    }
38
}