Skip to content

Conversation

ColonelMoutarde
Copy link
Contributor

@ColonelMoutarde ColonelMoutarde commented Jul 3, 2025

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

  • Improvement

PR checklist

@ColonelMoutarde ColonelMoutarde marked this pull request as draft July 3, 2025 06:55
@ColonelMoutarde ColonelMoutarde marked this pull request as ready for review July 3, 2025 07:36
}

public static function deadCmd() {
public static function deadCmd(): array {
Copy link
Contributor

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.

@Mips2648 Mips2648 self-requested a review July 5, 2025 09:23
sleep(5);
$cron->halt();
} catch (Error $e) {
} catch (Exception|Error $e) {
Copy link
Contributor

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) {
Copy link
Contributor

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);

Copy link
Contributor Author

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

Copy link
Contributor

@kwizer15 kwizer15 Jul 7, 2025

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.

Copy link
Contributor Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fait


public static function checkSpaceLeft($_dir = null) {
if ($_dir == null) {
if ($_dir === null) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

@pifou25
Copy link
Contributor

pifou25 commented Jul 6, 2025

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:
https://sonarcloud.io/code?id=pifou25_jeedom-core&selected=pifou25_jeedom-core%3Acore%2Fclass%2Fjeedom.class.php

user::searchByOptions($key),
user::searchByRight($key),
];
foreach ($searchExpressions as $result) {
Copy link
Contributor Author

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


public static function checkSpaceLeft($_dir = null) {
if ($_dir == null) {
if ($_dir === null) {
Copy link
Contributor Author

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

$cron->halt();
} catch (Error $e) {
} catch (Throwable $e) {
``
Copy link
Contributor

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) {
Copy link
Contributor Author

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.

sleep(5);
$cron->halt();
} catch (Error $e) {
} catch (Exception|Error $e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (Exception|Error $e) {
} catch (\Throwable $e) {

user::searchByOptions($key),
user::searchByRight($key),
];
foreach ($searchExpressions as $result) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fait

}

public static function deadCmd() {
public static function deadCmd(): array {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function deadCmd(): array {
/**
* @return array
*/
public static function deadCmd() {

}

public static function listBackup() {
public static function listBackup(): array {
Copy link
Contributor

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é)

@Phpvarious
Copy link
Contributor

Bonjour,
La plupart du temps ce sont des tabulations qui sont faites en début de ligne, hors sur ces modifs ce sont de simples espaces.
Je ne sait pas si c'est un standard pour php, mais pour une meilleure visibilité, surtout sur des fonctions plus complexe, il faudrait garder le même type d'espacement.

@kwizer15
Copy link
Contributor

kwizer15 commented Jul 28, 2025

Bonjour,
La plupart du temps ce sont des tabulations qui sont faites en début de ligne, hors sur ces modifs ce sont de simples espaces.
Je ne sait pas si c'est un standard pour php, mais pour une meilleure visibilité, surtout sur des fonctions plus complexe, il faudrait garder le même type d'espacement.

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.

@Phpvarious
Copy link
Contributor

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.
Sans doute Github qui par défaut utilise le tabs en édition :

image

@kwizer15
Copy link
Contributor

kwizer15 commented Aug 5, 2025

Bonjour,
La plupart du temps ce sont des tabulations qui sont faites en début de ligne, hors sur ces modifs ce sont de simples espaces.
Je ne sait pas si c'est un standard pour php, mais pour une meilleure visibilité, surtout sur des fonctions plus complexe, il faudrait garder le même type d'espacement.

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants