Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

DatarootSettingMigrator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
ccs 16
cts 19
cp 0.8421
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B migrate() 0 30 3
1
<?php
2
/**
3
 *
4
 */
5
6
namespace Elgg\Config;
7
8
/**
9
 * Migrates dataroot database value to settings.php
10
 *
11
 * @access private
12
 */
13
class DatarootSettingMigrator extends SettingsMigrator {
14
15
	/**
16
	 * {@inheritdoc}
17
	 */
18 1
	public function migrate() {
19
20
		try {
21 1
			$row = $this->db->getDataRow("
22 1
				SELECT value FROM {$this->db->prefix}datalists
23
				WHERE name = 'dataroot'
24
			");
25
26 1
			if ($row) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $row of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
27 1
				$value = $row->value;
28
				$lines = [
29 1
					"",
30 1
					"/**",
31 1
					" * The full file path for Elgg data storage. E.g. /path/to/elgg-data/",
32 1
					" *",
33 1
					" * @global string \$CONFIG->dataroot",
34 1
					" */",
35 1
					"\$CONFIG->dataroot = \"{$value}\";",
36 1
					""
37
				];
38 1
				$bytes = implode(PHP_EOL, $lines);
39
40 1
				$this->append($bytes);
41
42 1
				return $value;
43
			} else {
44
				error_log("The DB table {$this->db->prefix}datalists did not have 'dataroot'.");
45
			}
46
		} catch (\DatabaseException $ex) {
47
			error_log($ex->getMessage());
48
		}
49
	}
50
}