Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Change PHP keywords to comply with PSR2 #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions ykval-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function sign($a, $apiKey, $logger)
$qs = utf8_encode($qs);

// base64 encoded binary digest
$hmac = hash_hmac('sha1', $qs, $apiKey, TRUE);
$hmac = hash_hmac('sha1', $qs, $apiKey, true);
$hmac = base64_encode($hmac);

$logger->log(LOG_DEBUG, "SIGN: $qs H=$hmac");
Expand All @@ -96,17 +96,17 @@ function curl_settings($logger, $ident, $ch, $url, $timeout, $opts)
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'YK-VAL');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);

if (is_array($opts) === FALSE)
if (is_array($opts) === false)
{
$logger->log(LOG_WARN, $ident . 'curl options must be an array');
return;
}

foreach ($opts as $key => $val)
if (curl_setopt($ch, $key, $val) === FALSE)
if (curl_setopt($ch, $key, $val) === false)
$logger->log(LOG_WARN, "$ident failed to set " . curl_opt_name($key));
}

Expand All @@ -120,10 +120,10 @@ function curl_opt_name($opt)
$consts = get_defined_constants(true);
$consts = $consts['curl'];

$name = array_search($opt, $consts, TRUE);
$name = array_search($opt, $consts, true);

// array_search may return either on failure...
if ($name === FALSE || $name === NULL)
if ($name === false || $name === null)
return 'curl option';

