-
Notifications
You must be signed in to change notification settings - Fork 320
Modernize, simplify, refacto the jeedomClass #3101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: alpha
Are you sure you want to change the base?
Conversation
core/class/jeedom.class.php
Outdated
} | ||
|
||
public static function deadCmd() { | ||
public static function deadCmd(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ce genre de modification, bien que positive à terme, est risqué. Un changement de signature de methode non privée est un breaking change en cas d'extension de cette classe dans un plugin. Bien que peu probable, c'est surement plus prudent de typer via la phpdoc.
core/class/jeedom.class.php
Outdated
sleep(5); | ||
$cron->halt(); | ||
} catch (Error $e) { | ||
} catch (Exception|Error $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cette notation équivaut à catch (Throwable $e)
qui me semble plus simple.
user::searchByOptions($key), | ||
user::searchByRight($key), | ||
]; | ||
foreach ($searchExpressions as $result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plus efficace : $datas = array_merge(...$searchExpressions);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectivement, mais le comportement n'est pas le même entre PHP 7.4 et 7.3. pour le moment on devrait laisser comme ça
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est pas une histoire avec les tableaux vides?
Si c'est ça on peut forcer avec array_merge([], ...$tab);
Pardon d'insister mais le gain de performance sur ce type d'algo est énorme. array_merge est très lent, et dans une boucle on monte vite à plus d'une seconde d'execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je regarde pour tenter d'optimiser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fait
core/class/jeedom.class.php
Outdated
|
||
public static function checkSpaceLeft($_dir = null) { | ||
if ($_dir == null) { | ||
if ($_dir === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je m’y risquerai pas, sauf si t’as bien étudié les différents appels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai verifié, c'est ok
Excellente idée de simplifier / refactoriser les classes :) est-ce qu'on a un dashboard sonarqube qui permettrait de mettre en avant les améliorations possibles ? J'ai essayé de le faire avec snoarcloud.io (gratuit en ligne), par exemple pour cette classe: |
user::searchByOptions($key), | ||
user::searchByRight($key), | ||
]; | ||
foreach ($searchExpressions as $result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectivement, mais le comportement n'est pas le même entre PHP 7.4 et 7.3. pour le moment on devrait laisser comme ça
core/class/jeedom.class.php
Outdated
|
||
public static function checkSpaceLeft($_dir = null) { | ||
if ($_dir == null) { | ||
if ($_dir === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai verifié, c'est ok
core/class/jeedom.class.php
Outdated
$cron->halt(); | ||
} catch (Error $e) { | ||
} catch (Throwable $e) { | ||
`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coquille (merci phpstan)
user::searchByOptions($key), | ||
user::searchByRight($key), | ||
]; | ||
foreach ($searchExpressions as $result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je regarde pour tenter d'optimiser.
core/class/jeedom.class.php
Outdated
sleep(5); | ||
$cron->halt(); | ||
} catch (Error $e) { | ||
} catch (Exception|Error $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (Exception|Error $e) { | |
} catch (\Throwable $e) { |
user::searchByOptions($key), | ||
user::searchByRight($key), | ||
]; | ||
foreach ($searchExpressions as $result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fait
core/class/jeedom.class.php
Outdated
} | ||
|
||
public static function deadCmd() { | ||
public static function deadCmd(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function deadCmd(): array { | |
/** | |
* @return array | |
*/ | |
public static function deadCmd() { |
} | ||
|
||
public static function listBackup() { | ||
public static function listBackup(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Même chose que pour deadCmd
, je voulais pas spammer.
En règle général, un changement de signature de méthode est un BC, sauf cas très particulier.
C’est donc valable pour les fonctions suivantes.
Comme c’est tout de même un changement positif, tu peux éventuellement faire une PR avec uniquement ces changements. Ça permettra de voir si c’est mergeable ou pas.
Et n’hésite pas à compléter les PHP doc, on a fait un petit guide ici https://github.com/jeedom/documentations/pull/157/files (pas encore mergé)
Bonjour, |
J'ai déjà fait une PR #3005 dans ce sens (qui date un peu) mais c'est l'idée. Normalement on n'utilise que des espaces en php, pas de tab. |
Il y a du boulot alors :-) , car pratiquement tous les fichiers php utilisent des tab. ![]() |
Je peux accepter sans problème qu'on n'ai des points de vue différents, mais encore faudrait-il expliquer son point de vue plutôt que de mettre un pouce vers le bas sans autre explication @Salvialf |
Description
Dans cette PR, je me suis attaché à rendre le code plus explicite et optimal. J'ai aussi essayé de baisser la complexité cyclomatique de certaines méthodes.
Related issues/external references
PR checklist