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

Server::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 1
eloc 8
c 3
b 0
f 2
nc 1
nop 4
dl 0
loc 9
rs 9.6666
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\Lock\ILockingProvider;
36
use OCP\Settings\ISettings;
37
38
class Server implements ISettings {
39
	/** @var IDBConnection|Connection */
40
	private $db;
41
	/** @var IConfig */
42
	private $config;
43
	/** @var ILockingProvider */
44
	private $lockingProvider;
45
	/** @var IL10N */
46
	private $l;
47
48
	/**
49
	 * @param IDBConnection $db
50
	 * @param IConfig $config
51
	 * @param ILockingProvider $lockingProvider
52
	 * @param IL10N $l
53
	 */
54
	public function __construct(IDBConnection $db,
55
								IConfig $config,
56
								ILockingProvider $lockingProvider,
57
								IL10N $l) {
58
		$this->db = $db;
59
		$this->config = $config;
60
		$this->lockingProvider = $lockingProvider;
61
		$this->l = $l;
62
	}
63
64
	/**
65
	 * @return TemplateResponse
66
	 */
67
	public function getForm() {
68
		try {
69
			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...
70
				$invalidTransactionIsolationLevel = false;
71
			} else {
72
				$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...
73
			}
74
		} 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...
75
			// ignore
76
			$invalidTransactionIsolationLevel = false;
77
		}
78
79
		$envPath = getenv('PATH');
80
81
		// warn if outdated version of a memcache module is used
82
		$caches = [
83
			'apcu'	=> ['name' => $this->l->t('APCu'), 'version' => '4.0.6'],
84
			'redis'	=> ['name' => $this->l->t('Redis'), 'version' => '2.2.5'],
85
		];
86
		$outdatedCaches = [];
87
		foreach ($caches as $php_module => $data) {
88
			$isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
89
			if ($isOutdated) {
90
				$outdatedCaches[$php_module] = $data;
91
			}
92
		}
93
94
		if ($this->lockingProvider instanceof NoopLockingProvider) {
95
			$fileLockingType = 'none';
96
		} else if ($this->lockingProvider instanceof DBLockingProvider) {
97
			$fileLockingType = 'db';
98
		} else {
99
			$fileLockingType = 'cache';
100
		}
101
102
		// If the current web root is non-empty but the web root from the config is,
103
		// and system cron is used, the URL generator fails to build valid URLs.
104
		$shouldSuggestOverwriteCliUrl = $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'cron'
105
			&& \OC::$WEBROOT && \OC::$WEBROOT !== '/'
106
			&& !$this->config->getSystemValue('overwrite.cli.url', '');
107
		$suggestedOverwriteCliUrl = ($shouldSuggestOverwriteCliUrl) ? \OC::$WEBROOT : '';
108
109
		$parameters = [
110
			// Diagnosis
111
			'readOnlyConfigEnabled'            => \OC_Helper::isReadOnlyConfigEnabled(),
112
			'isLocaleWorking'                  => \OC_Util::isSetLocaleWorking(),
113
			'isAnnotationsWorking'             => \OC_Util::isAnnotationsWorking(),
114
			'checkForWorkingWellKnownSetup'    => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
115
			'has_fileinfo'                     => \OC_Util::fileInfoLoaded(),
116
			'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel,
117
			'getenvServerNotWorking'           => empty($envPath),
118
			'OutdatedCacheWarning'             => $outdatedCaches,
119
			'fileLockingType'                  => $fileLockingType,
120
			'suggestedOverwriteCliUrl'         => $suggestedOverwriteCliUrl,
121
122
			// Background jobs
123
			'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
124
			'cron_log'            => $this->config->getSystemValue('cron_log', true),
125
			'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...
126
			'cronErrors'		  => $this->config->getAppValue('core', 'cronErrors'),
127
		];
128
129
		return new TemplateResponse('settings', 'admin/server', $parameters, '');
130
	}
131
132
	/**
133
	 * @return string the section ID, e.g. 'sharing'
134
	 */
135
	public function getSection() {
136
		return 'server';
137
	}
138
139
	/**
140
	 * @return int whether the form should be rather on the top or bottom of
141
	 * the admin section. The forms are arranged in ascending order of the
142
	 * priority values. It is required to return a value between 0 and 100.
143
	 *
144
	 * E.g.: 70
145
	 */
146
	public function getPriority() {
147
		return 0;
148
	}
149
}
150