Skip to content

Commit 8597f51

Browse files
committed
Fix some sonarcloud issues
1 parent b0cb59b commit 8597f51

11 files changed

+131
-138
lines changed

src/Ajax/CmdAjax.php

+22-23
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use NextDom\Enums\ActionRight;
2121
use NextDom\Enums\AjaxParams;
22+
use NextDom\Enums\CmdConfigKey;
2223
use NextDom\Enums\CmdType;
2324
use NextDom\Enums\CmdViewType;
2425
use NextDom\Enums\Common;
@@ -57,7 +58,6 @@ class CmdAjax extends BaseAjax
5758
* Get one or more command(s) HTML render
5859
*
5960
* @throws CoreException
60-
* @throws \ReflectionException
6161
*/
6262
public function toHtml()
6363
{
@@ -71,18 +71,18 @@ public function toHtml()
7171
}
7272
$result[$cmd->getId()] = [
7373
'html' => $cmd->toHtml($value[Common::VERSION]),
74-
'id' => $cmd->getId(),
74+
AjaxParams::ID => $cmd->getId(),
7575
];
7676
}
7777
$this->ajax->success($result);
7878
} else {
7979
// Render one command
8080
$cmd = CmdManager::byId(Utils::init(AjaxParams::ID));
8181
if (!is_object($cmd)) {
82-
throw new CoreException(__('Commande inconnue - Vérifiez l\'id'));
82+
throw new CoreException(__('Commande inconnue - Vérifiez l\'ID'));
8383
}
8484
$result = [];
85-
$result['id'] = $cmd->getId();
85+
$result[AjaxParams::ID] = $cmd->getId();
8686
$result['html'] = $cmd->toHtml(Utils::init(AjaxParams::VERSION), Utils::init(AjaxParams::OPTION), Utils::init('cmdColor', null));
8787
$this->ajax->success($result);
8888
}
@@ -92,7 +92,6 @@ public function toHtml()
9292
* Execute a command
9393
*
9494
* @throws CoreException
95-
* @throws \ReflectionException
9695
*/
9796
public function execCmd()
9897
{
@@ -306,7 +305,7 @@ public function save()
306305
{
307306
AuthentificationHelper::isConnectedAsAdminOrFail();
308307
$cmdAjaxData = NextDomHelper::fromHumanReadable(json_decode(Utils::init(NextDomObj::CMD), true));
309-
$cmd = CmdManager::byId($cmdAjaxData['id']);
308+
$cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]);
310309
if (!is_object($cmd)) {
311310
$cmd = new Cmd();
312311
}
@@ -326,7 +325,7 @@ public function multiSave()
326325
AuthentificationHelper::isConnectedAsAdminOrFail();
327326
$cmds = json_decode(Utils::init(NextDomObj::CMD), true);
328327
foreach ($cmds as $cmdAjaxData) {
329-
$cmd = CmdManager::byId($cmdAjaxData['id']);
328+
$cmd = CmdManager::byId($cmdAjaxData[AjaxParams::ID]);
330329
if (!is_object($cmd)) {
331330
continue;
332331
}
@@ -419,8 +418,8 @@ public function getHistory()
419418
if ($dateStart !== '') {
420419
$dateStart = Utils::init(AjaxParams::DATE_START, date(DateFormat::FULL_DAY, strtotime(ConfigManager::byKey('history::defautShowPeriod') . ' ' . date(DateFormat::FULL_DAY))));
421420
}
422-
$result['maxValue'] = '';
423-
$result['minValue'] = '';
421+
$result[CmdConfigKey::MAX_VALUE] = '';
422+
$result[CmdConfigKey::MIN_VALUE] = '';
424423
if ($dateStart === null) {
425424
$result['dateStart'] = '';
426425
} else {
@@ -482,11 +481,11 @@ public function getHistory()
482481
}
483482
$infoHistory[] = $value;
484483
if (!$NEXTDOM_INTERNAL_CONFIG[NextDomObj::CMD][Common::TYPE][Common::INFO][Common::SUBTYPE][$cmd->getSubType()][Common::IS_HISTORIZED][Common::TIMELINE_ONLY]) {
485-
if (($value !== null && $value > $result['maxValue']) || $result['maxValue'] == '') {
486-
$result['maxValue'] = round($value, 1);
484+
if (($value !== null && $value > $result[CmdConfigKey::MAX_VALUE]) || $result[CmdConfigKey::MAX_VALUE] == '') {
485+
$result[CmdConfigKey::MAX_VALUE] = round($value, 1);
487486
}
488-
if (($value !== null && $value < $result['minValue']) || $result['minValue'] == '') {
489-
$result['minValue'] = round($value, 1);
487+
if (($value !== null && $value < $result[CmdConfigKey::MIN_VALUE]) || $result[CmdConfigKey::MIN_VALUE] == '') {
488+
$result[CmdConfigKey::MIN_VALUE] = round($value, 1);
490489
}
491490
}
492491
$data[] = $infoHistory;
@@ -498,18 +497,18 @@ public function getHistory()
498497
$infoHistory = [];
499498
$infoHistory[] = floatval($datetime) * 1000;
500499
$infoHistory[] = ($value === null) ? null : floatval($value);
501-
if ($value > $result['maxValue'] || $result['maxValue'] == '') {
502-
$result['maxValue'] = round($value, 1);
500+
if ($value > $result[CmdConfigKey::MAX_VALUE] || $result[CmdConfigKey::MAX_VALUE] == '') {
501+
$result[CmdConfigKey::MAX_VALUE] = round($value, 1);
503502
}
504-
if ($value < $result['minValue'] || $result['minValue'] == '') {
505-
$result['minValue'] = round($value, 1);
503+
if ($value < $result[CmdConfigKey::MIN_VALUE] || $result[CmdConfigKey::MIN_VALUE] == '') {
504+
$result[CmdConfigKey::MIN_VALUE] = round($value, 1);
506505
}
507506
$data[] = $infoHistory;
508507
}
509508
}
510509
$result['cmd_name'] = $cmdId;
511510
$result['history_name'] = $cmdId;
512-
$result['unite'] = Utils::init('unite');
511+
$result[Common::UNITE] = Utils::init(Common::UNITE);
513512
}
514513
$result['data'] = $data;
515514
$this->ajax->success($result);
@@ -544,27 +543,27 @@ public function setOrder()
544543
$cmds = json_decode(Utils::init('cmds'), true);
545544
$eqLogics = [];
546545
foreach ($cmds as $cmdJsonData) {
547-
if (!isset($cmdJsonData['id']) || trim($cmdJsonData['id']) == '') {
546+
if (!isset($cmdJsonData[AjaxParams::ID]) || trim($cmdJsonData[AjaxParams::ID]) == '') {
548547
continue;
549548
}
550-
$cmd = CmdManager::byId($cmdJsonData['id']);
549+
$cmd = CmdManager::byId($cmdJsonData[AjaxParams::ID]);
551550
if (!is_object($cmd)) {
552551
continue;
553552
}
554553
if ($cmd->getOrder() != $cmdJsonData['order']) {
555554
$cmd->setOrder($cmdJsonData['order']);
556555
$cmd->save();
557556
}
558-
if (isset($cmdJsonData['line']) && isset($cmdJsonData['column'])) {
557+
if (isset($cmdJsonData['line']) && isset($cmdJsonData[Common::COLUMN])) {
559558
$renderVersion = Utils::init(AjaxParams::VERSION, CmdViewType::DASHBOARD);
560559
if (!isset($eqLogics[$cmd->getEqLogic_id()])) {
561560
$eqLogics[$cmd->getEqLogic_id()] = [NextDomObj::EQLOGIC => $cmd->getEqLogic(), Common::CHANGED => false];
562561
}
563562
$layoutDisplay = 'layout::' . $renderVersion . '::table::cmd::' . $cmd->getId();
564563
if ($eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::line') != $cmdJsonData['line']
565-
|| $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData['column']) {
564+
|| $eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->getDisplay($layoutDisplay . '::column') != $cmdJsonData[Common::COLUMN]) {
566565
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::line', $cmdJsonData['line']);
567-
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData['column']);
566+
$eqLogics[$cmd->getEqLogic_id()][NextDomObj::EQLOGIC]->setDisplay($layoutDisplay . '::column', $cmdJsonData[Common::COLUMN]);
568567
$eqLogics[$cmd->getEqLogic_id()][Common::CHANGED] = true;
569568
}
570569
}

src/Ajax/EqLogicAjax.php

+20-18
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
use NextDom\Helpers\AuthentificationHelper;
2727
use NextDom\Helpers\NextDomHelper;
2828
use NextDom\Helpers\Utils;
29+
use NextDom\Managers\CmdManager;
2930
use NextDom\Managers\EqLogicManager;
3031
use NextDom\Managers\JeeObjectManager;
3132
use NextDom\Model\Entity\Cmd;
33+
use NextDom\Model\Entity\EqLogic;
3234

3335
/**
3436
* Class EqLogicAjax
@@ -52,7 +54,7 @@ public function getEqLogicObject()
5254
foreach ($linkedObject->getEqLogic() as $eqLogic) {
5355
if ($eqLogic->isVisible()) {
5456
$info_eqLogic = [];
55-
$info_eqLogic[Common::ID] = $eqLogic->getId();
57+
$info_eqLogic[AjaxParams::ID] = $eqLogic->getId();
5658
$info_eqLogic[Common::TYPE] = $eqLogic->getEqType_name();
5759
$info_eqLogic[Common::OBJECT_ID] = $eqLogic->getObject_id();
5860
$info_eqLogic[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION));
@@ -84,7 +86,7 @@ public function toHtml()
8486
throw new CoreException(__('Pas de version indiqué pour le rendu HTML'));
8587
}
8688
$result[$eqLogic->getId()] = [
87-
Common::ID => $eqLogic->getId(),
89+
AjaxParams::ID => $eqLogic->getId(),
8890
Common::TYPE => $eqLogic->getEqType_name(),
8991
Common::OBJECT_ID => $eqLogic->getObject_id(),
9092
Common::HTML => $eqLogic->toHtml($eqLogicData[AjaxParams::VERSION]),
@@ -97,7 +99,7 @@ public function toHtml()
9799
throw new CoreException(__('Eqlogic inconnu. Vérifiez l\'ID'));
98100
}
99101
$eqLogicInfo = [];
100-
$eqLogicInfo[Common::ID] = $eqLogic->getId();
102+
$eqLogicInfo[AjaxParams::ID] = $eqLogic->getId();
101103
$eqLogicInfo[Common::TYPE] = $eqLogic->getEqType_name();
102104
$eqLogicInfo[Common::OBJECT_ID] = $eqLogic->getObject_id();
103105
$eqLogicInfo[Common::HTML] = $eqLogic->toHtml(Utils::init(AjaxParams::VERSION));
@@ -114,7 +116,7 @@ public function htmlAlert()
114116
}
115117
$result[$eqLogic->getId()] = [
116118
Common::HTML => $eqLogic->toHtml(Utils::init(AjaxParams::VERSION)),
117-
Common::ID => $eqLogic->getId(),
119+
AjaxParams::ID => $eqLogic->getId(),
118120
Common::TYPE => $eqLogic->getEqType_name(),
119121
Common::OBJECT_ID => $eqLogic->getObject_id(),
120122
];
@@ -145,7 +147,7 @@ public function htmlBattery()
145147
foreach ($list as $eqLogic) {
146148
$result[] = [
147149
Common::HTML => $eqLogic->batteryWidget(Utils::init(AjaxParams::VERSION)),
148-
Common::ID => $eqLogic->getId(),
150+
AjaxParams::ID => $eqLogic->getId(),
149151
Common::TYPE => $eqLogic->getEqType_name(),
150152
Common::OBJECT_ID => $eqLogic->getObject_id(),
151153
];
@@ -197,7 +199,7 @@ public function listByTypeAndCmdType()
197199
$eqLogicList = EqLogicManager::listByTypeAndCmdType(Utils::init(AjaxParams::TYPE), Utils::init(AjaxParams::TYPE_CMD), Utils::init(AjaxParams::SUB_TYPE_CMD));
198200
$result = [];
199201
foreach ($eqLogicList as $eqLogic) {
200-
$eqLogic = EqLogicManager::byId($eqLogic[Common::ID]);
202+
$eqLogic = EqLogicManager::byId($eqLogic[AjaxParams::ID]);
201203
$info[NextDomObj::EQLOGIC] = Utils::o2a($eqLogic);
202204
$info[NextDomObj::OBJECT] = ['name' => 'Aucun'];
203205
if (is_object($eqLogic)) {
@@ -230,10 +232,10 @@ public function setOrder()
230232
{
231233
$eqLogics = json_decode(Utils::init('eqLogics'), true);
232234
foreach ($eqLogics as $eqLogic_json) {
233-
if (!isset($eqLogic_json[Common::ID]) || trim($eqLogic_json[Common::ID]) == '') {
235+
if (!isset($eqLogic_json[AjaxParams::ID]) || trim($eqLogic_json[AjaxParams::ID]) == '') {
234236
continue;
235237
}
236-
$eqLogic = EqLogicManager::byId($eqLogic_json[Common::ID]);
238+
$eqLogic = EqLogicManager::byId($eqLogic_json[AjaxParams::ID]);
237239
if (!is_object($eqLogic)) {
238240
continue;
239241
}
@@ -297,9 +299,9 @@ public function simpleSave()
297299
{
298300
AuthentificationHelper::isConnectedAsAdminOrFail();
299301
$eqLogicSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true);
300-
$eqLogic = EqLogicManager::byId($eqLogicSave[Common::ID]);
302+
$eqLogic = EqLogicManager::byId($eqLogicSave[AjaxParams::ID]);
301303
if (!is_object($eqLogic)) {
302-
throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[Common::ID]);
304+
throw new CoreException(__('EqLogic inconnu. Vérifiez l\'ID ') . $eqLogicSave[AjaxParams::ID]);
303305
}
304306

305307
if (!$eqLogic->hasRight(ActionRight::WRITE)) {
@@ -355,22 +357,22 @@ public function get()
355357
public function save()
356358
{
357359
AuthentificationHelper::isConnectedAsAdminOrFail();
358-
359360
$eqLogicsSave = json_decode(Utils::init(NextDomObj::EQLOGIC), true);
360361

361362
foreach ($eqLogicsSave as $eqLogicSave) {
362363
try {
363364
if (!is_array($eqLogicSave)) {
364365
throw new CoreException(__('Informations reçues incorrectes'));
365366
}
366-
$typeEqLogic = Utils::init(AjaxParams::TYPE);
367+
$typeEqLogic = Utils::initStr(AjaxParams::TYPE);
367368
$typeCmd = $typeEqLogic . NextDomObj::CMD;
368369
if ($typeEqLogic == '' || !class_exists($typeEqLogic) || !class_exists($typeCmd)) {
369370
throw new CoreException(__('Type incorrect, (classe commande inexistante)') . $typeCmd);
370371
}
372+
/** @var EqLogic $eqLogic */
371373
$eqLogic = null;
372-
if (isset($eqLogicSave[Common::ID])) {
373-
$eqLogic = $typeEqLogic::byId($eqLogicSave[Common::ID]);
374+
if (isset($eqLogicSave[AjaxParams::ID])) {
375+
$eqLogic = $typeEqLogic::byId($eqLogicSave[AjaxParams::ID]);
374376
}
375377
if (!is_object($eqLogic)) {
376378
$eqLogic = new $typeEqLogic();
@@ -385,16 +387,16 @@ public function save()
385387
}
386388
$eqLogicSave = NextDomHelper::fromHumanReadable($eqLogicSave);
387389
Utils::a2o($eqLogic, $eqLogicSave);
388-
$dbList = $typeCmd::byEqLogicId($eqLogic->getId());
390+
$dbList = CmdManager::byEqLogicId($eqLogic->getId());
389391
$eqLogic->save();
390392
$enableList = [];
391393

392394
if (isset($eqLogicSave[NextDomObj::CMD])) {
393395
$cmd_order = 0;
394396
foreach ($eqLogicSave[NextDomObj::CMD] as $cmd_info) {
395397
$cmd = null;
396-
if (isset($cmd_info[Common::ID])) {
397-
$cmd = $typeCmd::byId($cmd_info[Common::ID]);
398+
if (isset($cmd_info[AjaxParams::ID])) {
399+
$cmd = CmdManager::byId($cmd_info[AjaxParams::ID]);
398400
}
399401
if (!is_object($cmd)) {
400402
$cmd = new $typeCmd();
@@ -415,6 +417,7 @@ public function save()
415417
if (method_exists($eqLogic, 'postAjax')) {
416418
$eqLogic->postAjax();
417419
}
420+
$this->ajax->success(Utils::o2a($eqLogic));
418421
} catch (\Exception $e) {
419422
if (strpos($e->getMessage(), '[MySQL] Error code : 23000') !== false) {
420423
if ($e->getTrace()[2]['class'] == NextDomObj::EQLOGIC) {
@@ -426,7 +429,6 @@ public function save()
426429
throw new CoreException($e->getMessage());
427430
}
428431
}
429-
$this->ajax->success(Utils::o2a($eqLogic));
430432
}
431433
$this->ajax->success(null);
432434
}

src/Ajax/InteractAjax.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
namespace NextDom\Ajax;
1919

2020
use NextDom\Enums\AjaxParams;
21+
use NextDom\Enums\Common;
22+
use NextDom\Enums\SQLField;
2123
use NextDom\Enums\UserRight;
2224
use NextDom\Exceptions\CoreException;
2325
use NextDom\Helpers\NextDomHelper;
@@ -42,18 +44,18 @@ public function all()
4244
$results = Utils::o2a(InteractDefManager::all());
4345
foreach ($results as &$result) {
4446
// @TODO TOus sélectionnés dans tous les cas
45-
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
46-
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
47-
if ($result['link_type'] == 'cmd' && $result['link_id'] != '') {
48-
$link_id = '';
49-
foreach (explode('&&', $result['link_id']) as $cmd_id) {
47+
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
48+
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
49+
if ($result[SQLField::LINK_TYPE] == 'cmd' && $result[SQLField::LINK_ID] != '') {
50+
$linkId = '';
51+
foreach (explode('&&', $result[SQLField::LINK_ID]) as $cmd_id) {
5052
$cmd = CmdManager::byId($cmd_id);
5153
if (is_object($cmd)) {
52-
$link_id .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && ');
54+
$linkId .= CmdManager::cmdToHumanReadable('#' . $cmd->getId() . '# && ');
5355
}
5456

5557
}
56-
$result['link_id'] = trim(trim($link_id), '&&');
58+
$result[SQLField::LINK_ID] = trim(trim($linkId), '&&');
5759
}
5860
}
5961
$this->ajax->success($results);
@@ -62,16 +64,16 @@ public function all()
6264
public function byId()
6365
{
6466
$result = Utils::o2a(InteractDefManager::byId(Utils::init(AjaxParams::ID)));
65-
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
66-
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result['id']));
67+
$result['nbInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
68+
$result['nbEnableInteractQuery'] = count(InteractQueryManager::byInteractDefId($result[AjaxParams::ID]));
6769
$this->ajax->success(NextDomHelper::toHumanReadable($result));
6870
}
6971

7072
public function save()
7173
{
7274
$interact_json = NextDomHelper::fromHumanReadable(json_decode(Utils::init('interact'), true));
73-
if (isset($interact_json['id'])) {
74-
$interact = InteractDefManager::byId($interact_json['id']);
75+
if (isset($interact_json[AjaxParams::ID])) {
76+
$interact = InteractDefManager::byId($interact_json[AjaxParams::ID]);
7577
}
7678
if (!isset($interact) || !is_object($interact)) {
7779
$interact = new InteractDef();

src/Ajax/ListenerAjax.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace NextDom\Ajax;
1919

2020
use NextDom\Enums\AjaxParams;
21+
use NextDom\Enums\Common;
2122
use NextDom\Enums\UserRight;
2223
use NextDom\Exceptions\CoreException;
2324
use NextDom\Helpers\NextDomHelper;
@@ -54,11 +55,11 @@ public function all()
5455
{
5556
$listeners = Utils::o2a(ListenerManager::all());
5657
foreach ($listeners as &$listener) {
57-
$listener['event_str'] = '';
58-
foreach ($listener['event'] as $event) {
59-
$listener['event_str'] .= $event . ',';
58+
$listener[AjaxParams::EVENT_STR] = '';
59+
foreach ($listener[Common::EVENT] as $event) {
60+
$listener[AjaxParams::EVENT_STR] .= $event . ',';
6061
}
61-
$listener['event_str'] = NextDomHelper::toHumanReadable(trim($listener['event_str'], ','));
62+
$listener[AjaxParams::EVENT_STR] = NextDomHelper::toHumanReadable(trim($listener[AjaxParams::EVENT_STR], ','));
6263
}
6364
$this->ajax->success($listeners);
6465
}

0 commit comments

Comments
 (0)