return $name;
Expand All @@ -136,7 +136,7 @@ function curl_opt_name($opt)
// long as one of the URLs given work, data will be returned. If all
// URLs fail, data from some URL that did not match parameter $match
// (defaults to ^OK) is returned, or if all URLs failed, false.
function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=False, $timeout=10, $curlopts)
function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $returl=false, $timeout=10, $curlopts)
{
$mh = curl_multi_init();
$ch = array();
Expand Down Expand Up @@ -216,9 +216,9 @@ function retrieveURLasync($ident, $urls, $logger, $ans_req=1, $match="^OK", $ret

function KSMdecryptOTP($urls, $logger, $curlopts)
{
$response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=False, $timeout=10, $curlopts);
$response = retrieveURLasync('YK-KSM', $urls, $logger, $ans_req=1, $match='^OK', $returl=false, $timeout=10, $curlopts);

if ($response === FALSE)
if ($response === false)
return false;

$response = array_shift($response);
Expand All @@ -242,7 +242,7 @@ function KSMdecryptOTP($urls, $logger, $curlopts)

function sendResp($status, $logger, $apiKey = '', $extra = null)
{
if ($logger->request !== NULL)
if ($logger->request !== null)
$logger->request->set('status', $status);

$a['status'] = $status;
Expand Down Expand Up @@ -272,15 +272,15 @@ function sendResp($status, $logger, $apiKey = '', $extra = null)

$logger->log(LOG_INFO, "Response: " . $str . " (at " . gmdate("c") . " " . microtime() . ")");

if ($logger->request !== NULL)
if ($logger->request !== null)
$logger->request->write();

echo $str;
exit;
}

// backport from PHP 5.6
if (function_exists('hash_equals') === FALSE)
if (function_exists('hash_equals') === false)
{
function hash_equals($a, $b)
{
Expand Down Expand Up @@ -309,27 +309,27 @@ function total_time ($url)
$opts = array(
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 3,
CURLOPT_FORBID_REUSE => TRUE,
CURLOPT_FRESH_CONNECT => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FORBID_REUSE => true,
CURLOPT_FRESH_CONNECT => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'ykval-munin-vallatency/1.0',
);

if (($ch = curl_init()) === FALSE)
if (($ch = curl_init()) === false)
return false;

if (curl_setopt_array($ch, $opts) === FALSE)
if (curl_setopt_array($ch, $opts) === false)
return false;

// we don't care about the actual response
if (curl_exec($ch) === FALSE)
if (curl_exec($ch) === false)
return false;

$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);

curl_close($ch);

if (is_float($total_time) === FALSE)
if (is_float($total_time) === false)
return false;

return $total_time;
Expand All @@ -355,7 +355,7 @@ function endpoints ($urls)
$internal = substr(sha1($url), 0, 20);

// actual label name shown for graph values
if (($label = hostport($url)) === FALSE)
if (($label = hostport($url)) === false)
{
return false;
}
Expand Down Expand Up @@ -387,20 +387,20 @@ function endpoints ($urls)
*/
function hostport ($url)
{
if (($url = parse_url($url)) === FALSE)
if (($url = parse_url($url)) === false)
return false;

if (array_key_exists('host', $url) === FALSE || $url['host'] === NULL)
if (array_key_exists('host', $url) === false || $url['host'] === null)
return false;

if (array_key_exists('port', $url) === TRUE && $url['port'] !== NULL)
if (array_key_exists('port', $url) === true && $url['port'] !== null)
return $url['host'].':'.$url['port'];

if (array_key_exists('scheme', $url) === TRUE
if (array_key_exists('scheme', $url) === true
&& strtolower($url['scheme']) === 'http')
return $url['host'].':80';

if (array_key_exists('scheme', $url) === TRUE
if (array_key_exists('scheme', $url) === true
&& strtolower($url['scheme']) === 'https')
return $url['host'].':443';

Expand Down
4 changes: 2 additions & 2 deletions ykval-db-oci.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function connect(){
if (!$this->dbh) {
$error = oci_error();
$this->myLog->log(LOG_CRIT, "Database connection error: " . $error["message"]);
$this->dbh=Null;
$this->dbh=null;
return false;
}
return true;
Expand All @@ -88,7 +88,7 @@ protected function query($query, $returnresult=false) {
$result = oci_parse($this->dbh, $query);
if(!oci_execute($result)) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r(oci_error($result), true)));
$this->dbh = Null;
$this->dbh = null;
return false;
}
$this->result = $result;
Expand Down
20 changes: 10 additions & 10 deletions ykval-db-pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function connect(){
$this->dbh = new PDO($this->db_dsn, $this->db_username, $this->db_password, $this->db_options);
} catch (PDOException $e) {
$this->myLog->log(LOG_CRIT, "Database connection error: " . $e->getMessage());
$this->dbh=Null;
$this->dbh=null;
return false;
}
return true;
Expand All @@ -88,7 +88,7 @@ protected function query($query, $returnresult=false) {
$this->result = $this->dbh->query($query);
} catch (PDOException $e) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true)));
$this->dbh = Null;
$this->dbh = null;
return false;
}
if ($returnresult) return $this->result;
Expand Down Expand Up @@ -137,33 +137,33 @@ public function closeCursor($result=null){
*
* @return mixed Array with values from Db row or 2d-array with multiple rows
*/
public function findByMultiple($table, $where, $nr=NULL, $rev=NULL, $distinct=NULL)
public function findByMultiple($table, $where, $nr=null, $rev=null, $distinct=null)
{
$value = '';
$match = NULL;
$match = null;
$query = 'SELECT';

if ($distinct != NULL)
if ($distinct != null)
$query.= " DISTINCT " . $distinct;
else
$query.= " *";

$query.= " FROM " . $table;

if ($where != NULL)
if ($where != null)
{
foreach ($where as $key => $value)
{
if ($key != NULL)
if ($key != null)
{
if ($value != NULL)
if ($value != null)
$match .= " ". $key . " = '" . $value . "' and";
else
$match .= " ". $key . " is NULL and";
}
}

if ($match != NULL)
if ($match != null)
$query .= " WHERE" . $match;

$query = rtrim($query, "and");
Expand All @@ -173,7 +173,7 @@ public function findByMultiple($table, $where, $nr=NULL, $rev=NULL, $distinct=NU
if ($rev == 1)
$query.= " ORDER BY id DESC";

if ($nr != NULL)
if ($nr != null)
$query.= " LIMIT " . $nr;

$result = $this->query($query, true);
Expand Down
6 changes: 3 additions & 3 deletions ykval-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function timestampDeltaTime($first, $second)
*/
public function disconnect()
{
$this->dbh=NULL;
$this->dbh=null;
}

/**
Expand All @@ -104,8 +104,8 @@ public function disconnect()
*/
public function isConnected()
{
if ($this->dbh!=NULL) return True;
else return False;
if ($this->dbh!=null) return true;
else return false;
}

/**
Expand Down
54 changes: 27 additions & 27 deletions ykval-log-verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@

class LogVerify
{
public $format = NULL;
public $format = null;

private $fields = array(
'time_start' => NULL,
'time_end' => NULL,
'time_taken' => NULL,
'ip' => NULL,
'client' => NULL,
'public_id' => NULL,
'otp' => NULL,
'status' => NULL,
'nonce' => NULL,
'signed' => NULL,
'counter' => NULL,
'low' => NULL,
'high' => NULL,
'use' => NULL,
'tls' => NULL,
'protocol' => NULL,
'sl' => NULL,
'timeout' => NULL,
'time_start' => null,
'time_end' => null,
'time_taken' => null,
'ip' => null,
'client' => null,
'public_id' => null,
'otp' => null,
'status' => null,
'nonce' => null,
'signed' => null,
'counter' => null,
'low' => null,
'high' => null,
'use' => null,
'tls' => null,
'protocol' => null,
'sl' => null,
'timeout' => null,
);

/**
Expand All @@ -67,7 +67,7 @@ public function set($name, $value)
if ($name === 'time_end' || $name === 'time_taken')
return false;

if (array_key_exists($name, $this->fields) === FALSE)
if (array_key_exists($name, $this->fields) === false)
return false;

$this->fields[$name] = $value;
Expand All @@ -81,7 +81,7 @@ public function set($name, $value)
*/
public function write()
{
if ($this->format === NULL)
if ($this->format === null)
return false;

$values = array();
Expand Down Expand Up @@ -127,25 +127,25 @@ private function sanitized()
if (preg_match('/^[0-9]+$/', $a['client']) !== 1)
$a['client'] = '-';

if (filter_var($a['ip'], FILTER_VALIDATE_IP) === FALSE)
if (filter_var($a['ip'], FILTER_VALIDATE_IP) === false)
$a['ip'] = '-';

if (is_int($a['counter']) === FALSE)
if (is_int($a['counter']) === false)
$a['counter'] = '-';

if (is_int($a['low']) === FALSE)
if (is_int($a['low']) === false)
$a['low'] = '-';

if (is_int($a['high']) === FALSE)
if (is_int($a['high']) === false)
$a['high'] = '-';

if (is_int($a['use']) === FALSE)
if (is_int($a['use']) === false)
$a['use'] = '-';

if (preg_match('/^[a-zA-Z0-9]{16,40}$/', $a['nonce']) !== 1)
$a['nonce'] = '-';

if (is_float($a['protocol']) === TRUE)
if (is_float($a['protocol']) === true)
$a['protocol'] = sprintf('%.1f', $a['protocol']);
else
$a['protocol'] = '-';
Expand Down
4 changes: 2 additions & 2 deletions ykval-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class Log
{
// request logger object
public $request = NULL;
public $request = null;

private $log_levels = array(
LOG_EMERG => 'LOG_EMERG',
Expand All @@ -57,7 +57,7 @@ public function addField ($name, $value)
$this->fields[$name] = $value;
}

public function log ($priority, $message, $extra = NULL)
public function log ($priority, $message, $extra = null)
{
$prefix = '';
foreach ($this->fields as $val)
Expand Down
Loading