Issues (195)

lib/Controller/SettingsController.php (7 issues)

1
<?php
2
3
/**
4
 * @copyright Copyright (c) 2018 Matthias Held <[email protected]>
5
 * @author Matthias Held <[email protected]>
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace OCA\RansomwareDetection\Controller;
23
24
use OCA\RansomwareDetection\AppInfo\Application;
25
use OCA\RansomwareDetection\Model\Settings;
26
use OCP\AppFramework\Http;
0 ignored issues
show
The type OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use OCP\AppFramework\Http\JSONResponse;
0 ignored issues
show
The type OCP\AppFramework\Http\JSONResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use OCP\AppFramework\Controller;
0 ignored issues
show
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use OCP\IConfig;
0 ignored issues
show
The type OCP\IConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use OCP\IUserSession;
0 ignored issues
show
The type OCP\IUserSession was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use OCP\IRequest;
0 ignored issues
show
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
class SettingsController extends Controller
34
{
35
    /** @var IConfig */
36
    protected $config;
37
38
    /** @var IUserSession */
39
    protected $userSession;
40
41
    /** @var int */
42
    private $userId;
43
44
    /**
45
     * @param string               $appName
46
     * @param IRequest             $request
47
     * @param IUserSession         $userSession
48
     * @param IConfig              $config
49
     * @param string               $userId
50
     */
51
    public function __construct(
52
        $appName,
53
        IRequest $request,
54
        IUserSession $userSession,
55
        IConfig $config,
56
        $userId
57
    ) {
58
        parent::__construct($appName, $request);
59
60
        $this->config = $config;
61
        $this->userSession = $userSession;
62
        $this->userId = $userId;
0 ignored issues
show
Documentation Bug introduced by
The property $userId was declared of type integer, but $userId is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
63
    }
64
65
    /**
66
     * Get settings.
67
     *
68
     * @NoCSRFRequired
69
     * @NoAdminRequired
70
     *
71
     * @return JSONResponse
72
     */
73
    public function findAll() {
74
        $debug = $this->config->getAppValue(Application::APP_ID, 'debug', 0);
75
        $color = $this->config->getUserValue($this->userId, Application::APP_ID, 'color_mode', 0);
76
        $settings = new Settings($debug, $color);
77
78
        return new JSONResponse($settings, Http::STATUS_OK);
79
    }
80
81
    /**
82
     * Set settings.
83
     *
84
     * @NoCSRFRequired
85
     * @NoAdminRequired
86
     *
87
     * @return JSONResponse
88
     */
89
    public function update($color, $debug) {
90
        $this->config->setUserValue($this->userId, Application::APP_ID, 'color_mode', $color);
91
92
        return new JSONResponse(null, Http::STATUS_OK);
93
    }
94
}
95