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

This commit is contained in:
odain
2025-11-07 20:39:38 +01:00
parent 7681c157ec
commit b0a792afab
369 changed files with 22041 additions and 26866 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
*
@@ -19,7 +20,6 @@
namespace Combodo\iTop\Application\UI\Base\Layout\ActivityPanel;
use appUserPreferences;
use AttributeDateTime;
use cmdbAbstractObject;
@@ -102,7 +102,6 @@ class ActivityPanel extends UIBlock
/** @var bool */
protected $bPrefilterEditsOnLogs;
/**
* ActivityPanel constructor.
*
@@ -166,7 +165,6 @@ class ActivityPanel extends UIBlock
$this->AddCaseLogTab($sCaseLogAttCode);
}
return $this;
}
@@ -185,7 +183,8 @@ class ActivityPanel extends UIBlock
*
* @return int
*/
public function GetObjectId(): int {
public function GetObjectId(): int
{
return $this->oObject->GetKey();
}
@@ -194,7 +193,8 @@ class ActivityPanel extends UIBlock
*
* @return string
*/
public function GetObjectClass(): string {
public function GetObjectClass(): string
{
return get_class($this->oObject);
}
@@ -210,7 +210,7 @@ class ActivityPanel extends UIBlock
public function SetObjectMode(string $sMode)
{
// Consistency check
if(!in_array($sMode, cmdbAbstractObject::EnumDisplayModes())){
if (!in_array($sMode, cmdbAbstractObject::EnumDisplayModes())) {
throw new Exception("Activity panel: Object mode '$sMode' not allowed, should be either ".implode(' / ', cmdbAbstractObject::EnumDisplayModes()));
}
@@ -300,8 +300,7 @@ class ActivityPanel extends UIBlock
// Reset entries
$this->aEntries = [];
foreach ($aEntries as $oEntry)
{
foreach ($aEntries as $oEntry) {
$this->AddEntry($oEntry);
}
@@ -315,8 +314,7 @@ class ActivityPanel extends UIBlock
*/
public function GetEntries(): array
{
if ($this->bAreEntriesSorted === false)
{
if ($this->bAreEntriesSorted === false) {
$this->SortEntries();
}
@@ -335,18 +333,15 @@ class ActivityPanel extends UIBlock
$aCurrentGroup = ['author_login' => null, 'origin' => null, 'entries' => []];
$aPreviousEntryData = ['author_login' => null, 'origin' => null];
foreach($this->GetEntries() as $sId => $oEntry)
{
foreach ($this->GetEntries() as $sId => $oEntry) {
// New entry data
$sAuthorLogin = $oEntry->GetAuthorLogin();
$sOrigin = $oEntry->GetOrigin();
// Check if it's time to change of group
if(($sAuthorLogin !== $aPreviousEntryData['author_login']) || ($sOrigin !== $aPreviousEntryData['origin']))
{
if (($sAuthorLogin !== $aPreviousEntryData['author_login']) || ($sOrigin !== $aPreviousEntryData['origin'])) {
// Flush current group if necessary
if(empty($aCurrentGroup['entries']) === false)
{
if (empty($aCurrentGroup['entries']) === false) {
$aGroupedEntries[] = $aCurrentGroup;
}
@@ -359,8 +354,7 @@ class ActivityPanel extends UIBlock
}
// Flush last group
if(empty($aCurrentGroup['entries']) === false)
{
if (empty($aCurrentGroup['entries']) === false) {
$aGroupedEntries[] = $aCurrentGroup;
}
@@ -374,16 +368,14 @@ class ActivityPanel extends UIBlock
*/
protected function SortEntries()
{
if(count($this->aEntries) > 1)
{
uasort($this->aEntries, function($oEntryA, $oEntryB){
if (count($this->aEntries) > 1) {
uasort($this->aEntries, function ($oEntryA, $oEntryB) {
/** @var ActivityEntry $oEntryA */
/** @var ActivityEntry $oEntryB */
$sDateTimeA = $oEntryA->GetRawDateTime();
$sDateTimeB = $oEntryB->GetRawDateTime();
if ($sDateTimeA === $sDateTimeB)
{
if ($sDateTimeA === $sDateTimeB) {
return 0;
}
@@ -409,14 +401,12 @@ class ActivityPanel extends UIBlock
$this->bAreEntriesSorted = false;
// Add case log to the panel and update metadata when necessary
if ($oEntry instanceof CaseLogEntry)
{
if ($oEntry instanceof CaseLogEntry) {
$sCaseLogAttCode = $oEntry->GetAttCode();
$sAuthorLogin = $oEntry->GetAuthorLogin();
// Initialize case log metadata
if ($this->HasCaseLogTab($sCaseLogAttCode) === false)
{
if ($this->HasCaseLogTab($sCaseLogAttCode) === false) {
$this->AddCaseLogTab($sCaseLogAttCode);
}
@@ -427,8 +417,7 @@ class ActivityPanel extends UIBlock
// - Message count
$this->aCaseLogs[$sCaseLogAttCode]['total_messages_count']++;
// - Authors
if(array_key_exists($sAuthorLogin, $this->aCaseLogs[$sCaseLogAttCode]['authors']) === false)
{
if (array_key_exists($sAuthorLogin, $this->aCaseLogs[$sCaseLogAttCode]['authors']) === false) {
$this->aCaseLogs[$sCaseLogAttCode]['authors'][$sAuthorLogin] = [
'messages_count' => 0,
];
@@ -449,12 +438,10 @@ class ActivityPanel extends UIBlock
*/
public function RemoveEntry(string $sEntryId)
{
if (array_key_exists($sEntryId, $this->aEntries))
{
if (array_key_exists($sEntryId, $this->aEntries)) {
// Recompute case logs metadata only if necessary
$oEntry = $this->aEntries[$sEntryId];
if ($oEntry instanceof CaseLogEntry)
{
if ($oEntry instanceof CaseLogEntry) {
$sCaseLogAttCode = $oEntry->GetAttCode();
$sAuthorLogin = $oEntry->GetAuthorLogin();
@@ -463,8 +450,7 @@ class ActivityPanel extends UIBlock
$this->aCaseLogs[$sCaseLogAttCode]['total_messages_count']--;
// - Authors
$this->aCaseLogs[$sCaseLogAttCode]['authors'][$sAuthorLogin]['messages_count']--;
if($this->aCaseLogs[$sCaseLogAttCode]['authors'][$sAuthorLogin]['messages_count'] === 0)
{
if ($this->aCaseLogs[$sCaseLogAttCode]['authors'][$sAuthorLogin]['messages_count'] === 0) {
unset($this->aCaseLogs[$sCaseLogAttCode]['authors'][$sAuthorLogin]);
}
}
@@ -563,8 +549,7 @@ class ActivityPanel extends UIBlock
protected function AddCaseLogTab(string $sAttCode)
{
// Add case log only if not already existing
if (!array_key_exists($sAttCode, $this->aCaseLogs))
{
if (!array_key_exists($sAttCode, $this->aCaseLogs)) {
$iFlags = ($this->GetObject()->IsNew()) ? $this->GetObject()->GetInitialStateAttributeFlags($sAttCode) : $this->GetObject()->GetAttributeFlags($sAttCode);
$bIsHidden = (OPT_ATT_HIDDEN === ($iFlags & OPT_ATT_HIDDEN));
$bIsReadOnly = (OPT_ATT_READONLY === ($iFlags & OPT_ATT_READONLY));
@@ -614,8 +599,7 @@ class ActivityPanel extends UIBlock
*/
protected function RemoveCaseLogTab(string $sAttCode)
{
if (array_key_exists($sAttCode, $this->aCaseLogs))
{
if (array_key_exists($sAttCode, $this->aCaseLogs)) {
unset($this->aCaseLogs[$sAttCode]);
}
@@ -693,7 +677,7 @@ class ActivityPanel extends UIBlock
*/
public function SetCaseLogTabEntryForm(string $sCaseLogId, CaseLogEntryForm $oCaseLogEntryForm)
{
if ($this->HasCaseLogTab($sCaseLogId)){
if ($this->HasCaseLogTab($sCaseLogId)) {
$this->aCaseLogTabsEntryForms[$sCaseLogId] = $oCaseLogEntryForm;
}
@@ -743,8 +727,7 @@ class ActivityPanel extends UIBlock
foreach ($this->GetCaseLogTabsEntryForms() as $oCaseLogEntryForm) {
if ($oCaseLogEntryForm->IsSubmitAutonomous()) {
$iAutonomousSubmission++;
}
else {
} else {
$iBridgedSubmissions++;
}
}
@@ -948,7 +931,7 @@ class ActivityPanel extends UIBlock
*/
public function GetSubBlocks(): array
{
$aSubBlocks = array();
$aSubBlocks = [];
foreach ($this->GetCaseLogTabsEntryForms() as $sCaseLogId => $oCaseLogEntryForm) {
$aSubBlocks[$oCaseLogEntryForm->GetId()] = $oCaseLogEntryForm;
@@ -967,4 +950,4 @@ class ActivityPanel extends UIBlock
{
return \UserRights::IsActionAllowed($this->GetObjectClass(), UR_ACTION_MODIFY);
}
}
}