Passed
Push — master ( d89542...5cf388 )
by Nils
06:27
created

MiscController::refreshExtensionSettingsAction()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 23
nc 6
nop 0
dl 0
loc 32
rs 9.552
c 1
b 0
f 0
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass
11
 * @version    API
12
 *
13
 * @file      MiscController.php
14
 * ---
15
 *
16
 * @author    Nils Laumaillé ([email protected])
17
 *
18
 * @copyright 2009-2025 Teampass.net
19
 *
20
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
21
 * ---
22
 *
23
 * @see       https://www.teampass.net
24
 */
25
26
use Symfony\Component\HttpFoundation\Request AS symfonyRequest;
27
28
class MiscController extends BaseController
29
{
30
31
32
    public function refreshExtensionSettingsAction()
33
    {
34
        $request = symfonyRequest::createFromGlobals();
35
        $requestMethod = $request->getMethod();
36
        $strErrorDesc = $responseData = $strErrorHeader = '';
37
38
        if (strtoupper($requestMethod) === 'POST') {
39
            require API_ROOT_PATH . "/Model/MiscModel.php";
40
            $miscModel = new MiscModel();
41
            $extensionSettings = $miscModel->getBrowserExtensionSettings();
42
            if ($extensionSettings !== null) {
0 ignored issues
show
introduced by
The condition $extensionSettings !== null is always true.
Loading history...
43
                $responseData = json_encode($extensionSettings);
44
            } else {
45
                $strErrorDesc = 'Failed to retrieve browser extension settings';
46
                $strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
47
            }
48
49
        } else {
50
            $strErrorDesc = 'Method '.$requestMethod.' not supported';
51
            $strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
52
        }
53
54
        // send output
55
        if (empty($strErrorDesc) === true) {
56
            $this->sendOutput(
57
                $responseData,
58
                ['Content-Type: application/json', 'HTTP/1.1 200 OK']
59
            );
60
        } else {
61
            $this->sendOutput(
62
                json_encode(['error' => $strErrorDesc]), 
63
                ['Content-Type: application/json', $strErrorHeader]
64
            );
65
        }
66
    }
67
}