Applied PHP formatting rules

This commit is contained in:
Bernd Bestel
2020-08-31 20:40:31 +02:00
parent 33325d5560
commit d4c5da2173
58 changed files with 3667 additions and 3082 deletions

View File

@@ -2,12 +2,14 @@
function FindObjectInArrayByPropertyValue($array, $propertyName, $propertyValue)
{
foreach($array as $object)
foreach ($array as $object)
{
if($object->{$propertyName} == $propertyValue)
if ($object->{$propertyName}
== $propertyValue)
{
return $object;
}
}
return null;
@@ -15,31 +17,41 @@ function FindObjectInArrayByPropertyValue($array, $propertyName, $propertyValue)
function FindAllObjectsInArrayByPropertyValue($array, $propertyName, $propertyValue, $operator = '==')
{
$returnArray = array();
$returnArray = [];
foreach($array as $object)
foreach ($array as $object)
{
switch($operator)
switch ($operator)
{
case '==':
if($object->{$propertyName} == $propertyValue)
if ($object-> {$propertyName}
== $propertyValue)
{
$returnArray[] = $object;
}
break;
case '>':
if($object->{$propertyName} > $propertyValue)
if ($object-> {$propertyName}
> $propertyValue)
{
$returnArray[] = $object;
}
break;
case '<':
if($object->{$propertyName} < $propertyValue)
if ($object-> {$propertyName}
< $propertyValue)
{
$returnArray[] = $object;
}
break;
}
}
return $returnArray;
@@ -47,31 +59,38 @@ function FindAllObjectsInArrayByPropertyValue($array, $propertyName, $propertyVa
function FindAllItemsInArrayByValue($array, $value, $operator = '==')
{
$returnArray = array();
$returnArray = [];
foreach($array as $item)
foreach ($array as $item)
{
switch($operator)
switch ($operator)
{
case '==':
if($item == $value)
if ($item == $value)
{
$returnArray[] = $item;
}
break;
case '>':
if($item > $value)
if ($item > $value)
{
$returnArray[] = $item;
}
break;
case '<':
if($item < $value)
if ($item < $value)
{
$returnArray[] = $item;
}
break;
}
}
return $returnArray;
@@ -80,7 +99,8 @@ function FindAllItemsInArrayByValue($array, $value, $operator = '==')
function SumArrayValue($array, $propertyName)
{
$sum = 0;
foreach($array as $object)
foreach ($array as $object)
{
$sum += floatval($object->{$propertyName});
}
@@ -102,11 +122,13 @@ function GetClassConstants($className, $prefix = null)
$matchingKeys = preg_grep('!^' . $prefix . '!', array_keys($constants));
return array_intersect_key($constants, array_flip($matchingKeys));
}
}
function RandomString($length, $allowedChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$randomString = '';
for ($i = 0; $i < $length; $i++)
{
$randomString .= $allowedChars[rand(0, strlen($allowedChars) - 1)];
@@ -142,13 +164,16 @@ function ExternalSettingValue(string $value)
{
$tvalue = rtrim($value, "\r\n");
$lvalue = strtolower($tvalue);
if ($lvalue === "true"){
if ($lvalue === 'true')
{
return true;
}
elseif ($lvalue === "false")
elseif ($lvalue === 'false')
{
return false;
}
return $tvalue;
}
@@ -158,30 +183,35 @@ function Setting(string $name, $value)
{
// The content of a $name.txt file in /data/settingoverrides can overwrite the given setting (for embedded mode)
$settingOverrideFile = GROCY_DATAPATH . '/settingoverrides/' . $name . '.txt';
if (file_exists($settingOverrideFile))
{
define('GROCY_' . $name, ExternalSettingValue(file_get_contents($settingOverrideFile)));
}
elseif (getenv('GROCY_' . $name) !== false) // An environment variable with the same name and prefix GROCY_ overwrites the given setting
{
define('GROCY_' . $name, ExternalSettingValue(getenv('GROCY_'. $name)));
define('GROCY_' . $name, ExternalSettingValue(getenv('GROCY_' . $name)));
}
else
{
define('GROCY_' . $name, $value);
}
}
}
global $GROCY_DEFAULT_USER_SETTINGS;
$GROCY_DEFAULT_USER_SETTINGS = array();
$GROCY_DEFAULT_USER_SETTINGS = [];
function DefaultUserSetting(string $name, $value)
{
global $GROCY_DEFAULT_USER_SETTINGS;
if (!array_key_exists($name, $GROCY_DEFAULT_USER_SETTINGS))
{
$GROCY_DEFAULT_USER_SETTINGS[$name] = $value;
}
}
function GetUserDisplayName($user)
@@ -210,7 +240,7 @@ function GetUserDisplayName($user)
function IsValidFileName($fileName)
{
if(preg_match('=^[^/?*;:{}\\\\]+\.[^/?*;:{}\\\\]+$=', $fileName))
if (preg_match('=^[^/?*;:{}\\\\]+\.[^/?*;:{}\\\\]+$=', $fileName))
{
return true;
}
@@ -232,6 +262,7 @@ function string_starts_with($haystack, $needle)
function string_ends_with($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0)
{
return true;