Format code using php-cs-fixer

This commit is contained in:
jo 2021-10-11 16:10:47 +02:00
parent 43d7dc92cd
commit d52c6184b9
352 changed files with 17473 additions and 17041 deletions

View file

@ -2,41 +2,38 @@
class Airtime_Zend_Log extends Zend_Log
{
/**
*
* @var boolean
* @var bool
*/
protected $_registeredErrorHandler = false;
/**
*
* @var array|boolean
* @var array|bool
*/
protected $_errorHandlerMap = false;
protected $_errorHandlerMap = false;
/**
*
* @var callback
* @var callable
*/
protected $_origErrorHandler = null;
protected $_origErrorHandler;
public function __construct(Zend_Log_Writer_Abstract $writer = null)
{
parent::__construct($writer);
}
/**
* Error Handler will convert error into log message, and then call the original error handler
* Error Handler will convert error into log message, and then call the original error handler.
*
* @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
* @param int $errno
* @see http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
*
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return boolean
* @param int $errline
* @param array $errcontext
*
* @return bool
*/
public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
@ -48,15 +45,16 @@ class Airtime_Zend_Log extends Zend_Log
} else {
$priority = Zend_Log::INFO;
}
$this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
$this->log($errstr, $priority, ['errno' => $errno, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext]);
}
if ($this->_origErrorHandler !== null) {
return call_user_func($this->_origErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext);
}
return false;
}
/**
* Register Logging system as an error handler to log php errors
* Note: it still calls the original error handler if set_error_handler is able to return it.
@ -68,7 +66,7 @@ class Airtime_Zend_Log extends Zend_Log
* E_DEPRECATED, E_STRICT, E_USER_DEPRECATED => DEBUG
* (unknown/other) => INFO
*
* @link http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
* @see http://www.php.net/manual/en/function.set-error-handler.php Custom error handler
*
* @return Zend_Log
*/
@ -79,22 +77,22 @@ class Airtime_Zend_Log extends Zend_Log
return $this;
}
$this->_origErrorHandler = set_error_handler(array($this, 'errorHandler'));
$this->_origErrorHandler = set_error_handler([$this, 'errorHandler']);
// Contruct a default map of phpErrors to Zend_Log priorities.
// Some of the errors are uncatchable, but are included for completeness
$this->_errorHandlerMap = array(
E_NOTICE => Zend_Log::NOTICE,
E_USER_NOTICE => Zend_Log::NOTICE,
E_WARNING => Zend_Log::WARN,
E_CORE_WARNING => Zend_Log::WARN,
E_USER_WARNING => Zend_Log::WARN,
E_ERROR => Zend_Log::ERR,
E_USER_ERROR => Zend_Log::ERR,
E_CORE_ERROR => Zend_Log::ERR,
$this->_errorHandlerMap = [
E_NOTICE => Zend_Log::NOTICE,
E_USER_NOTICE => Zend_Log::NOTICE,
E_WARNING => Zend_Log::WARN,
E_CORE_WARNING => Zend_Log::WARN,
E_USER_WARNING => Zend_Log::WARN,
E_ERROR => Zend_Log::ERR,
E_USER_ERROR => Zend_Log::ERR,
E_CORE_ERROR => Zend_Log::ERR,
E_RECOVERABLE_ERROR => Zend_Log::ERR,
E_STRICT => Zend_Log::DEBUG,
);
E_STRICT => Zend_Log::DEBUG,
];
// PHP 5.3.0+
if (defined('E_DEPRECATED')) {
$this->_errorHandlerMap['E_DEPRECATED'] = Zend_Log::DEBUG;
@ -104,6 +102,7 @@ class Airtime_Zend_Log extends Zend_Log
}
$this->_registeredErrorHandler = true;
return $this;
}
}

View file

