Completed
Push — stable10 ( 737591...a2942c )
by Lukas
09:58 queued 09:42
created

Admin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Files\Settings;
25
26
use bantu\IniGetWrapper\IniGetWrapper;
27
use OCP\AppFramework\Http\TemplateResponse;
28
use OCP\IRequest;
29
use OCP\Settings\ISettings;
30
use OCP\Util;
31
32
class Admin implements ISettings {
33
34
	/** @var IniGetWrapper */
35
	private $iniWrapper;
36
37
	/** @var IRequest */
38
	private $request;
39
40
	public function __construct(IniGetWrapper $iniWrapper, IRequest $request) {
41
		$this->iniWrapper = $iniWrapper;
42
		$this->request = $request;
43
	}
44
45
	/**
46
	 * @return TemplateResponse
47
	 */
48
	public function getForm() {
49
		$htaccessWorking  = (getenv('htaccessWorking') == 'true');
50
		$htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
51
		$userIniWritable  = is_writable(\OC::$SERVERROOT.'/.user.ini');
52
53
		$upload_max_filesize = $this->iniWrapper->getBytes('upload_max_filesize');
54
		$post_max_size = $this->iniWrapper->getBytes('post_max_size');
55
		$maxUploadFilesize = Util::humanFileSize(min($upload_max_filesize, $post_max_size));
56
		if($_POST && $this->request->passesCSRFCheck()) {
57
			if(isset($_POST['maxUploadSize'])) {
58
				if(($setMaxSize = \OC_Files::setUploadLimit(Util::computerFileSize($_POST['maxUploadSize']))) !== false) {
0 ignored issues
show
Documentation introduced by
\OCP\Util::computerFileS..._POST['maxUploadSize']) is of type double|false, but the function expects a integer.

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...
59
					$maxUploadFilesize = Util::humanFileSize($setMaxSize);
60
				}
61
			}
62
		}
63
64
		$parameters = [
65
			'uploadChangable'              => (($htaccessWorking and $htaccessWritable) or $userIniWritable ),
66
			'uploadMaxFilesize'            => $maxUploadFilesize,
67
			// max possible makes only sense on a 32 bit system
68
			'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4,
69
			'maxPossibleUploadSize'        => Util::humanFileSize(PHP_INT_MAX),
70
		];
71
72
		return new TemplateResponse('files', 'admin', $parameters, '');
73
	}
74
75
	/**
76
	 * @return string the section ID, e.g. 'sharing'
77
	 */
78
	public function getSection() {
79
		return 'additional';
80
	}
81
82
	/**
83
	 * @return int whether the form should be rather on the top or bottom of
84
	 * the admin section. The forms are arranged in ascending order of the
85
	 * priority values. It is required to return a value between 0 and 100.
86
	 *
87
	 * E.g.: 70
88
	 */
89
	public function getPriority() {
90
		return 5;
91
	}
92
93
}
94