5454 * container?: array{
5555 * definitions?: array<array-key, DefinitionType>,
5656 * singletons?: array<array-key, DefinitionType>,
57- * }
57+ * },
58+ * params?: array<string, mixed>,
5859 * }
5960 *
6061 * @copyright Copyright (C) 2023 Terabytesoftw.
@@ -97,6 +98,13 @@ final class ServiceMap
9798 */
9899 private array $ componentsDefinitions = [];
99100
101+ /**
102+ * Application params for PHPStan type inference.
103+ *
104+ * @phpstan-var array<string, mixed>
105+ */
106+ private array $ params = [];
107+
100108 /**
101109 * Service definitions map for Yii Application analysis.
102110 *
@@ -133,6 +141,7 @@ public function __construct(string $configPath = '')
133141 $ this ->processBehaviors ($ config );
134142 $ this ->processComponents ($ config );
135143 $ this ->processDefinition ($ config );
144+ $ this ->processParams ($ config );
136145 $ this ->processSingletons ($ config );
137146 }
138147
@@ -237,6 +246,19 @@ public function getComponentDefinitionById(string $id): array
237246 return is_array ($ definition ) ? $ definition : [];
238247 }
239248
249+ /**
250+ * Retrieves the application params map for PHPStan type inference.
251+ *
252+ * Returns the `params` key-value pairs extracted from the Yii Application configuration file, enabling static
253+ * analysis tools to infer precise array shape types for `Yii::$app->params` access.
254+ *
255+ * @return array<string, mixed> Params key-value pairs from configuration.
256+ */
257+ public function getParams (): array
258+ {
259+ return $ this ->params ;
260+ }
261+
240262 /**
241263 * Retrieves the fully qualified class name of a Yii Service by its identifier.
242264 *
@@ -306,6 +328,10 @@ private function loadConfig(string $configPath): array
306328 $ this ->throwErrorWhenConfigFileIsNotArray ($ configPath , 'components ' );
307329 }
308330
331+ if (isset ($ config ['params ' ]) && is_array ($ config ['params ' ]) === false ) {
332+ $ this ->throwErrorWhenConfigFileIsNotArray ($ configPath , 'params ' );
333+ }
334+
309335 if (isset ($ config ['container ' ])) {
310336 if (is_array ($ config ['container ' ]) === false ) {
311337 $ this ->throwErrorWhenConfigFileIsNotArray ($ configPath , 'container ' );
@@ -517,6 +543,23 @@ private function processDefinition(array $config): void
517543 }
518544 }
519545
546+ /**
547+ * Processes application params from the Yii Application configuration array.
548+ *
549+ * Extracts the `params` section and stores it for type inference of `Yii::$app->params` array access.
550+ *
551+ * @param array $config Yii Application configuration array containing params definitions.
552+ *
553+ * @phpstan-import-type ServiceType from ServiceMap
554+ * @phpstan-param ServiceType $config
555+ */
556+ private function processParams (array $ config ): void
557+ {
558+ if ($ config !== []) {
559+ $ this ->params = $ config ['params ' ] ?? [];
560+ }
561+ }
562+
520563 /**
521564 * Processes singleton service definitions from the Yii Application configuration array.
522565 *
@@ -584,7 +627,9 @@ private function throwErrorWhenConfigFileIsNotArray(string ...$args): never
584627 */
585628 private function throwErrorWhenIsNotString (string ...$ args ): never
586629 {
587- throw new RuntimeException (sprintf ("'%s': '%s' must be a 'string', got '%s'. " , ...$ args ));
630+ throw new RuntimeException (
631+ sprintf ("'%s': '%s' must be a 'string', got '%s'. " , ...$ args ),
632+ );
588633 }
589634
590635 /**
@@ -602,6 +647,8 @@ private function throwErrorWhenIsNotString(string ...$args): never
602647 */
603648 private function throwErrorWhenUnsupportedDefinition (string $ id ): never
604649 {
605- throw new RuntimeException (sprintf ("Unsupported definition for '%s'. " , $ id ));
650+ throw new RuntimeException (
651+ sprintf ("Unsupported definition for '%s'. " , $ id ),
652+ );
606653 }
607654}
0 commit comments