@ -1,7 +1,7 @@
<?php
class Logging {
class Logging
{
private static $_logger;
private static $_path;
@ -9,17 +9,18 @@ class Logging {
{
if (!isset(self::$_logger)) {
$writer = new Zend_Log_Writer_Stream(self::$_path);
if (Zend_Version::compareVersion("1.11") > 0) {
if (Zend_Version::compareVersion('1.11') > 0) {
//Running Zend version 1.10 or lower. Need to instantiate our
//own Zend Log class with backported code from 1.11.
require_once __DIR__."/AirtimeLog.php";
require_once __DIR__ . '/AirtimeLog.php';
self::$_logger = new Airtime_Zend_Log($writer);
} else {
self::$_logger = new Zend_Log($writer);
}
self::$_logger->registerErrorHandler();
}
return self::$_logger;
}
@ -27,27 +28,29 @@ class Logging {
{
self::$_path = $path;
}
public static function toString($p_msg)
{
if (is_array($p_msg) || is_object($p_msg)) {
return print_r($p_msg, true);
} else if (is_bool($p_msg)) {
return $p_msg ? "true" : "false";
} else {
return $p_msg;
}
if (is_bool($p_msg)) {
return $p_msg ? 'true' : 'false';
}
return $p_msg;
}
/** @param debugMode Prints the function name, file, and line number. This is slow as it uses debug_backtrace()
* so don't use it unless you need it.
* @param mixed $debugMode
*/
private static function getLinePrefix($debugMode=false)
private static function getLinePrefix($debugMode = false)
{
$linePrefix = "";
$linePrefix = '';
if (array_key_exists('SERVER_NAME', $_SERVER)) {
$linePrefix .= $_SERVER['SERVER_NAME'] . " ";
$linePrefix .= $_SERVER['SERVER_NAME'] . ' ';
}
if ($debugMode) {
@ -56,16 +59,16 @@ class Logging {
$caller = $bt[1];
$file = basename($caller['file']);
$line = $caller['line'];
$function = "Unknown function";
$function = 'Unknown function';
if (array_key_exists(2, $bt)) {
$function = $bt[2]['function'];
}
$linePrefix .= "[$file:$line - $function()] - ";
$linePrefix .= "[{$file}:{$line} - {$function}()] - ";
}
return $linePrefix;
}
public static function info($p_msg)
{
$logger = self::getLogger();
@ -81,17 +84,17 @@ class Logging {
public static function error($p_msg)
{
$logger = self::getLogger();
$logger->err(self::getLinePrefix(true) . self::toString($p_msg));
$logger->err(self::getLinePrefix(true) . self::toString($p_msg));
//Escape the % symbols in any of our errors because Sentry chokes (vsprint formatting error).
$msg = self::toString($p_msg);
$msg = str_replace("%", "%%", $msg);
$msg = str_replace('%', '%%', $msg);
SentryLogger::getInstance()->captureError($msg);
}
public static function debug($p_msg)
{
if (!(defined('APPLICATION_ENV') && APPLICATION_ENV == "development")) {
if (!(defined('APPLICATION_ENV') && APPLICATION_ENV == 'development')) {
return;
}
@ -103,8 +106,8 @@ class Logging {
public static function debug_sparse(array $p_msg)
{
Logging::debug("Sparse output:");
Logging::debug( array_filter($p_msg) );
Logging::debug('Sparse output:');
Logging::debug(array_filter($p_msg));
}
public static function enablePropelLogging()
@ -138,8 +141,7 @@ class Logging {
return;
}
switch($err['type'])
{
switch ($err['type']) {
case E_ERROR:
case E_WARNING:
case E_PARSE:
@ -153,17 +155,16 @@ class Logging {
if (array_key_exists('message', $err)) {
$errorStr .= $err['message'];
}
if (array_key_exists('file', $err))
{
$errorStr .= ' at ' .$err['file'];
if (array_key_exists('file', $err)) {
$errorStr .= ' at ' . $err['file'];
}
if (array_key_exists('line', $err))
{
if (array_key_exists('line', $err)) {
$errorStr .= ':' . $err['line'];
}
$errorStr .= "\n" . var_export($err, true);
Logging::error($errorStr);
break;
}
}
@ -173,6 +174,4 @@ class Logging {
//Static callback:
register_shutdown_function('Logging::loggingShutdownCallback');
}
}

View file

@ -2,7 +2,7 @@
class SentryLogger
{
private static $instance = null;
private static $instance;
private $sentryClient;
/** Singleton getter */
@ -10,31 +10,34 @@ class SentryLogger
{
if (!is_null(self::$instance)) {
return self::$instance;
} else {
self::$instance = new SentryLogger();
return self::$instance;
}
self::$instance = new SentryLogger();
return self::$instance;
}
private function __construct()
{
if (!file_exists(SENTRY_CONFIG_PATH)) {
$this->sentryClient = null;
return;
}
// Instantiate a new client with a compatible DSN
$sentry_config = parse_ini_file(SENTRY_CONFIG_PATH, false);
$dsn = $sentry_config['dsn'];
$this->sentryClient = new Raven_Client($dsn,
array(
$this->sentryClient = new Raven_Client(
$dsn,
[
//FIXME: This doesn't seem to be working...
'processorOptions' => array(
'Raven_SanitizeDataProcessor' => array(
'processorOptions' => [
'Raven_SanitizeDataProcessor' => [
'fields_re' => '/(authorization|password|passwd|user_token|secret|SESSION)/i',
'values_re' => '/^(?:\d[ -]*?){13,16}$/'
)
)
));
'values_re' => '/^(?:\d[ -]*?){13,16}$/',
],
],
]
);
$client = $this->sentryClient;
/* The Raven docs suggest not enabling these because they're "too noisy".
@ -74,10 +77,10 @@ class SentryLogger
self::addUserData($client);
self::addTags($client);
$event_id = $client->getIdent($client->captureException($exception, array(
$event_id = $client->getIdent($client->captureException($exception, [
'extra' => $this->getExtraData(),
'tags' => $this->getTags(),
)));
]));
$client->context->clear();
}
@ -92,17 +95,18 @@ class SentryLogger
// Provide some additional data with an exception
self::addUserData($client);
self::addTags($client);
$event_id = $client->getIdent($client->captureMessage($errorMessage, array(
'extra' => $this->getExtraData()
)));
$event_id = $client->getIdent($client->captureMessage($errorMessage, [
'extra' => $this->getExtraData(),
]));
$client->context->clear();
}
private static function getTags()
{
$tags = array();
$tags = [];
$config = Config::getConfig();
$tags['Development Environment'] = $config["dev_env"];
$tags['Development Environment'] = $config['dev_env'];
return $tags;
}
@ -113,19 +117,19 @@ class SentryLogger
private static function addUserData($client)
{
$userData = array();
$userData = [];
$userData['client_id'] = Application_Model_Preference::GetClientId();
$userData['station_url'] = array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : "";
$userData['station_url'] = array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : '';
$client->user_context($userData);
}
/** Extra data to log with Sentry */
private function getExtraData()
{
$extraData = array();
$extraData = [];
$extraData['php_version'] = phpversion();
$extraData['client_id'] = Application_Model_Preference::GetClientId();
return $extraData;
}
}