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

@ -1,69 +1,72 @@
<?php
define("BUILD_PATH", dirname(dirname(__DIR__)) . "/build/");
define("AIRTIME_CONF_TEMP_PATH", "/etc/airtime/airtime.conf.temp");
define("RMQ_INI_TEMP_PATH", "/tmp/rabbitmq.ini.tmp");
// load autoloader since this files is an entry path see
define('BUILD_PATH', dirname(dirname(__DIR__)) . '/build/');
define('AIRTIME_CONF_TEMP_PATH', '/etc/airtime/airtime.conf.temp');
define('RMQ_INI_TEMP_PATH', '/tmp/rabbitmq.ini.tmp');
// load autoloader since this files is an entry path see
// the end of the file for the "server" that is being
// executed.
require_once __DIR__ . '/../../vendor/autoload.php';
/**
* Class Setup
* Class Setup.
*
* @author sourcefabric
*
*
* Abstract superclass for the setup and installation process
*/
abstract class Setup {
abstract class Setup
{
protected static $_section;
/**
* Array of key->value pairs for airtime.conf
* Array of key->value pairs for airtime.conf.
*
* @var array
*/
protected static $_properties;
abstract function __construct($settings);
abstract public function __construct($settings);
abstract function runSetup();
abstract public function runSetup();
/**
* Write new property values to a given section in airtime.conf.temp
* Write new property values to a given section in airtime.conf.temp.
*/
protected function writeToTemp() {
protected function writeToTemp()
{
if (!file_exists(AIRTIME_CONF_TEMP_PATH)) {
copy(BUILD_PATH . "airtime.example.conf", AIRTIME_CONF_TEMP_PATH);
copy(BUILD_PATH . 'airtime.example.conf', AIRTIME_CONF_TEMP_PATH);
}
//Logging::info(AIRTIME_CONF_TEMP_PATH);
$this->_write(AIRTIME_CONF_TEMP_PATH);
}
protected function _write($filePath) {
protected function _write($filePath)
{
$file = file($filePath);
$fileOutput = "";
$fileOutput = '';
$inSection = false;
foreach ($file as $line) {
if (strpos($line, static::$_section) !== false) {
$inSection = true;
} else if (strpos($line, "[") !== false) {
} elseif (strpos($line, '[') !== false) {
$inSection = false;
}
if (substr(trim($line), 0, 1) == "#") {
if (substr(trim($line), 0, 1) == '#') {
/* Workaround to strip comments from airtime.conf.
* We need to do this because python's ConfigObj and PHP
* have different (and equally strict) rules about comment
* characters in configuration files.
*/
} else if ($inSection) {
$key = trim(@substr($line, 0, strpos($line, "=")));
} elseif ($inSection) {
$key = trim(@substr($line, 0, strpos($line, '=')));
$fileOutput .= $key && isset(static::$_properties[$key]) ?
$key . " = " . static::$_properties[$key] . "\n" : $line;
$key . ' = ' . static::$_properties[$key] . "\n" : $line;
} else {
$fileOutput .= $line;
}
@ -75,66 +78,72 @@ abstract class Setup {
/**
* Generates a random string.
*
* @param integer $p_len
* length of the output string
* @param int $p_len
* length of the output string
* @param string $p_chars
* characters to use in the output string
* characters to use in the output string
*
* @return string the generated random string
*/
protected function generateRandomString($p_len = 20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
protected function generateRandomString($p_len = 20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
{
$string = '';
for($i = 0; $i < $p_len; $i++) {
for ($i = 0; $i < $p_len; ++$i) {
$pos = mt_rand(0, strlen($p_chars) - 1);
$string .= $p_chars{$pos};
$string .= $p_chars[$pos];
}
return $string;
}
}
/**
* Class AirtimeDatabaseException
*
* Class AirtimeDatabaseException.
*
* @author sourcefabric
*
* Exception class for database setup errors
*/
class AirtimeDatabaseException extends Exception {
protected $message = "Unknown Airtime database exception";
protected $errors = array();
class AirtimeDatabaseException extends Exception
{
protected $message = 'Unknown Airtime database exception';
protected $errors = [];
public function __construct($message = null, $errors = array(), $code = 0, Exception $previous = null) {
public function __construct($message = null, $errors = [], $code = 0, Exception $previous = null)
{
parent::__construct($message, $code, $previous);
$this->errors = $errors;
}
public function getErrorFields() {
public function getErrorFields()
{
return $this->errors;
}
}
// Import Setup subclasses
require_once ('database-setup.php');
require_once ('rabbitmq-setup.php');
require_once ('general-setup.php');
require_once ('media-setup.php');
require_once 'database-setup.php';
require_once 'rabbitmq-setup.php';
require_once 'general-setup.php';
require_once 'media-setup.php';
// If airtime.conf exists, we shouldn't be here
if (!file_exists("/etc/airtime/airtime.conf")) {
if (isset($_GET["obj"]) && $objType = $_GET["obj"]) {
if (!file_exists('/etc/airtime/airtime.conf')) {
if (isset($_GET['obj']) && $objType = $_GET['obj']) {
$obj = new $objType($_POST);
if ($obj instanceof Setup) {
try {
$response = $obj->runSetup();
} catch (AirtimeDatabaseException $e) {
$response = array(
"message" => $e->getMessage(),
"errors" => $e->getErrorFields()
);
$response = [
'message' => $e->getMessage(),
'errors' => $e->getErrorFields(),
];
}
echo json_encode($response);
}
}