setup: phpstan level 2

setup: phpstan level 2
This commit is contained in:
odain
2026-01-13 16:29:16 +01:00
parent 13c18b611c
commit 0582ae1038
9 changed files with 30 additions and 23 deletions

View File

@@ -6,7 +6,6 @@ class AnalyzeInstallation
{
private static AnalyzeInstallation $oInstance;
private ?array $aAvailableModules = null;
private ?array $aSelectInstall = null;
protected function __construct()
{
@@ -23,7 +22,7 @@ class AnalyzeInstallation
final public static function SetInstance(?AnalyzeInstallation $oInstance): void
{
static::$oInstance = $oInstance;
self::$oInstance = $oInstance;
}
/**

View File

@@ -19,7 +19,7 @@ class ModuleInstallationRepository
final public static function SetInstance(?ModuleInstallationRepository $oInstance): void
{
static::$oInstance = $oInstance;
self::$oInstance = $oInstance;
}
private ?array $aSelectInstall = null;
@@ -205,8 +205,8 @@ SQL;
$oSet->SetLimit($iOffset + 1);
$iParentId = 0;
/** @var \DBObject $oModuleInstallation */
while ($oModuleInstallation = $oSet->Fetch()) {
while (!is_null($oModuleInstallation = $oSet->Fetch())) {
/** @var \DBObject $oModuleInstallation */
if ($iOffset == 0) {
$iParentId = $oModuleInstallation->Get('id');
break;

View File

@@ -63,17 +63,17 @@ class DependencyExpression
private static function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
{
if (!isset(static::$oPhpExpressionEvaluator)) {
static::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
if (!isset(self::$oPhpExpressionEvaluator)) {
self::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
}
return static::$oPhpExpressionEvaluator;
return self::$oPhpExpressionEvaluator;
}
/**
* Return module names potentially required by current dependency
*
* @return array
* @return array<string>
*/
public function GetRemainingModuleNamesToResolve(): array
{

View File

@@ -114,7 +114,7 @@ class Module
}
/**
* @return array: list of unique module names
* @return array<string> list of unique module names
*/
public function GetUnresolvedDependencyModuleNames(): array
{

View File

@@ -168,7 +168,7 @@ class ModuleDependencySort
foreach ($aCountDepsByModuleId as $sModuleId => $iInDegreeCounter) {
$oModule = $aUnresolvedDependencyModules[$sModuleId];
if ($bOneLoopAtLeast && $iInDegreeCounter > 0) {
if ($bOneLoopAtLeast && ($iInDegreeCounter > 0)) {
break;
}

View File

@@ -95,7 +95,7 @@ class ModuleDiscovery
protected static $m_aModules = [];
protected static $m_aModuleVersionByName = [];
/** @var array<\iTopExtension $m_aRemovedExtensions */
/** @var array<\iTopExtension> $m_aRemovedExtensions */
protected static $m_aRemovedExtensions = [];
// All the entries below are list of file paths relative to the module directory
@@ -307,11 +307,11 @@ class ModuleDiscovery
private static function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
{
if (!isset(static::$oPhpExpressionEvaluator)) {
static::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
if (!isset(self::$oPhpExpressionEvaluator)) {
self::$oPhpExpressionEvaluator = new PhpExpressionEvaluator([], RunTimeEnvironment::STATIC_CALL_AUTOSELECT_WHITELIST);
}
return static::$oPhpExpressionEvaluator;
return self::$oPhpExpressionEvaluator;
}
/**
@@ -360,10 +360,12 @@ class ModuleDiscovery
/**
* Helper function to interpret the name of a module
*
* @param $sModuleId string Identifier of the module, in the form 'name/version'
* @return array(name, version)
*
* @return array of 2 elements (name, version)
*/
public static function GetModuleName($sModuleId)
public static function GetModuleName($sModuleId): array
{
$aMatches = [];
if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches)) {

View File

@@ -58,12 +58,14 @@ class ModuleFileReader
final public static function SetInstance(?ModuleFileReader $oInstance): void
{
static::$oInstance = $oInstance;
self::$oInstance = $oInstance;
}
/**
* Read the information from a module file (module.xxx.php)
* @param string $sModuleFile
*
* @param string $sModuleFilePath
*
* @return array
* @throws ModuleFileReaderException
*/
@@ -109,7 +111,9 @@ class ModuleFileReader
* Read the information from a module file (module.xxx.php)
* Warning: this method is using eval() function to load the ModuleInstallerAPI classes.
* Current method is never called at design/runtime. It is acceptable to use it during setup only.
* @param string $sModuleFile
*
* @param string $sModuleFilePath
*
* @return array
* @throws ModuleFileReaderException
*/
@@ -199,7 +203,7 @@ class ModuleFileReader
/**
* @param string $sModuleFilePath
* @param \PhpParser\Node\Expr\Assign $oAssignation
* @param \PhpParser\Node\Stmt\Expression $oExpression
*
* @return array|null
* @throws ModuleFileReaderException

View File

@@ -71,12 +71,12 @@ class InstallationFileService
return $this->aAfterComputationSelectedExtensions;
}
public function SetItopExtensionsMap(ItopExtensionsMap $oItopExtensionsMap): void
public function SetItopExtensionsMap(iTopExtensionsMap $oItopExtensionsMap): void
{
$this->oItopExtensionsMap = $oItopExtensionsMap;
}
public function GetItopExtensionsMap(): ItopExtensionsMap
public function GetItopExtensionsMap(): iTopExtensionsMap
{
if (is_null($this->oItopExtensionsMap)) {
$this->oItopExtensionsMap = new iTopExtensionsMap($this->sTargetEnvironment);

View File

@@ -230,6 +230,7 @@ class XMLDataLoader
} else {
$iDstObj = (int)($oSubNode);
// Attempt to find the object in the list of loaded objects
/** @var \Combodo\iTop\Core\AttributeDefinition\AttributeExternalKey $oAttDef */
$iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), $iDstObj);
if ($iExtKey == 0) {
$iExtKey = -$iDstObj; // Convention: Unresolved keys are stored as negative !
@@ -356,6 +357,7 @@ class XMLDataLoader
$iExtKey = -1;
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) {
if (($oAttDef->IsExternalKey()) && ($oTargetObj->Get($sAttCode) < 0)) { // Convention unresolved key = negative
/** @var \Combodo\iTop\Core\AttributeDefinition\AttributeExternalKey $oAttDef */
$sTargetClass = $oAttDef->GetTargetClass();
$iTempKey = $oTargetObj->Get($sAttCode);