Completed
Pull Request — master (#6158)
by Morris
25:44 queued 10:22
created

Server::getSection()   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 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 OC\Settings\Admin;
25
26
use Doctrine\DBAL\Connection;
27
use Doctrine\DBAL\DBALException;
28
use Doctrine\DBAL\Platforms\SqlitePlatform;
29
use OC\Lock\DBLockingProvider;
30
use OC\Lock\NoopLockingProvider;
31
use OCP\AppFramework\Http\TemplateResponse;
32
use OCP\IConfig;
33
use OCP\IDBConnection;
34
use OCP\IL10N;
35
use OCP\IRequest;
36
use OCP\Lock\ILockingProvider;
37
use OCP\Settings\ISettings;
38
39
class Server implements ISettings {
40
	/** @var IDBConnection|Connection */
41
	private $db;
42
	/** @var IRequest */
43
	private $request;
44
	/** @var IConfig */
45
	private $config;
46
	/** @var ILockingProvider */
47
	private $lockingProvider;
48
	/** @var IL10N */
49
	private $l;
50
51
	/**
52
	 * @param IDBConnection $db
53
	 * @param IRequest $request
54
	 * @param IConfig $config
55
	 * @param ILockingProvider $lockingProvider
56
	 * @param IL10N $l
57
	 */
58
	public function __construct(IDBConnection $db,
59
								IRequest $request,
60
								IConfig $config,
61
								ILockingProvider $lockingProvider,
62
								IL10N $l) {
63
		$this->db = $db;
64
		$this->request = $request;
65
		$this->config = $config;
66
		$this->lockingProvider = $lockingProvider;
67
		$this->l = $l;
68
	}
69
70
	/**
71
	 * @return TemplateResponse
72
	 */
73
	public function getForm() {
74
		try {
75
			if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
0 ignored issues
show
Bug introduced by
The class Doctrine\DBAL\Platforms\SqlitePlatform does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
76
				$invalidTransactionIsolationLevel = false;
77
			} else {
78
				$invalidTransactionIsolationLevel = $this->db->getTransactionIsolation() !== Connection::TRANSACTION_READ_COMMITTED;
0 ignored issues
show
Bug introduced by
The method getTransactionIsolation() does not seem to exist on object<OCP\IDBConnection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
			}
80
		} catch (DBALException $e) {
0 ignored issues
show
Bug introduced by
The class Doctrine\DBAL\DBALException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
81
			// ignore
82
			$invalidTransactionIsolationLevel = false;
83
		}
84
85
		$envPath = getenv('PATH');
86
87
		// warn if outdated version of a memcache module is used
88
		$caches = [
89
			'apcu'	=> ['name' => $this->l->t('APCu'), 'version' => '4.0.6'],
90
			'redis'	=> ['name' => $this->l->t('Redis'), 'version' => '2.2.5'],
91
		];
92
		$outdatedCaches = [];
93
		foreach ($caches as $php_module => $data) {
94
			$isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
95
			if ($isOutdated) {
96
				$outdatedCaches[$php_module] = $data;
97
			}
98
		}
99
100
		if ($this->lockingProvider instanceof NoopLockingProvider) {
101
			$fileLockingType = 'none';
102
		} else if ($this->lockingProvider instanceof DBLockingProvider) {
103
			$fileLockingType = 'db';
104
		} else {
105
			$fileLockingType = 'cache';
106
		}
107
108
		$suggestedOverwriteCliUrl = '';
109
		if ($this->config->getSystemValue('overwrite.cli.url', '') === '') {
110
			$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
111
			if (!$this->config->getSystemValue('config_is_read_only', false)) {
112
				// Set the overwrite URL when it was not set yet.
113
				$this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl);
114
				$suggestedOverwriteCliUrl = '';
115
			}
116
		}
117
118
		$parameters = [
119
			// Diagnosis
120
			'readOnlyConfigEnabled'            => \OC_Helper::isReadOnlyConfigEnabled(),
121
			'isLocaleWorking'                  => \OC_Util::isSetLocaleWorking(),
122
			'isAnnotationsWorking'             => \OC_Util::isAnnotationsWorking(),
123
			'checkForWorkingWellKnownSetup'    => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
124
			'has_fileinfo'                     => \OC_Util::fileInfoLoaded(),
125
			'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel,
126
			'getenvServerNotWorking'           => empty($envPath),
127
			'OutdatedCacheWarning'             => $outdatedCaches,
128
			'fileLockingType'                  => $fileLockingType,
129
			'suggestedOverwriteCliUrl'         => $suggestedOverwriteCliUrl,
130
131
			// Background jobs
132
			'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
133
			'lastcron'            => $this->config->getAppValue('core', 'lastcron', false),
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

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...
134
			'cronErrors'		  => $this->config->getAppValue('core', 'cronErrors'),
135
			'cli_based_cron_possible' => function_exists('posix_getpwuid'),
136
			'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
137
		];
138
139
		return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
140
	}
141
142
	/**
143
	 * @return string the section ID, e.g. 'sharing'
144
	 */
145
	public function getSection() {
146
		return 'server';
147
	}
148
149
	/**
150
	 * @return int whether the form should be rather on the top or bottom of
151
	 * the admin section. The forms are arranged in ascending order of the
152
	 * priority values. It is required to return a value between 0 and 100.
153
	 *
154
	 * E.g.: 70
155
	 */
156
	public function getPriority() {
157
		return 0;
158
	}
159
}
160