N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (c) 2010-2024 Combodo SAS
*
@@ -46,11 +47,9 @@ use utils;
*/
class DesignDocument extends DOMDocument
{
/** To fix DOMNode::getLineNo() ref https://www.php.net/manual/en/domnode.getlineno.php */
public const XML_PARSE_BIG_LINES = 4194304;
/**
* @throws \Exception
*/
@@ -135,13 +134,10 @@ class DesignDocument extends DOMDocument
*/
public static function XPathQuote($sValue)
{
if (strpos($sValue, '"') !== false)
{
if (strpos($sValue, '"') !== false) {
$aParts = explode('"', $sValue);
$sRet = 'concat("'.implode('", \'"\', "', $aParts).'")';
}
else
{
} else {
$sRet = '"'.$sValue.'"';
}
return $sRet;
@@ -156,12 +152,9 @@ class DesignDocument extends DOMDocument
public function GetNodes($sXPath, $oContextNode = null)
{
$oXPath = new \DOMXPath($this);
if (is_null($oContextNode))
{
if (is_null($oContextNode)) {
$oResult = $oXPath->query($sXPath);
}
else
{
} else {
$oResult = $oXPath->query($sXPath, $oContextNode);
}
return $oResult;
@@ -174,8 +167,12 @@ class DesignDocument extends DOMDocument
*/
public static function GetItopNodePath($oNode)
{
if ($oNode instanceof \DOMDocument) return '';
if (is_null($oNode)) return '';
if ($oNode instanceof \DOMDocument) {
return '';
}
if (is_null($oNode)) {
return '';
}
$sId = $oNode->getAttribute('id');
$sNodeDesc = ($sId != '') ? $oNode->nodeName.'['.$sId.']' : $oNode->nodeName;
@@ -303,16 +300,13 @@ class DesignElement extends \DOMElement
public function GetUniqueElement($sTagName, $bMustExist = true)
{
$oNode = null;
foreach($this->childNodes as $oChildNode)
{
if ($oChildNode->nodeName == $sTagName)
{
foreach ($this->childNodes as $oChildNode) {
if ($oChildNode->nodeName == $sTagName) {
$oNode = $oChildNode;
break;
}
}
if ($bMustExist && is_null($oNode))
{
if ($bMustExist && is_null($oNode)) {
throw new DOMFormatException('Missing unique tag: '.$sTagName);
}
return $oNode;
@@ -337,20 +331,17 @@ class DesignElement extends \DOMElement
public function GetText($sDefault = null)
{
$sText = null;
foreach($this->childNodes as $oChildNode)
{
if ($oChildNode instanceof \DOMText)
{
if (is_null($sText)) $sText = '';
foreach ($this->childNodes as $oChildNode) {
if ($oChildNode instanceof \DOMText) {
if (is_null($sText)) {
$sText = '';
}
$sText .= $oChildNode->wholeText;
}
}
if (is_null($sText))
{
if (is_null($sText)) {
return $sDefault;
}
else
{
} else {
return $sText;
}
}
@@ -367,8 +358,7 @@ class DesignElement extends \DOMElement
public function GetChildText($sTagName, $sDefault = null)
{
$sRet = $sDefault;
if ($oChild = $this->GetOptionalElement($sTagName))
{
if ($oChild = $this->GetOptionalElement($sTagName)) {
$sRet = $oChild->GetText($sDefault);
}
return $sRet;
@@ -427,7 +417,6 @@ class DesignElement extends \DOMElement
return self::_FindNode($this, $oRefNode, $sSearchId);
}
/**
* Find the child node matching the given node.
* UNSAFE: may return nodes marked as _alteration="removed"
@@ -482,31 +471,24 @@ class DesignElement extends \DOMElement
*/
public static function _FindNodes(DOMNode $oParent, DesignElement $oRefNode, string $sSearchId = null)
{
if ($oParent instanceof DOMDocument)
{
if ($oParent instanceof DOMDocument) {
$oDoc = $oParent->firstChild->ownerDocument;
$oRoot = $oParent;
}
else
{
} else {
$oDoc = $oParent->ownerDocument;
$oRoot = $oParent;
}
$oXPath = new DOMXPath($oDoc);
if ($oRefNode->hasAttribute('id'))
{
if ($oRefNode->hasAttribute('id')) {
// Find the elements having the same tag name and id
if (!$sSearchId)
{
if (!$sSearchId) {
$sSearchId = $oRefNode->getAttribute('id');
}
$sXPath = './'.$oRefNode->tagName."[@id='$sSearchId']";
$oRes = $oXPath->query($sXPath, $oRoot);
}
else
{
} else {
// Get the elements having the same tag name
$sXPath = './'.$oRefNode->tagName;