Completed
Push — master ( b6eb50...929611 )
by Morris
40:39 queued 20:56
created

AdminController::getForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Joas Schilling <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Morris Jobke <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\UpdateNotification\Controller;
27
28
use OCA\UpdateNotification\ResetTokenBackgroundJob;
29
use OCP\AppFramework\Controller;
30
use OCP\AppFramework\Http\DataResponse;
31
use OCP\AppFramework\Utility\ITimeFactory;
32
use OCP\BackgroundJob\IJobList;
33
use OCP\IConfig;
34
use OCP\IL10N;
35
use OCP\IRequest;
36
use OCP\Security\ISecureRandom;
37
use OCP\Util;
38
39
class AdminController extends Controller {
40
	/** @var IJobList */
41
	private $jobList;
42
	/** @var ISecureRandom */
43
	private $secureRandom;
44
	/** @var IConfig */
45
	private $config;
46
	/** @var ITimeFactory */
47
	private $timeFactory;
48
	/** @var IL10N */
49
	private $l10n;
50
51
	/**
52
	 * @param string $appName
53
	 * @param IRequest $request
54
	 * @param IJobList $jobList
55
	 * @param ISecureRandom $secureRandom
56
	 * @param IConfig $config
57
	 * @param ITimeFactory $timeFactory
58
	 * @param IL10N $l10n
59
	 */
60 View Code Duplication
	public function __construct($appName,
61
								IRequest $request,
62
								IJobList $jobList,
63
								ISecureRandom $secureRandom,
64
								IConfig $config,
65
								ITimeFactory $timeFactory,
66
								IL10N $l10n) {
67
		parent::__construct($appName, $request);
68
		$this->jobList = $jobList;
69
		$this->secureRandom = $secureRandom;
70
		$this->config = $config;
71
		$this->timeFactory = $timeFactory;
72
		$this->l10n = $l10n;
73
	}
74
75
	/**
76
	 * @param string $channel
77
	 * @return DataResponse
78
	 */
79
	public function setChannel($channel) {
80
		Util::setChannel($channel);
81
		$this->config->setAppValue('core', 'lastupdatedat', 0);
82
		return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
83
	}
84
85
	/**
86
	 * @return DataResponse
87
	 */
88
	public function createCredentials() {
89
		// Create a new job and store the creation date
90
		$this->jobList->add(ResetTokenBackgroundJob::class);
91
		$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
92
93
		// Create a new token
94
		$newToken = $this->secureRandom->generate(64);
95
		$this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
96
97
		return new DataResponse($newToken);
0 ignored issues
show
Documentation introduced by
$newToken is of type string, but the function expects a array|object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98
	}
99
}
100