-
Notifications
You must be signed in to change notification settings - Fork 0
Code Development Rules
The following is a set of rules to which code development and pull requests should adhere to. This is to maintain a standard format of code across the project. See Cacti Development Standards and PHP Standards Recommendations (PSR) standards.
The following are some basic code, formatting and styles choices made when writing code for the cacti project. Where examples can be given, these are provided in a subsection below.
- Remove trailing whitespaces from lines
- No soft tabs on initial tabbing (use hard tabs
\t
instead of spaces) - Use of
sizeof()
instead ofisset()
for array checks - Strings should use i18n versions via
__('<string>')
- Pull requests should include an entry in
docs/CHANGELOG
- Use db_xxx_prepared functions if passing parameters
- Keep first part of query with the db_..() function
- Keywords in SQL Statements should be capitalized
- FROM, JOIN, WHERE, ON, AND, OR should be on separate line
- Favor the use of WHERE over HAVING
When checking for array presence, it is better to use sizeof() to verify that you have a result.
if (isset($users)) {
This could should be re-written as follows to check that we have elements, not just whether an variable is defined, not that this does mean the array should be predefined.
if (sizeof($users) > 0) {
Using the above formatting rules, the following code should be re-formatted:
$tables = db_fetch_assoc('SELECT * FROM information_schema.tables WHERE table_schema = ' . $database_default);
This code should be re-formatting as follows using hard tab indentation before the FROM, WHERE and array lines. The parameter has also been shifted to an array password to the _prepared function in order to prevent SQL injection attacks possible by just tagging the value on the end of the statement.
$tables = db_fetch_assoc_prepared('SELECT *
FROM information_schema.tables
WHERE table_schema = ?',
array($database_default));
-
Testing Enviroments
OS Version Common Items Spine CentOS v 6 v 7 Fedora v 27 FreeBSD v 10.4 v 11.1 OpenSUSE Leaf v 42.3 Ubuntu v 18.04 v 17.10 v 16.04