Completed
Push — influxdb ( d2694e...dfa551 )
by
unknown
06:23
created
src/Repositories/InfluxdbRepository.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -19,120 +19,120 @@
 block discarded – undo
19 19
  */
20 20
 class InfluxdbRepository
21 21
 {
22
-    /**
23
-     * Array containing the allowed sources
24
-     *
25
-     * @var  string[]
26
-     */
27
-    public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version'];
28
-
29
-    /**
30
-     * The database driver.
31
-     *
32
-     * @var    DatabaseInterface
33
-     * @since  1.3.0
34
-     */
35
-    private $db;
36
-
37
-    /**
38
-     * Instantiate the repository.
39
-     *
40
-     * @param DatabaseInterface $db The database driver.
41
-     */
42
-    public function __construct(DatabaseInterface $db)
43
-    {
44
-        $this->db = $db;
45
-    }
46
-
47
-    /**
48
-     * Saves the given data.
49
-     *
50
-     * @param \stdClass $data Data object to save.
51
-     *
52
-     * @return  void
53
-     */
54
-    public function save(\stdClass $data): void
55
-    {
56
-        $writeApi = $this->db->createWriteApi();
57
-
58
-        // Set the modified date of the record
59
-        $timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp();
60
-
61
-        $point = Point::measurement('joomla')
62
-            ->addTag('unique_id', $data->unique_id)
63
-            ->time($timestamp);
64
-
65
-        // Extract major and minor version
66
-        if (!empty($data->php_version)) {
67
-            preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion);
68
-            $point->addField('php_version', $data->php_version);
69
-            if (!empty($phpVersion)) {
70
-                $point->addField('php_major', $phpVersion[1])
71
-                    ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]);
72
-            }
73
-        }
74
-
75
-        // Prepare CMS version
76
-        if (!empty($data->cms_version)) {
77
-            preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions);
78
-
79
-            $point->addField('cms_version', $data->cms_version);
80
-            if (!empty($cmsVersions)) {
81
-                $point
82
-                    ->addField('cms_major', $cmsVersions[1])
83
-                    ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]);
84
-            }
85
-        }
86
-
87
-        // Prepare Database versions
88
-        if (!empty($data->db_version)) {
89
-            preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions);
90
-
91
-            $point->addField('db_version', $data->db_version);
92
-            if (!empty($dbVersions)) {
93
-                $point->addField('db_major', $dbVersions[1])
94
-                    ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]);
95
-            }
96
-        }
97
-
98
-        // Prepare Database Driver
99
-        if (!empty($data->db_type)) {
100
-            $dbServer = null;
101
-            if ($data->db_type === 'postgresql') {
102
-                $dbServer = 'PostgreSQL';
103
-            } elseif (str_contains($data->db_type, 'mysql')) {
104
-                $dbServer = 'MySQL';
105
-                if (!empty($data->db_version)) {
106
-                    if (
107
-                        version_compare($data->db_version, '10.0.0', '>=')
108
-                        // We know this is not 100% correct but more accurate than expecting MySQL with this version string
109
-                        || version_compare($data->db_version, '5.5.5', '=')
110
-                    ) {
111
-                        $dbServer = 'MariaDB';
112
-                    }
113
-                }
114
-            } elseif (str_contains($data->db_type, 'mariadb')) {
115
-                $dbServer = 'MariaDB';
116
-            } elseif (str_contains($data->db_type, 'sqlsrv')) {
117
-                $dbServer = 'MSSQL';
118
-            }
119
-
120
-            $point->addField('db_driver', $data->db_type);
121
-            if (!empty($dbServer)) {
122
-                $point->addField('db_server', $dbServer);
123
-            }
124
-        }
125
-
126
-        // Prepare Operating System
127
-        if (!empty($data->server_os)) {
128
-            $os = explode(' ', $data->server_os, 2);
129
-
130
-            $point->addField('server_string', $data->server_os);
131
-            if (!empty($os[0])) {
132
-                $point->addField('server_os', $os[0]);
133
-            }
134
-        }
135
-
136
-        $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms');
137
-    }
22
+	/**
23
+	 * Array containing the allowed sources
24
+	 *
25
+	 * @var  string[]
26
+	 */
27
+	public const ALLOWED_SOURCES = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version'];
28
+
29
+	/**
30
+	 * The database driver.
31
+	 *
32
+	 * @var    DatabaseInterface
33
+	 * @since  1.3.0
34
+	 */
35
+	private $db;
36
+
37
+	/**
38
+	 * Instantiate the repository.
39
+	 *
40
+	 * @param DatabaseInterface $db The database driver.
41
+	 */
42
+	public function __construct(DatabaseInterface $db)
43
+	{
44
+		$this->db = $db;
45
+	}
46
+
47
+	/**
48
+	 * Saves the given data.
49
+	 *
50
+	 * @param \stdClass $data Data object to save.
51
+	 *
52
+	 * @return  void
53
+	 */
54
+	public function save(\stdClass $data): void
55
+	{
56
+		$writeApi = $this->db->createWriteApi();
57
+
58
+		// Set the modified date of the record
59
+		$timestamp = (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp();
60
+
61
+		$point = Point::measurement('joomla')
62
+			->addTag('unique_id', $data->unique_id)
63
+			->time($timestamp);
64
+
65
+		// Extract major and minor version
66
+		if (!empty($data->php_version)) {
67
+			preg_match('/^(\d+)\.(\d+)\./', $data->php_version, $phpVersion);
68
+			$point->addField('php_version', $data->php_version);
69
+			if (!empty($phpVersion)) {
70
+				$point->addField('php_major', $phpVersion[1])
71
+					->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]);
72
+			}
73
+		}
74
+
75
+		// Prepare CMS version
76
+		if (!empty($data->cms_version)) {
77
+			preg_match('/^(\d+)\.(\d+)\./', $data->cms_version, $cmsVersions);
78
+
79
+			$point->addField('cms_version', $data->cms_version);
80
+			if (!empty($cmsVersions)) {
81
+				$point
82
+					->addField('cms_major', $cmsVersions[1])
83
+					->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]);
84
+			}
85
+		}
86
+
87
+		// Prepare Database versions
88
+		if (!empty($data->db_version)) {
89
+			preg_match('/^(\d+)\.(\d+)\./', $data->db_version, $dbVersions);
90
+
91
+			$point->addField('db_version', $data->db_version);
92
+			if (!empty($dbVersions)) {
93
+				$point->addField('db_major', $dbVersions[1])
94
+					->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]);
95
+			}
96
+		}
97
+
98
+		// Prepare Database Driver
99
+		if (!empty($data->db_type)) {
100
+			$dbServer = null;
101
+			if ($data->db_type === 'postgresql') {
102
+				$dbServer = 'PostgreSQL';
103
+			} elseif (str_contains($data->db_type, 'mysql')) {
104
+				$dbServer = 'MySQL';
105
+				if (!empty($data->db_version)) {
106
+					if (
107
+						version_compare($data->db_version, '10.0.0', '>=')
108
+						// We know this is not 100% correct but more accurate than expecting MySQL with this version string
109
+						|| version_compare($data->db_version, '5.5.5', '=')
110
+					) {
111
+						$dbServer = 'MariaDB';
112
+					}
113
+				}
114
+			} elseif (str_contains($data->db_type, 'mariadb')) {
115
+				$dbServer = 'MariaDB';
116
+			} elseif (str_contains($data->db_type, 'sqlsrv')) {
117
+				$dbServer = 'MSSQL';
118
+			}
119
+
120
+			$point->addField('db_driver', $data->db_type);
121
+			if (!empty($dbServer)) {
122
+				$point->addField('db_server', $dbServer);
123
+			}
124
+		}
125
+
126
+		// Prepare Operating System
127
+		if (!empty($data->server_os)) {
128
+			$os = explode(' ', $data->server_os, 2);
129
+
130
+			$point->addField('server_string', $data->server_os);
131
+			if (!empty($os[0])) {
132
+				$point->addField('server_os', $os[0]);
133
+			}
134
+		}
135
+
136
+		$writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms');
137
+	}
138 138
 }
Please login to merge, or discard this patch.