code style fix

This commit is contained in:
odain
2025-11-14 10:41:47 +01:00
parent 2b1ecf15b4
commit 5b7a5e14a3
7 changed files with 29 additions and 37 deletions

View File

@@ -81,11 +81,11 @@ class MFException extends Exception
public function __construct($message = null, $code = 0, $oNode, $sXPath = null, $sExtraInfo = '', $oParentFallbackNode = null) public function __construct($message = null, $code = 0, $oNode, $sXPath = null, $sExtraInfo = '', $oParentFallbackNode = null)
{ {
$iSourceLineNumber = ModelFactory::GetXMLLineNumber($oNode); $iSourceLineNumber = ModelFactory::GetXMLLineNumber($oNode);
if ($iSourceLineNumber==0 && ! is_null($oParentFallbackNode)){ if ($iSourceLineNumber == 0 && ! is_null($oParentFallbackNode)) {
$iSourceLineNumber = ModelFactory::GetXMLLineNumber($oParentFallbackNode); $iSourceLineNumber = ModelFactory::GetXMLLineNumber($oParentFallbackNode);
} }
if (is_null($sXPath)){ if (is_null($sXPath)) {
$sXPath = DesignDocument::GetItopNodePath($oNode); $sXPath = DesignDocument::GetItopNodePath($oNode);
} }
@@ -2139,7 +2139,7 @@ EOF;
* @throws MFException * @throws MFException
* @throws \Exception * @throws \Exception
*/ */
public function RedefineChildNode(MFElement $oNode, $sSearchId = null, $oParentFallbackNode=null) public function RedefineChildNode(MFElement $oNode, $sSearchId = null, $oParentFallbackNode = null)
{ {
// First: cleanup any flag behind the new node, and eventually add trace data // First: cleanup any flag behind the new node, and eventually add trace data
$oNode->ApplyChanges(); $oNode->ApplyChanges();

View File

@@ -215,10 +215,8 @@ class ModuleDiscovery
ksort($aDependencies); ksort($aDependencies);
$aOrderedModules = []; $aOrderedModules = [];
$iLoopCount = 0; $iLoopCount = 0;
while(($iLoopCount < count($aModules)) && (count($aDependencies) > 0) ) while (($iLoopCount < count($aModules)) && (count($aDependencies) > 0)) {
{ foreach ($aDependencies as $sId => $aRemainingDeps) {
foreach($aDependencies as $sId => $aRemainingDeps)
{
$bDependenciesSolved = true; $bDependenciesSolved = true;
foreach ($aRemainingDeps as $sDepId) { foreach ($aRemainingDeps as $sDepId) {
if (!self::DependencyIsResolved($sDepId, $aOrderedModules, $aSelectedModules)) { if (!self::DependencyIsResolved($sDepId, $aOrderedModules, $aSelectedModules)) {
@@ -278,8 +276,7 @@ class ModuleDiscovery
$bResult = false; $bResult = false;
$aModuleVersions = []; $aModuleVersions = [];
// Separate the module names from their version for an easier comparison later // Separate the module names from their version for an easier comparison later
foreach($aOrderedModules as $sModuleId) foreach ($aOrderedModules as $sModuleId) {
{
list($sModuleName, $sVersion) = self::GetModuleName($sModuleId); list($sModuleName, $sVersion) = self::GetModuleName($sModuleId);
$aModuleVersions[$sModuleName] = $sVersion; $aModuleVersions[$sModuleName] = $sVersion;
} }
@@ -395,12 +392,10 @@ class ModuleDiscovery
if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches)) { if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches)) {
$sName = $aMatches[1]; $sName = $aMatches[1];
$sVersion = $aMatches[2]; $sVersion = $aMatches[2];
if ($sVersion === ""){ if ($sVersion === "") {
$sVersion = "1.0.0"; $sVersion = "1.0.0";
} }
} } else {
else
{
$sName = $sModuleId; $sName = $sModuleId;
$sVersion = "1.0.0"; $sVersion = "1.0.0";
} }

View File

@@ -1268,10 +1268,9 @@ JS;
*/ */
protected function AddCompatibilityFiles(string $sFileType, string $sMode): void protected function AddCompatibilityFiles(string $sFileType, string $sMode): void
{ {
$sConstantName = 'COMPATIBILITY_'.strtoupper($sMode).'_LINKED_'. ($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'STYLESHEETS' : 'SCRIPTS') .'_REL_PATH'; $sConstantName = 'COMPATIBILITY_'.strtoupper($sMode).'_LINKED_'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'STYLESHEETS' : 'SCRIPTS').'_REL_PATH';
$sMethodName = 'Link'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'Resource' : 'Script').'FromAppRoot'; $sMethodName = 'Link'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'Resource' : 'Script').'FromAppRoot';
// Add ancestors files // Add ancestors files
foreach (array_reverse(class_parents(static::class)) as $sParentClass) { foreach (array_reverse(class_parents(static::class)) as $sParentClass) {
foreach (constant($sParentClass.'::'.$sConstantName) as $sFile) { foreach (constant($sParentClass.'::'.$sConstantName) as $sFile) {

View File

@@ -139,15 +139,15 @@ class SessionHandler extends \SessionHandler
// - Data corruption (not a json / not an array / no previous creation_time key) // - Data corruption (not a json / not an array / no previous creation_time key)
$iCreationTime = time(); $iCreationTime = time();
$aJson=[]; $aJson = [];
if (! is_null($sPreviousFileVersionContent)) { if (! is_null($sPreviousFileVersionContent)) {
$aJson = json_decode($sPreviousFileVersionContent, true); $aJson = json_decode($sPreviousFileVersionContent, true);
if (is_array($aJson)){ if (is_array($aJson)) {
if (array_key_exists('creation_time', $aJson)) { if (array_key_exists('creation_time', $aJson)) {
$iCreationTime = $aJson['creation_time']; $iCreationTime = $aJson['creation_time'];
} }
} else { } else {
$aJson=[]; $aJson = [];
} }
} }
@@ -155,42 +155,42 @@ class SessionHandler extends \SessionHandler
'login_mode' => Session::Get('login_mode'), 'login_mode' => Session::Get('login_mode'),
'user_id' => $sUserId, 'user_id' => $sUserId,
'creation_time' => $iCreationTime, 'creation_time' => $iCreationTime,
'context' => implode('|', ContextTag::GetStack()) 'context' => implode('|', ContextTag::GetStack()),
]; ];
$oiSessionHandlerExtension = $this->GetSessionHandlerExtension(); $oiSessionHandlerExtension = $this->GetSessionHandlerExtension();
if (! is_null($oiSessionHandlerExtension)){ if (! is_null($oiSessionHandlerExtension)) {
$oiSessionHandlerExtension->CompleteSessionData($aJson, $aData); $oiSessionHandlerExtension->CompleteSessionData($aJson, $aData);
} }
return json_encode ( return json_encode(
$aData $aData
); );
} catch(Exception $e) { } catch (Exception $e) {
IssueLog::Error(__METHOD__, null, [ 'error' => $e->getMessage() ]); IssueLog::Error(__METHOD__, null, [ 'error' => $e->getMessage() ]);
} }
return null; return null;
} }
private function GetSessionHandlerExtension() : ?iSessionHandlerExtension private function GetSessionHandlerExtension(): ?iSessionHandlerExtension
{ {
$sSessionHandlerExtensionClass = utils::GetConfig()->Get('sessions_tracking.session_handler_extension'); $sSessionHandlerExtensionClass = utils::GetConfig()->Get('sessions_tracking.session_handler_extension');
if (strlen($sSessionHandlerExtensionClass) !=0){ if (strlen($sSessionHandlerExtensionClass) != 0) {
try{ try {
if (! class_exists($sSessionHandlerExtensionClass)){ if (! class_exists($sSessionHandlerExtensionClass)) {
throw new \Exception("Cannot find class"); throw new \Exception("Cannot find class");
} }
/** @var iSessionHandlerExtension $oSessionHandlerExtension */ /** @var iSessionHandlerExtension $oSessionHandlerExtension */
$oSessionHandlerExtension = new $sSessionHandlerExtensionClass; $oSessionHandlerExtension = new $sSessionHandlerExtensionClass();
if ($oSessionHandlerExtension instanceof iSessionHandlerExtension){ if ($oSessionHandlerExtension instanceof iSessionHandlerExtension) {
return $oSessionHandlerExtension; return $oSessionHandlerExtension;
} }
throw new \Exception("Not an instance of iSessionHandlerExtension"); throw new \Exception("Not an instance of iSessionHandlerExtension");
} catch(\Exception $e) { } catch (\Exception $e) {
IssueLog::Error(__METHOD__ . ': cannot instanciate iSessionHandlerExtension', null, ['sessions_tracking.session_handler_extension' => $sSessionHandlerExtensionClass]); IssueLog::Error(__METHOD__.': cannot instanciate iSessionHandlerExtension', null, ['sessions_tracking.session_handler_extension' => $sSessionHandlerExtensionClass]);
} }
} }

View File

@@ -2397,9 +2397,8 @@ class SynchroReplica extends DBObject implements iDisplay
} }
} }
// Really modified ? // Really modified ?
if ($oDestObj->IsModified()) if ($oDestObj->IsModified()) {
{ if (method_exists(get_class($oDestObj), "SetCurrentChange")) {
if(method_exists(get_class($oDestObj), "SetCurrentChange")){
$oDestObj::SetCurrentChange($oChange); $oDestObj::SetCurrentChange($oChange);
} }
$oDestObj->DBUpdate(); $oDestObj->DBUpdate();
@@ -2452,7 +2451,7 @@ class SynchroReplica extends DBObject implements iDisplay
} }
} }
if(method_exists(get_class($oDestObj), "SetCurrentChange")){ if (method_exists(get_class($oDestObj), "SetCurrentChange")) {
$oDestObj::SetCurrentChange($oChange); $oDestObj::SetCurrentChange($oChange);
} }
$iNew = $oDestObj->DBInsert(); $iNew = $oDestObj->DBInsert();

View File

@@ -1,6 +1,5 @@
<?php <?php
namespace Combodo\iTop\Test\UnitTest\Setup; namespace Combodo\iTop\Test\UnitTest\Setup;
use Combodo\iTop\Test\UnitTest\ItopTestCase; use Combodo\iTop\Test\UnitTest\ItopTestCase;

View File

@@ -325,4 +325,4 @@ class SessionHandlerTest extends ItopDataTestCase
$sContent = $this->GenerateSessionContent($oSessionHandler, json_encode(null)); $sContent = $this->GenerateSessionContent($oSessionHandler, json_encode(null));
$this->assertNotNull($sContent, "Call to CompleteSessionData should NOT fail due to Argument #1 (\$aJson) must be of type array, null given"); $this->assertNotNull($sContent, "Call to CompleteSessionData should NOT fail due to Argument #1 (\$aJson) must be of type array, null given");
} }
} }