Completed
Pull Request — master (#841)
by Blizzz
10:54 queued 01:57
created

Server::getForm()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 42
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 30
nc 4
nop 0
dl 0
loc 42
rs 8.8571
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 OC\Settings\Admin;
25
26
use Doctrine\DBAL\Connection;
27
use Doctrine\DBAL\DBALException;
28
use Doctrine\DBAL\Platforms\SqlitePlatform;
29
use OCP\AppFramework\Http\TemplateResponse;
30
use OCP\IConfig;
31
use OCP\IDBConnection;
32
use OCP\Settings\ISettings;
33
34
class Server implements ISettings {
35
36
	/** @var IDBConnection|Connection */
37
	private $db;
38
39
	/** @var IConfig */
40
	private $config;
41
42
	public function __construct(IDBConnection $db, IConfig $config) {
43
		$this->db = $db;
44
		$this->config = $config;
45
	}
46
47
	/**
48
	 * @return TemplateResponse
49
	 */
50
	public function getForm() {
51
		try {
52
			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...
53
				$invalidTransactionIsolationLevel = false;
54
			} else {
55
				$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...
56
			}
57
		} 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...
58
			// ignore
59
			$invalidTransactionIsolationLevel = false;
60
		}
61
62
		$parameters = [
63
			// Diagnosis
64
			'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
65
			'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
66
			'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
67
			'checkForWorkingWellKnownSetup', $this->config->getSystemValue('check_for_working_wellknown_setup'),
68
			'has_fileinfo' => \OC_Util::fileInfoLoaded(),
69
			'invalidTransactionIsolationLevel' => $invalidTransactionIsolationLevel,
70
71
			// Background jobs
72
			'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
73
			'cron_log'            => $this->config->getSystemValue('cron_log', true),
74
			'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...
75
76
			// Mail
77
			'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
78
			'mail_domain'           => $this->config->getSystemValue('mail_domain', ''),
79
			'mail_from_address'     => $this->config->getSystemValue('mail_from_address', ''),
80
			'mail_smtpmode'         => $this->config->getSystemValue('mail_smtpmode', ''),
81
			'mail_smtpsecure'       => $this->config->getSystemValue('mail_smtpsecure', ''),
82
			'mail_smtphost'         => $this->config->getSystemValue('mail_smtphost', ''),
83
			'mail_smtpport'         => $this->config->getSystemValue('mail_smtpport', ''),
84
			'mail_smtpauthtype'     => $this->config->getSystemValue('mail_smtpauthtype', ''),
85
			'mail_smtpauth'         => $this->config->getSystemValue('mail_smtpauth', false),
86
			'mail_smtpname'         => $this->config->getSystemValue('mail_smtpname', ''),
87
			'mail_smtppassword'     => $this->config->getSystemValue('mail_smtppassword', ''),
88
		];
89
90
		return new TemplateResponse('settings', 'admin/server', $parameters, '');
91
	}
92
93
	/**
94
	 * @return string the section ID, e.g. 'sharing'
95
	 */
96
	public function getSection() {
97
		return 'server';
98
	}
99
100
	/**
101
	 * @return int whether the form should be rather on the top or bottom of
102
	 * the admin section. The forms are arranged in ascending order of the
103
	 * priority values. It is required to return a value between 0 and 100.
104
	 *
105
	 * E.g.: 70
106
	 */
107
	public function getPriority() {
108
		return 0;
109
	}
110
}
111