Completed
Push — influxdb ( a9389d...ada106 )
by
unknown
05:43
created
src/Repositories/InfluxdbRepository.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -19,119 +19,119 @@
 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 (version_compare($data->db_version, '10.0.0', '>=')
107
-                        // We know this is not 100% correct but more accurate than expecting MySQL with this version string
108
-                        || version_compare($data->db_version, '5.5.5', '=')
109
-                    ) {
110
-                        $dbServer = 'MariaDB';
111
-                    }
112
-                }
113
-            } elseif (str_contains($data->db_type, 'mariadb')) {
114
-                $dbServer = 'MariaDB';
115
-            } elseif (str_contains($data->db_type, 'sqlsrv')) {
116
-                $dbServer = 'MSSQL';
117
-            }
118
-
119
-            $point->addField('db_driver', $data->db_type);
120
-            if (!empty($dbServer)) {
121
-                $point->addField('db_server', $dbServer);
122
-            }
123
-        }
124
-
125
-        // Prepare Operating System
126
-        if (!empty($data->server_os)) {
127
-            $os = explode(' ', $data->server_os, 2);
128
-
129
-            $point->addField('server_string', $data->server_os);
130
-            if (!empty($os[0])) {
131
-                $point->addField('server_os', $os[0]);
132
-            }
133
-        }
134
-
135
-        $writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms');
136
-    }
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 (version_compare($data->db_version, '10.0.0', '>=')
107
+						// We know this is not 100% correct but more accurate than expecting MySQL with this version string
108
+						|| version_compare($data->db_version, '5.5.5', '=')
109
+					) {
110
+						$dbServer = 'MariaDB';
111
+					}
112
+				}
113
+			} elseif (str_contains($data->db_type, 'mariadb')) {
114
+				$dbServer = 'MariaDB';
115
+			} elseif (str_contains($data->db_type, 'sqlsrv')) {
116
+				$dbServer = 'MSSQL';
117
+			}
118
+
119
+			$point->addField('db_driver', $data->db_type);
120
+			if (!empty($dbServer)) {
121
+				$point->addField('db_server', $dbServer);
122
+			}
123
+		}
124
+
125
+		// Prepare Operating System
126
+		if (!empty($data->server_os)) {
127
+			$os = explode(' ', $data->server_os, 2);
128
+
129
+			$point->addField('server_string', $data->server_os);
130
+			if (!empty($os[0])) {
131
+				$point->addField('server_os', $os[0]);
132
+			}
133
+		}
134
+
135
+		$writeApi->write($point, \InfluxDB2\Model\WritePrecision::S, 'cms');
136
+	}
137 137
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             $point->addField('php_version', $data->php_version);
69 69
             if (!empty($phpVersion)) {
70 70
                 $point->addField('php_major', $phpVersion[1])
71
-                    ->addField('php_minor', $phpVersion[1] . '.' . $phpVersion[2]);
71
+                    ->addField('php_minor', $phpVersion[1].'.'.$phpVersion[2]);
72 72
             }
73 73
         }
74 74
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             if (!empty($cmsVersions)) {
81 81
                 $point
82 82
                     ->addField('cms_major', $cmsVersions[1])
83
-                    ->addField('cms_minor', $cmsVersions[1] . '.' . $cmsVersions[2]);
83
+                    ->addField('cms_minor', $cmsVersions[1].'.'.$cmsVersions[2]);
84 84
             }
85 85
         }
86 86
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
             $point->addField('db_version', $data->db_version);
92 92
             if (!empty($dbVersions)) {
93 93
                 $point->addField('db_major', $dbVersions[1])
94
-                    ->addField('db_minor', $dbVersions[1] . '.' . $dbVersions[2]);
94
+                    ->addField('db_minor', $dbVersions[1].'.'.$dbVersions[2]);
95 95
             }
96 96
         }
97 97
 
Please login to merge, or discard this patch.