Skip to content

Commit

Permalink
Disable Yoda style
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Aug 12, 2022
1 parent 87d8e97 commit 6a39cc3
Show file tree
Hide file tree
Showing 21 changed files with 257 additions and 256 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
->setRules(array(
'@Symfony' => true,
'array_syntax' => array('syntax' => 'long'),
'yoda_style' => array('equal' => false, 'identical' => false, 'less_and_greater' => false, 'always_move_variable' => false),
))
->setLineEnding(PHP_EOL)
->setFinder($finder)
Expand Down
14 changes: 7 additions & 7 deletions api_FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
foreach ($return as $line) {
$tmp = explode(' ', $line);

if ('domains_being_blocked' === $tmp[0] && !is_numeric($tmp[1]) || 'status' === $tmp[0]) {
if ($tmp[0] === 'domains_being_blocked' && !is_numeric($tmp[1]) || $tmp[0] === 'status') {
// Expect string response
$stats[$tmp[0]] = $tmp[1];
} elseif (isset($_GET['summary'])) {
// "summary" expects a formmated string response
if ('ads_percentage_today' !== $tmp[0]) {
if ($tmp[0] !== 'ads_percentage_today') {
$stats[$tmp[0]] = number_format($tmp[1]);
} else {
$stats[$tmp[0]] = number_format($tmp[1], 1, '.', '');
Expand Down Expand Up @@ -100,7 +100,7 @@
}

if (isset($_GET['topItems']) && $auth) {
if ('audit' === $_GET['topItems']) {
if ($_GET['topItems'] === 'audit') {
$return = callFTLAPI('top-domains for audit');
} elseif (is_numeric($_GET['topItems'])) {
$return = callFTLAPI('top-domains ('.$_GET['topItems'].')');
Expand All @@ -114,15 +114,15 @@
$top_queries = array();
foreach ($return as $line) {
$tmp = explode(' ', $line);
if (2 == count($tmp)) {
if (count($tmp) == 2) {
$tmp[2] = '';
}
$domain = utf8_encode($tmp[2]);
$top_queries[$domain] = intval($tmp[1]);
}
}

if ('audit' === $_GET['topItems']) {
if ($_GET['topItems'] === 'audit') {
$return = callFTLAPI('top-ads for audit');
} elseif (is_numeric($_GET['topItems'])) {
$return = callFTLAPI('top-ads ('.$_GET['topItems'].')');
Expand Down Expand Up @@ -216,7 +216,7 @@
}

if (isset($_GET['getForwardDestinations']) && $auth) {
if ('unsorted' === $_GET['getForwardDestinations']) {
if ($_GET['getForwardDestinations'] === 'unsorted') {
$return = callFTLAPI('forward-dest unsorted');
} else {
$return = callFTLAPI('forward-dest');
Expand Down Expand Up @@ -282,7 +282,7 @@
} elseif (isset($_GET['domain'])) {
// Get specific domain only
$return = callFTLAPI('getallqueries-domain '.$_GET['domain']);
} elseif (isset($_GET['client']) && (isset($_GET['type']) && 'blocked' === $_GET['type'])) {
} elseif (isset($_GET['client']) && (isset($_GET['type']) && $_GET['type'] === 'blocked')) {
// Get specific client only
$return = callFTLAPI('getallqueries-client-blocked '.$_GET['client']);
} elseif (isset($_GET['client'])) {
Expand Down
18 changes: 9 additions & 9 deletions api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
$network = array();
$results = $db->query('SELECT * FROM network');

while (false !== $results && $res = $results->fetchArray(SQLITE3_ASSOC)) {
while ($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC)) {
$id = intval($res['id']);

// Get IP addresses and host names for this device
$res['ip'] = array();
$res['name'] = array();
$network_addresses = $db->query("SELECT ip,name FROM network_addresses WHERE network_id = {$id} ORDER BY lastSeen DESC");
while (false !== $network_addresses && $network_address = $network_addresses->fetchArray(SQLITE3_ASSOC)) {
while ($network_addresses !== false && $network_address = $network_addresses->fetchArray(SQLITE3_ASSOC)) {
array_push($res['ip'], $network_address['ip']);
if (null !== $network_address['name']) {
if ($network_address['name'] !== null) {
array_push($res['name'], utf8_encode($network_address['name']));
} else {
array_push($res['name'], '');
Expand All @@ -58,7 +58,7 @@

if (isset($_GET['getAllQueries']) && $auth) {
$allQueries = array();
if ('empty' !== $_GET['getAllQueries']) {
if ($_GET['getAllQueries'] !== 'empty') {
$from = intval($_GET['from']);
$until = intval($_GET['until']);

Expand All @@ -77,7 +77,7 @@
$dbquery .= ' WHERE timestamp >= :from AND timestamp <= :until ';
if (isset($_GET['types'])) {
$types = $_GET['types'];
if (1 === preg_match('/^[0-9]+(?:,[0-9]+)*$/', $types)) {
if (preg_match('/^[0-9]+(?:,[0-9]+)*$/', $types) === 1) {
// Append selector to DB query. The used regex ensures
// that only numbers, separated by commas are accepted
// to avoid code injection and other malicious things
Expand Down Expand Up @@ -331,7 +331,7 @@ function parseDBData($results, $interval, $from, $until)
while ($row = $results->fetchArray()) {
// $data[timestamp] = value_in_this_interval
$data[$row[0]] = intval($row[1]);
if (-1 === $first_db_timestamp) {
if ($first_db_timestamp === -1) {
$first_db_timestamp = intval($row[0]);
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ function parseDBData($results, $interval, $from, $until)

if (isset($_GET['status']) && $auth) {
$extra = ';';
if (isset($_GET['ignore']) && 'DNSMASQ_WARN' === $_GET['ignore']) {
if (isset($_GET['ignore']) && $_GET['ignore'] === 'DNSMASQ_WARN') {
$extra = "WHERE type != 'DNSMASQ_WARN';";
}
$results = $db->query('SELECT COUNT(*) FROM message '.$extra);
Expand All @@ -389,14 +389,14 @@ function parseDBData($results, $interval, $from, $until)

if (isset($_GET['messages']) && $auth) {
$extra = ';';
if (isset($_GET['ignore']) && 'DNSMASQ_WARN' === $_GET['ignore']) {
if (isset($_GET['ignore']) && $_GET['ignore'] === 'DNSMASQ_WARN') {
$extra = "WHERE type != 'DNSMASQ_WARN';";
}

$messages = array();
$results = $db->query('SELECT * FROM message '.$extra);

while (false !== $results && $res = $results->fetchArray(SQLITE3_ASSOC)) {
while ($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC)) {
// Convert string to to UTF-8 encoding to ensure php-json can handle it.
// Furthermore, convert special characters to HTML entities to prevent XSS attacks.
foreach ($res as $key => $value) {
Expand Down
16 changes: 8 additions & 8 deletions queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
$showing = '';

if (isset($setupVars['API_QUERY_LOG_SHOW'])) {
if ('all' === $setupVars['API_QUERY_LOG_SHOW']) {
if ($setupVars['API_QUERY_LOG_SHOW'] === 'all') {
$showing = 'showing';
} elseif ('permittedonly' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'permittedonly') {
$showing = 'showing permitted';
} elseif ('blockedonly' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'blockedonly') {
$showing = 'showing blocked';
} elseif ('nothing' === $setupVars['API_QUERY_LOG_SHOW']) {
} elseif ($setupVars['API_QUERY_LOG_SHOW'] === 'nothing') {
$showing = 'showing no queries (due to setting)';
}
} elseif (isset($_GET['type']) && 'blocked' === $_GET['type']) {
} elseif (isset($_GET['type']) && $_GET['type'] === 'blocked') {
$showing = 'showing blocked';
} else {
// If filter variable is not set, we
Expand All @@ -35,7 +35,7 @@
$showing .= ' all queries within the Pi-hole log';
} elseif (isset($_GET['client'])) {
// Add switch between showing all queries and blocked only
if (isset($_GET['type']) && 'blocked' === $_GET['type']) {
if (isset($_GET['type']) && $_GET['type'] === 'blocked') {
// Show blocked queries for this client + link to all
$showing .= ' blocked queries for client '.htmlentities($_GET['client']);
$showing .= ', <a href="?client='.htmlentities($_GET['client']).'">show all</a>';
Expand All @@ -45,9 +45,9 @@
$showing .= ', <a href="?client='.htmlentities($_GET['client']).'&type=blocked">show blocked only</a>';
}
} elseif (isset($_GET['forwarddest'])) {
if ('blocked' === $_GET['forwarddest']) {
if ($_GET['forwarddest'] === 'blocked') {
$showing .= ' queries blocked by Pi-hole';
} elseif ('cached' === $_GET['forwarddest']) {
} elseif ($_GET['forwarddest'] === 'cached') {
$showing .= ' queries answered from cache';
} else {
$showing .= ' queries for upstream destination '.htmlentities($_GET['forwarddest']);
Expand Down
8 changes: 4 additions & 4 deletions scripts/pi-hole/php/FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function piholeFTLConfig($piholeFTLConfFile = DEFAULT_FTLCONFFILE, $force = fals

function connectFTL($address, $port)
{
if (DEFAULT_FTL_IP == $address) {
if ($address == DEFAULT_FTL_IP) {
$config = piholeFTLConfig();
// Read port
$portfileName = isset($config['PORTFILE']) ? $config['PORTFILE'] : DEFAULT_FTL_PORTFILE;
if ('' != $portfileName) {
if ($portfileName != '') {
$portfileContents = file_get_contents($portfileName);
if (is_numeric($portfileContents)) {
$port = intval($portfileContents);
Expand All @@ -60,7 +60,7 @@ function getResponseFTL($socket)
$errCount = 0;
while (true) {
$out = fgets($socket);
if ('' == $out) {
if ($out == '') {
++$errCount;
}

Expand All @@ -69,7 +69,7 @@ function getResponseFTL($socket)
exit('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}');
}

if (false !== strrpos($out, '---EOM---')) {
if (strrpos($out, '---EOM---') !== false) {
break;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/pi-hole/php/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function check_csrf($token)
{
// Check CSRF token
$session_started = function_exists('session_status') ?
PHP_SESSION_ACTIVE == session_status() :
'' == session_id();
session_status() == PHP_SESSION_ACTIVE :
session_id() == '';

if (!$session_started) {
// Start a new PHP session (or continue an existing one)
Expand Down
20 changes: 10 additions & 10 deletions scripts/pi-hole/php/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
}

// To which column should the record be added to?
if ('adlist' === $table) {
if ($table === 'adlist') {
$field = 'address';
} else {
$field = 'domain';
}

// Get initial count of domains in this table
if (-1 === $type) {
if ($type === -1) {
$countquery = "SELECT COUNT(*) FROM {$table};";
} else {
$countquery = "SELECT COUNT(*) FROM {$table} WHERE type = {$type};";
Expand All @@ -109,9 +109,9 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f

// Prepare INSERT SQLite statement
$bindcomment = false;
if ('domain_audit' === $table) {
if ($table === 'domain_audit') {
$querystr = "INSERT OR IGNORE INTO {$table} ({$field}) VALUES (:{$field});";
} elseif (-1 === $type) {
} elseif ($type === -1) {
$querystr = "INSERT OR IGNORE INTO {$table} ({$field},comment) VALUES (:{$field}, :comment);";
$bindcomment = true;
} else {
Expand Down Expand Up @@ -153,7 +153,7 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
Expand Down Expand Up @@ -181,7 +181,7 @@ function add_to_table($db, $table, $domains, $comment = null, $wildcardstyle = f
$extra = '';
}

if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
Expand Down Expand Up @@ -217,15 +217,15 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
}

// Get initial count of domains in this table
if (-1 === $type) {
if ($type === -1) {
$countquery = "SELECT COUNT(*) FROM {$table};";
} else {
$countquery = "SELECT COUNT(*) FROM {$table} WHERE type = {$type};";
}
$initialcount = intval($db->querySingle($countquery));

// Prepare SQLite statement
if (-1 === $type) {
if ($type === -1) {
$querystr = "DELETE FROM {$table} WHERE domain = :domain AND type = {$type};";
} else {
$querystr = "DELETE FROM {$table} WHERE domain = :domain;";
Expand Down Expand Up @@ -253,7 +253,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
Expand All @@ -270,7 +270,7 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1
if ($returnnum) {
return $num;
}
if (1 === $num) {
if ($num === 1) {
$plural = '';
} else {
$plural = 's';
Expand Down
16 changes: 8 additions & 8 deletions scripts/pi-hole/php/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
function validDomain($domain_name, &$message = null)
{
if (!preg_match('/^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$/i', $domain_name)) {
if (null !== $message) {
if ($message !== null) {
$message = 'it contains invalid characters';
}

return false;
}
if (!preg_match('/^.{1,253}$/', $domain_name)) {
if (null !== $message) {
if ($message !== null) {
$message = 'its length is invalid';
}

return false;
}
if (!preg_match('/^[^\\.]{1,63}(\\.[^\\.]{1,63})*$/', $domain_name)) {
if (null !== $message) {
if ($message !== null) {
$message = 'at least one label is of invalid length';
}

Expand Down Expand Up @@ -55,13 +55,13 @@ function validIP($address)
return false;
}

return false === !filter_var($address, FILTER_VALIDATE_IP);
return !filter_var($address, FILTER_VALIDATE_IP) === false;
}

function validCIDRIP($address)
{
// This validation strategy has been taken from ../js/groups-common.js
$isIPv6 = false !== strpos($address, ':');
$isIPv6 = strpos($address, ':') !== false;
if ($isIPv6) {
// One IPv6 element is 16bit: 0000 - FFFF
$v6elem = '[0-9A-Fa-f]{1,4}';
Expand All @@ -83,7 +83,7 @@ function validCIDRIP($address)
function validMAC($mac_addr)
{
// Accepted input format: 00:01:02:1A:5F:FF (characters may be lower case)
return false === !filter_var($mac_addr, FILTER_VALIDATE_MAC);
return !filter_var($mac_addr, FILTER_VALIDATE_MAC) === false;
}

function validEmail($email)
Expand Down Expand Up @@ -155,7 +155,7 @@ function pihole_execute($argument_string)
$return_status = -1;
$command = 'sudo pihole '.$escaped;
exec($command, $output, $return_status);
if (0 !== $return_status) {
if ($return_status !== 0) {
trigger_error("Executing {$command} failed.", E_USER_WARNING);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ function getCustomDNSEntries()
$line = str_replace("\n", '', $line);
$explodedLine = explode(' ', $line);

if (2 != count($explodedLine)) {
if (count($explodedLine) != 2) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/pi-hole/php/gravity.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function gravity_last_update($raw = false)
{
$db = SQLite3_connect(getGravityDBFilename());
$date_file_created_unix = $db->querySingle("SELECT value FROM info WHERE property = 'updated';");
if (false === $date_file_created_unix) {
if ($date_file_created_unix === false) {
if ($raw) {
// Array output
return array('file_exists' => false);
Expand Down Expand Up @@ -43,7 +43,7 @@ function gravity_last_update($raw = false)
// String output (more than one day ago)
return $gravitydiff->format('Adlists updated %a days, %H:%I (hh:mm) ago');
}
if (1 == $gravitydiff->d) {
if ($gravitydiff->d == 1) {
// String output (one day ago)
return $gravitydiff->format('Adlists updated one day, %H:%I (hh:mm) ago');
}
Expand Down
Loading

0 comments on commit 6a39cc3

Please sign in to comment.