ConfigController::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace TinyPngBundle\Controller;
4
5
use Pimcore\Controller\FrontendController;
6
use Pimcore\File;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
use TinyPngBundle\Helper\AssetHelper;
12
13
/**
14
 * Class ConfigController
15
 * @package TinyPngBundle\Controller
16
 */
17
class ConfigController extends FrontendController
18
{
19
    /**
20
     * @Route("/admin/tinypng/get-config")
21
     */
22 2
    public function getConfig()
23
    {
24 2
        $config = AssetHelper::getConfig();
25 2
        return new JsonResponse($config, 200);
26
    }
27
28
    /**
29
     * @Route("/admin/tinypng/set-config")
30
     */
31 3
    public function setConfig(Request $request)
32
    {
33 3
        $data = json_decode($request->get('data'), true);
34
35 3
        if (is_null($data)) {
36 1
            return new JsonResponse(['success' => false], 200);
37
        }
38
39 2
        File::putPhpFile(PIMCORE_CONFIGURATION_DIRECTORY . '/tinypng.php', to_php_data_file_format([
40
            'config' => [
41 2
                'apiKey' => $data['config.apiKey']
42
            ]
43
        ]));
44 2
        return new JsonResponse(['success' => true], 200);
45
    }
46
}