@@ -162,8 +162,13 @@ private function getLatestLtsNodeVersion(): string
162162 return 'Unknown ' ;
163163 }
164164
165+ /** @var array<int, array<string, mixed>> $nodes */
165166 foreach ($ nodes as $ node ) {
166- if (isset ($ node ['lts ' ]) && $ node ['lts ' ] !== false ) {
167+ if (isset ($ node ['lts ' ])
168+ && $ node ['lts ' ] !== false
169+ && isset ($ node ['version ' ])
170+ && is_string ($ node ['version ' ])
171+ ) {
167172 return trim ($ node ['version ' ], 'v ' );
168173 }
169174 }
@@ -407,12 +412,15 @@ private function getSearchEngineFromMagentoConfig(): ?string
407412 private function checkSearchEngineViaDeploymentConfig ($ objectManager ): ?string
408413 {
409414 try {
415+ /** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */
410416 $ deploymentConfig = $ objectManager ->get (\Magento \Framework \App \DeploymentConfig::class);
411417 $ engineConfig = $ deploymentConfig ->get ('system/search/engine ' );
412418
413- if (!empty ($ engineConfig )) {
414- $ host = $ deploymentConfig ->get ('system/search/engine_host ' ) ?: 'localhost ' ;
415- $ port = $ deploymentConfig ->get ('system/search/engine_port ' ) ?: '9200 ' ;
419+ if (!empty ($ engineConfig ) && is_string ($ engineConfig )) {
420+ $ hostRaw = $ deploymentConfig ->get ('system/search/engine_host ' );
421+ $ portRaw = $ deploymentConfig ->get ('system/search/engine_port ' );
422+ $ host = is_string ($ hostRaw ) ? $ hostRaw : 'localhost ' ;
423+ $ port = is_string ($ portRaw ) ? $ portRaw : '9200 ' ;
416424
417425 $ url = "http:// {$ host }: {$ port }" ;
418426 if ($ this ->testElasticsearchConnection ($ url )) {
@@ -439,12 +447,11 @@ private function checkSearchEngineViaDeploymentConfig($objectManager): ?string
439447 private function checkSearchEngineViaEngineResolver ($ objectManager ): ?string
440448 {
441449 try {
450+ /** @var \Magento\Framework\Search\EngineResolverInterface $engineResolver */
442451 $ engineResolver = $ objectManager ->get (\Magento \Framework \Search \EngineResolverInterface::class);
443- if ($ engineResolver ) {
444- $ currentEngine = $ engineResolver ->getCurrentSearchEngine ();
445- if (!empty ($ currentEngine )) {
446- return ucfirst ($ currentEngine ) . ' (Magento config) ' ;
447- }
452+ $ currentEngine = $ engineResolver ->getCurrentSearchEngine ();
453+ if (!empty ($ currentEngine )) {
454+ return ucfirst ($ currentEngine ) . ' (Magento config) ' ;
448455 }
449456 } catch (\Exception $ e ) {
450457 if ($ this ->io ->isVerbose ()) {
@@ -541,12 +548,16 @@ private function getSearchEngineHosts(): array
541548 */
542549 private function formatSearchEngineVersion (array $ info ): string
543550 {
544- if (isset ($ info ['version ' ]['distribution ' ]) && $ info ['version ' ]['distribution ' ] === 'opensearch ' ) {
545- return 'OpenSearch ' . $ info ['version ' ]['number ' ];
551+ $ version = $ info ['version ' ] ?? null ;
552+ if (!is_array ($ version )) {
553+ return 'Search Engine Available ' ;
554+ }
555+ if (isset ($ version ['distribution ' ]) && $ version ['distribution ' ] === 'opensearch ' ) {
556+ return 'OpenSearch ' . (is_string ($ version ['number ' ]) ? $ version ['number ' ] : '' );
546557 }
547558
548- if (isset ($ info [ ' version ' ] ['number ' ])) {
549- return 'Elasticsearch ' . $ info [ ' version ' ] ['number ' ];
559+ if (isset ($ version ['number ' ])) {
560+ return 'Elasticsearch ' . ( is_string ( $ version [ ' number ' ]) ? $ version ['number ' ] : '' ) ;
550561 }
551562
552563 return 'Search Engine Available ' ;
@@ -597,6 +608,7 @@ private function tryMagentoHttpClient(string $url): ?array
597608 if ($ status === 200 && !empty ($ response )) {
598609 $ data = json_decode ($ response , true );
599610 if (is_array ($ data )) {
611+ /** @var array<string, mixed> $data */
600612 return $ data ;
601613 }
602614 }
@@ -661,10 +673,24 @@ private function getDiskSpace(): string
661673 $ totalSpace = disk_total_space ('. ' );
662674 $ freeSpace = disk_free_space ('. ' );
663675
664- $ totalGB = round ((($ totalSpace / 1024 ) / 1024 ) / 1024 , 2 );
665- $ freeGB = round ((($ freeSpace / 1024 ) / 1024 ) / 1024 , 2 );
676+ if ($ totalSpace === false || $ freeSpace === false ) {
677+ return 'Unknown ' ;
678+ }
679+
680+ if ($ totalSpace <= 0 ) {
681+ $ totalGB = 0.0 ;
682+ $ usedGB = 0.0 ;
683+ $ usedPercent = 0.0 ;
684+
685+ return "$ usedGB GB / $ totalGB GB ( $ usedPercent%) " ;
686+ }
687+
688+ $ totalGB = round ($ totalSpace / 1024 / 1024 / 1024 , 2 );
689+ $ freeGB = round ($ freeSpace / 1024 / 1024 / 1024 , 2 );
666690 $ usedGB = round ($ totalGB - $ freeGB , 2 );
667- $ usedPercent = round (($ usedGB / $ totalGB ) * 100 , 2 );
691+ $ usedPercent = $ totalGB > 0.0
692+ ? round (($ usedGB / $ totalGB ) * 100 , 2 )
693+ : 0.0 ;
668694
669695 return "$ usedGB GB / $ totalGB GB ( $ usedPercent%) " ;
670696 }
@@ -734,9 +760,10 @@ private function getMagentoEnvironmentValue(string $name): ?string
734760 private function getValueFromDeploymentConfig ($ objectManager , string $ name ): ?string
735761 {
736762 try {
763+ /** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */
737764 $ deploymentConfig = $ objectManager ->get (\Magento \Framework \App \DeploymentConfig::class);
738765 $ envValue = $ deploymentConfig ->get ('system/default/environment/ ' . $ name );
739- if ($ envValue !== null ) {
766+ if ($ envValue !== null && is_scalar ( $ envValue ) ) {
740767 return (string ) $ envValue ;
741768 }
742769 } catch (\Exception $ e ) {
@@ -760,7 +787,7 @@ private function getValueFromEnvironmentService($objectManager, string $name): ?
760787 try {
761788 $ environmentService = $ objectManager ->get (\Magento \Framework \App \EnvironmentInterface::class);
762789 $ method = 'get ' . str_replace (' ' , '' , ucwords (str_replace ('_ ' , ' ' , strtolower ($ name ))));
763- if (method_exists ($ environmentService , $ method )) {
790+ if (is_object ( $ environmentService ) && method_exists ($ environmentService , $ method )) {
764791 $ value = $ environmentService ->$ method ();
765792 if ($ value !== null ) {
766793 return (string ) $ value ;
0 commit comments