File tree Expand file tree Collapse file tree 5 files changed +13
-32
lines changed Expand file tree Collapse file tree 5 files changed +13
-32
lines changed Original file line number Diff line number Diff line change 55- Enh #25 : Add support for PHPStan Extension Installer (@samuelrajan747 )
66- Enh #26 : Add PHPStan extension installer instructions and improve ` ServiceMap ` configuration handling (@terabytesoftw )
77- Bug #27 : Enhance error handling in ` ServiceMap ` for invalid configuration structures and add corresponding test cases (@terabytesoftw )
8+ - Bug #28 : Refactor component handling in ` ServiceMap ` to improve variable naming and streamline logic (@terabytesoftw )
89
910## 0.2.2 June 04, 2025
1011
Original file line number Diff line number Diff line change @@ -270,24 +270,20 @@ private function processComponents(array $config): void
270270 if ($ config !== []) {
271271 $ components = $ config ['components ' ] ?? [];
272272
273- foreach ($ components as $ id => $ component ) {
273+ foreach ($ components as $ id => $ definition ) {
274274 if (is_string ($ id ) === false ) {
275275 $ this ->throwErrorWhenIdIsNotString ('Component ' , gettype ($ id ));
276276 }
277277
278- if (is_object ($ component )) {
279- $ this ->components [$ id ] = get_class ($ component );
278+ if (is_object ($ definition )) {
279+ $ this ->components [$ id ] = get_class ($ definition );
280280
281281 continue ;
282282 }
283283
284- if (isset ($ component ['class ' ]) && is_string ($ component ['class ' ]) && $ component ['class ' ] !== '' ) {
285- $ this ->components [$ id ] = $ component ['class ' ];
286-
287- continue ;
284+ if (isset ($ definition ['class ' ]) && is_string ($ definition ['class ' ]) && $ definition ['class ' ] !== '' ) {
285+ $ this ->components [$ id ] = $ definition ['class ' ];
288286 }
289-
290- $ this ->throwErrorWhenUnsupportedDefinition ($ id );
291287 }
292288 }
293289 }
Original file line number Diff line number Diff line change @@ -120,6 +120,10 @@ public function testItLoadsServicesAndComponents(): void
120120 $ serviceMap ->getComponentClassById ('customInitializedComponent ' ),
121121 'ServiceMap should resolve component id \'customInitializedComponent \' to \'MyActiveRecord::class \'. ' ,
122122 );
123+ $ this ->assertNull (
124+ $ serviceMap ->getComponentClassById ('assetManager ' ),
125+ 'ServiceMap should return \'null \' for \'assetManager \' component id as it is not a class but an array. ' ,
126+ );
123127 }
124128
125129 public function testItAllowsWithoutEmptyConfigPath (): void
@@ -164,20 +168,6 @@ public function testThrowRuntimeExceptionWhenComponentsHasUnsupportedIdNotString
164168 new ServiceMap ($ fixturePath );
165169 }
166170
167- /**
168- * @throws ReflectionException if the service definition is invalid or can't be resolved.
169- */
170- public function testThrowRuntimeExceptionWhenComponentsHasUnsupportedTypeArrayInvalidValue (): void
171- {
172- $ ds = DIRECTORY_SEPARATOR ;
173- $ fixturePath = __DIR__ . "{$ ds }fixture {$ ds }components-unsupported-type-array-invalid.php " ;
174-
175- $ this ->expectException (RuntimeException::class);
176- $ this ->expectExceptionMessage ('Unsupported definition for \'unsupported-array-invalid \'. ' );
177-
178- new ServiceMap ($ fixturePath );
179- }
180-
181171 public function testThrowRuntimeExceptionWhenConfigPathFileDoesNotExist (): void
182172 {
183173 $ this ->expectException (InvalidArgumentException::class);
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 66
77return [
88 'components ' => [
9+ 'assetManager ' => [
10+ 'basePath ' => '@runtime/assets ' ,
11+ ],
912 'customComponent ' => [
1013 'class ' => MyActiveRecord::class,
1114 ],
You can’t perform that action at this time.
0 commit comments