Passed
Push — master ( a242e3...dfddba )
by Marcel
03:14
created

WizzardController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 11
rs 10
1
<?php
2
/**
3
 * Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @author Arthur Schiwon <[email protected]>
10
 * @author Christoph Wurst <[email protected]>
11
 * @copyright 2020 Marcel Scherello
12
 */
13
14
namespace OCA\Analytics\Controller;
15
16
use OCP\AppFramework\Controller;
17
use OCP\AppFramework\Http\DataResponse;
18
use OCP\IConfig;
19
use OCP\IRequest;
20
use OCP\IUserSession;
21
22
class WizzardController extends Controller
23
{
24
25
    /** @var IConfig */
26
    protected $config;
27
    /** @var IUserSession */
28
    private $userSession;
29
    private $AppName;
30
31
    public function __construct(
32
        string $AppName,
33
        IRequest $request,
34
        IUserSession $userSession,
35
        IConfig $config
36
    )
37
    {
38
        parent::__construct($AppName, $request);
39
        $this->AppName = $AppName;
40
        $this->config = $config;
41
        $this->userSession = $userSession;
42
    }
43
44
45
    /**
46
     * @NoAdminRequired
47
     *
48
     * @return DataResponse
49
     * @throws \OCP\PreConditionNotMetException
50
     */
51
    public function dismiss(): DataResponse
52
    {
53
        $user = $this->userSession->getUser();
54
        if ($user === null) {
55
            throw new \RuntimeException("Acting user cannot be resolved");
56
        }
57
        $this->config->setUserValue($user->getUID(), $this->AppName, 'wizzard', 1);
58
        return new DataResponse();
59
    }
60
}