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

classes/Elgg/Config/DatarootSettingMigrator.php (1 issue)

implicit conversion of array to boolean.

Best Practice Bug Minor
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
}