librenms/doc/Developing/Code-Guidelines.md
VVelox 6575042f5f go through making lots of the docs more lint happy (#10342)
* clean up all but header incrementing in Creating-Transport.md

* make Device-Dependencies.md mdl happy

* make Entities.md as mdl happy as possible... one long table line left

* make mdl as happy as possible for index.md

* clean up Introduction.md as much as possible

* minor formatting cleanup... move each icon onto its own row

* make ack and notes the same style

* clean Macros.md up

* clean Rules.md up as much as possible

* tweak one line a bit to get it to format a bit nicer

* a bit more format tweaking, making sure it does not sure with >

* clean up as much as possible for Templates.md

* make Testing.md as mdl happy as possibly

* clean Transports.md up as much as possible

* clean as many issues as possible for Alerts.md

* clean up as much of ARP.md as possible

* clean up as much as possible for Bills.md

* make DeviceGroups.md as mdl happy as possible

* cleanup Devices.md

* make as mdl happy as possible Inventory.md and index.md

* mdl cleanup for Logs.md and PortGroups.md

* make Ports.md and Routing.md as happy as possible

* clean up Services.md, Switching.md, and Systems.md as much as possible

* more markup cleanup

* lots more md cleanup udner Devloping/

* reapply bits from #10343 that accidentally got removed when merging
2019-06-20 13:53:44 -05:00

2.3 KiB

source: Developing/Code-Guidelines.md path: blob/master/doc/

Coding guidelines

This document is here to help code standards for contributions towards LibreNMS. The original code base that we forked from had a lack of standards and as such the code base has a variety of different styles. Whilst we don't want to restrict how people write code, these guidelines should mean we have a good standard going forward that makes reading the code easier. All modern day ide's should be able to assist in these guidelines without breaking your usual workflow.

PHP-FIG PSR-2 Coding Style

All new code should follow the PHP-FIG PSR-2 standard. Below are a few key items from that specification, please make sure to follow the full spec.

Indentation

Please use four (4) spaces to indent code rather than a tab. Ensure you increase indentation for nested code blocks.

if ($foo == 5) {
    if ($foo == 5) {
        if ($foo == 5) {

Line length

Try to keep the length of a line under 80 characters. If you must exceed 80 characters, please keep it under 120 characters. This makes reading the code easier and also enables compatibility for all screen sizes.

Control structures

A space must be used both before and after the parenthesis and also surrounding the condition operator.

if ($foo == 5) {

Do not put blocks of code on a single line, do use parenthesis

if ($foo == 5) {
    echo 'foo is 5';
}

else and elseif should start on the same line as ending of the previous code block.

if ($foo == 5) {
    echo 'foo is 5';
} elsif ($foo == 4) {
    echo 'foo is 4';
} else {
    echo 'foo is something else';
}

Including files

Using parenthesis around file includes isn't required, instead just place the file in between ''

require_once 'includes/snmp.inc.php';

PHP tags

Ensure you use <?php rather than the shorthand version <?.

<?php

The ?> must be excluded from all files that only include PHP (no html). For instance anything in includes/ or html/includes don't need the tag along with config.php.