14
14
use Laminas \Cache \Storage \Adapter \AdapterOptions ;
15
15
use Webmozart \Assert \Assert ;
16
16
17
+ use function array_keys ;
17
18
use function is_array ;
18
19
use function is_object ;
19
20
@@ -74,6 +75,7 @@ public function getMetadata(string $key): ?object
74
75
/**
75
76
* Internal method to get metadata of an item.
76
77
*
78
+ * @param non-empty-string $normalizedKey
77
79
* @return TMetadata|null Metadata on success, null on failure or in case metadata is not accessible.
78
80
* @throws ExceptionInterface
79
81
*/
@@ -103,28 +105,14 @@ public function getMetadatas(array $keys): array
103
105
}
104
106
105
107
$ result = $ this ->triggerPost (__FUNCTION__ , $ args , $ result );
106
- Assert::isMap ($ result );
107
- Assert::allObject ($ result );
108
+ $ this ->assertValidMetadataResult ($ result );
108
109
109
- /**
110
- * NOTE: We do trust the event handling here and assume that it will return a map of instances of Metadata
111
- * and thus does not modify the type.
112
- *
113
- * @var array<string,TMetadata> $result
114
- */
115
110
return $ result ;
116
111
} catch (Exception $ exception ) {
117
112
$ result = [];
118
113
$ result = $ this ->triggerThrowable (__FUNCTION__ , $ args , $ result , $ exception );
119
- Assert::isArray ($ result );
120
- Assert::allObject ($ result );
114
+ $ this ->assertValidMetadataResult ($ result );
121
115
122
- /**
123
- * NOTE: We do trust the event handling here and assume that it will return a map of instances of Metadata
124
- * and thus does not modify the type.
125
- *
126
- * @var array<string,TMetadata> $result
127
- */
128
116
return $ result ;
129
117
}
130
118
}
@@ -150,4 +138,14 @@ protected function internalGetMetadatas(array $normalizedKeys): array
150
138
151
139
return $ result ;
152
140
}
141
+
142
+ /**
143
+ * @psalm-assert array<non-empty-string,TMetadata> $result
144
+ */
145
+ private function assertValidMetadataResult (mixed $ result ): void
146
+ {
147
+ Assert::isMap ($ result );
148
+ $ this ->assertValidKeys (array_keys ($ result ));
149
+ Assert::allObject ($ result );
150
+ }
153
151
}
0 commit comments