Skip to content

Commit

Permalink
- Indentation
Browse files Browse the repository at this point in the history
- PhpDoc
  • Loading branch information
LusanSmile committed Jan 29, 2020
1 parent 25f6762 commit 24d68ef
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 34 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "nextdom/core",
"description": "Software for home automation Open Source",
"require": {
"ext-json": "*",
"christian-riesen/base32": "^1.3",
"doctrine/cache": "^1.6",
"endroid/qr-code": "^2.5",
Expand Down
18 changes: 13 additions & 5 deletions src/Managers/BackupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
*/
class BackupManager
{
/**
* @var null
*/
private static $logLevel = null;

/**
Expand Down Expand Up @@ -72,6 +75,7 @@ public static function backup(bool $background = false)
*
* @return bool true if no error
* @throws CoreException
* @throws \Exception
*/
public static function createBackup()
{
Expand Down Expand Up @@ -315,13 +319,14 @@ public static function createBackupArchive(string $outputPath, $sqlPath, $cacheP
}

/**
* @param array $roots
* @param array $roots
* @param string $pattern
* @param Tar $tar
* @param $logFile
* @param Tar $tar
* @param $logFile
* @throws \splitbrain\PHPArchive\ArchiveCorruptedException
* @throws \splitbrain\PHPArchive\ArchiveIOException
* @throws \splitbrain\PHPArchive\FileInfoException
* @throws \Exception
*/
private static function addPathToArchive($roots, $pattern, $tar, $logFile)
{
Expand Down Expand Up @@ -609,6 +614,7 @@ private static function extractArchive($file)
*
* @param string $tmpDir extracted backup root directory
* @throws CoreException
* @throws \Exception
*/
private static function restorePlugins($tmpDir)
{
Expand Down Expand Up @@ -643,6 +649,7 @@ private static function restorePlugins($tmpDir)
*
* @param $folderRoot
* @throws CoreException on permission error
* @throws \Exception
*/
private static function restorePublicPerms($folderRoot)
{
Expand Down Expand Up @@ -855,9 +862,9 @@ private static function clearCache()
}

/**
* Obtenir la liste des sauvegardes
* Get the list of backups
*
* @return array Liste des sauvegardes
* @return array list of backups
* @throws \Exception
*/
public static function listBackup(): array
Expand All @@ -879,6 +886,7 @@ public static function listBackup(): array
* @param string $backupFilePath Backup file path
*
* @throws CoreException
* @throws \Exception
*/
public static function removeBackup(string $backupFilePath)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Managers/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function stats($details = false)
$result['count']++;
}
}
} else if ($engine == CacheEngine::REDIS) {
} elseif ($engine == CacheEngine::REDIS) {
$result['count'] = self::$cacheSystem->getRedis()->dbSize();
}
if ($details) {
Expand Down
8 changes: 8 additions & 0 deletions src/Managers/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,18 @@ public static function preConfig_market_password($newValue)
return $newValue;
}

/**
* @param $_value
* @return string|string[]
*/
public static function preConfig_info_latitude($_value){
return str_replace(',','.',$_value);
}

/**
* @param $_value
* @return string|string[]
*/
public static function preConfig_info_longitude($_value){
return str_replace(',','.',$_value);
}
Expand Down
21 changes: 15 additions & 6 deletions src/Managers/ConsistencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
*/
class ConsistencyManager
{
/**
* @var array
*/
private static $defaultSummary = [
'security' => ['key' => 'security', 'name' => 'Alerte', 'calcul' => 'sum', 'icon' => '<i class="icon nextdom-alerte2"></i>', 'unit' => '', 'count' => 'binary', 'allowDisplayZero' => false],
'motion' => ['key' => 'motion', 'name' => 'Mouvement', 'calcul' => 'sum', 'icon' => '<i class="icon nextdom-mouvement"></i>', 'unit' => '', 'count' => 'binary', 'allowDisplayZero' => false],
Expand Down Expand Up @@ -130,11 +133,11 @@ private static function checkAllDefaultCrons()
if (false == is_object($cron)) {
$cron = new Cron();
}
$cron->setClass($cronClass);
$cron->setFunction($cronName);
$cron->setSchedule($cronConfig["schedule"]);
$cron->setTimeout($cronConfig["timeout"]);
$cron->setDeamon(0);
$cron->setClass($cronClass)
->setFunction($cronName)
->setSchedule($cronConfig["schedule"])
->setTimeout($cronConfig["timeout"])
->setDeamon(0);
if (true == array_key_exists("enabled", $cronConfig)) {
$cron->setEnable($cronConfig["enabled"]);
}
Expand All @@ -148,7 +151,7 @@ private static function checkAllDefaultCrons()
/**
* @return array
*/
public static function getDefaultCrons()
public static function getDefaultCrons(): array
{
return [
"nextdom" => [
Expand Down Expand Up @@ -249,6 +252,9 @@ public static function getDefaultCrons()
];
}

/**
* @throws \Exception
*/
private static function cleanWidgetCache()
{
foreach (EqLogicManager::all() as $c_item) {
Expand All @@ -269,6 +275,9 @@ private static function saveObjects()
}
}

/**
* @throws \Exception
*/
private static function resetCommandsActionID()
{
foreach (CmdManager::all() as $c_cmd) {
Expand Down
8 changes: 5 additions & 3 deletions src/Managers/CronManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ public static function searchClassAndFunction($className, $functionName, $option

/**
* Clean cron that will never run
* @throws \Exception
*/
public static function clean()
{
$crons = self::all();
foreach ($crons as $cron) {
$cronExpression = new \Cron\CronExpression($cron->getSchedule(), new \Cron\FieldFactory);
$cronExpression = new \Cron\CronExpression($cron->getSchedule(), new \Cron\FieldFactory());
try {
if (!$cronExpression->isDue()) {
$cronExpression->getNextRunDate();
Expand Down Expand Up @@ -176,6 +177,7 @@ public static function loadAvg()

/**
* Write jeeCron PID of current process
* @throws \Exception
*/
public static function setPidFile()
{
Expand Down Expand Up @@ -203,7 +205,7 @@ public static function jeeCronRun()
/**
* Return the current pid of jeecron or empty if not running
*
* @return int Current jeeCron PID
* @return false|string Current jeeCron PID
* @throws \Exception
*/
public static function getPidFile()
Expand Down Expand Up @@ -234,7 +236,7 @@ public static function convertDateToCron($dateToConvert)
* @return string
* @throws \Exception
*/
public static function convertCronSchedule($cron)
public static function convertCronSchedule(string $cron)
{
$return = str_replace('*/ ', '* ', $cron);
preg_match_all('/([0-9]*\/\*)/m', $return, $matches, PREG_SET_ORDER, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/Managers/EqLogicManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ public static function allType()

/**
* Vérifier si un objet est actif
* @throws \Exception
*/
public static function checkAlive()
{
Expand Down Expand Up @@ -426,6 +427,7 @@ public static function byTimeout($timeout = 0, $onlyEnable = false)
* @param $input
* @return array|mixed
* @throws \ReflectionException
* @throws CoreException
*/
public static function toHumanReadable($input)
{
Expand Down Expand Up @@ -467,6 +469,7 @@ public static function toHumanReadable($input)

/**
* @TODO: ???
* @throws \Exception
*/
public static function clearCacheWidget()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Managers/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public static function add($eventCode, $eventOptions = [])
/**
* Add multiple events in cache
*
* @param string $eventName
* @param array $values
* @param $eventCode
* @param array $eventOptions
* @throws \Exception
*/
public static function adds($eventCode, $eventOptions = [])
Expand All @@ -126,7 +126,7 @@ public static function adds($eventCode, $eventOptions = [])
/**
* Clean events
*
* @param $events
* @param $_events
* @return array
*/
public static function cleanEvent($_events)
Expand Down Expand Up @@ -274,4 +274,4 @@ private static function changesSince($_datetime)
$result[Common::RESULT] = array_reverse($result[Common::RESULT]);
return $result;
}
}
}
4 changes: 4 additions & 0 deletions src/Managers/InteractDefManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public static function searchByQuery($_query)
return static::searchMultipleByClauses($clauses);
}

/**
* @throws \NextDom\Exceptions\CoreException
* @throws \ReflectionException
*/
public static function regenerateInteract()
{
foreach (self::all() as $interactDef) {
Expand Down
12 changes: 12 additions & 0 deletions src/Managers/JeeObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public static function getRootObjects($all = false, $onlyVisible = false)
return DBHelper::Prepare($sql, [], $fetchType, \PDO::FETCH_CLASS, self::CLASS_NAME);
}

/**
* @param User $user
* @return array|mixed|null
* @throws CoreException
*/
public static function getDefaultUserRoom(User $user)
{
$rootRoomId = $user->getOptions('defaultDashboardObject');
Expand Down Expand Up @@ -196,6 +201,13 @@ public static function all($onlyVisible = false)
return static::getMultipleByClauses($clauses, ['position', 'name', 'father_id']);
}

/**
* @param $father_id
* @param $onlyVisible
* @return mixed|null
* @throws CoreException
* @throws \ReflectionException
*/
public static function getChildren($father_id, $onlyVisible)
{
$clauses = ['father_id' => $father_id];
Expand Down
7 changes: 6 additions & 1 deletion src/Managers/Parents/CastedObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ abstract static function cast($castType);
byId as baseById;
}

/**
* @param $requestedId
* @return mixed
* @throws CoreException
*/
public static function byId($requestedId) {

return static::cast(static::baseById($requestedId));
}
}
}
19 changes: 6 additions & 13 deletions src/Managers/Parents/CommonManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ trait CommonManager
* @return mixed
*
* @throws CoreException
* @throws \ReflectionException
*/
public static function byId($requestedId)
{
if (empty($requestedId)) {
if (empty($requestedId) === true) {
return null;
}
$params = ['id' => $requestedId];
Expand All @@ -70,7 +69,6 @@ public static function byId($requestedId)
* @return mixed|null
*
* @throws CoreException
* @throws \ReflectionException
*/
protected static function getAll()
{
Expand All @@ -87,7 +85,6 @@ protected static function getAll()
* @return mixed|null
*
* @throws CoreException
* @throws \ReflectionException
*/
protected static function getAllOrdered(string $orderColumn, bool $reverseOrder = false, int $limit = 0)
{
Expand Down Expand Up @@ -181,10 +178,9 @@ protected static function searchMultipleByClauses(array $clauses, $orderColumn =
*/
private static function query(array $clauses, $compOperator = '', bool $onlyOneResult = false, $orderColumn = '', bool $reverseOrder = false) {
$sql = static::createSQL($clauses, $compOperator, $orderColumn, $reverseOrder);
if ($onlyOneResult) {
if ($onlyOneResult === true) {
return DBHelper::getOneObject($sql, $clauses, static::CLASS_NAME);
}
else {
} else {
return DBHelper::getAllObjects($sql, $clauses, static::CLASS_NAME);
}
}
Expand All @@ -199,7 +195,6 @@ private static function query(array $clauses, $compOperator = '', bool $onlyOneR
*
* @return string
*
* @throws \ReflectionException
*/
private static function createSQL(array $clauses, string $compOperator, $orderColumn = '', bool $reverseOrder = false)
{
Expand All @@ -209,17 +204,15 @@ private static function createSQL(array $clauses, string $compOperator, $orderCo
foreach ($clauses as $clauseName => $clauseValue) {
if ($sqlClauses === '') {
$sqlClauses = "WHERE ";
}
else {
} else {
$sqlClauses .= "AND ";
}
$sqlClauses .= "`$clauseName` $compOperator :$clauseName ";
}
if ($orderColumn !== '') {
if (is_array($orderColumn)) {
$sqlOrder = "ORDER BY `" . implode("`, `", $orderColumn) . "`";
}
else {
} else {
$sqlOrder = "ORDER BY `$orderColumn`";
}
if ($reverseOrder) {
Expand All @@ -228,4 +221,4 @@ private static function createSQL(array $clauses, string $compOperator, $orderCo
}
return $sql . $sqlClauses . $sqlOrder;
}
}
}
3 changes: 2 additions & 1 deletion src/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@
*
* @param string $className Name of the class
*
* @throws CoreException
* @throws Exception
*/
function nextdomPluginAutoload($className)
function nextdomPluginAutoload(string $className)
{
global $ENABLED_PLUGINS;
if ($ENABLED_PLUGINS === null) {
Expand Down

0 comments on commit 24d68ef

Please sign in to comment.