ConfigController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 28
rs 10
ccs 10
cts 10
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 4 1
A setConfig() 0 14 2
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
}