File tree Expand file tree Collapse file tree 2 files changed +48
-7
lines changed
Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -118,11 +118,7 @@ public function resolve(array $config): array
118118
119119 if ($ diff = array_diff (array_keys ($ config ), $ allowedKeys )) {
120120 $ this ->throwOrLogError (
121- new InvalidMap (sprintf (
122- 'Key(s) "%s" are not known, known keys: "%s" ' ,
123- implode ('", " ' , ($ diff )),
124- implode ('", " ' , $ allowedKeys )
125- ))
121+ UnknownKeys::fromKeysAndAllowedKeys (array_values ($ diff ), $ allowedKeys )
126122 );
127123
128124 $ config = $ this ->removeKeys ($ config , $ diff );
@@ -227,12 +223,12 @@ public function errors(): ResolverErrors
227223 }
228224
229225 /**
230- * @return array <string>
226+ * @return list <string>
231227 */
232228 private function resolveAllowedKeys (): array
233229 {
234230 $ allowedKeys = array_merge (array_keys ($ this ->defaults ), $ this ->required );
235- return $ allowedKeys ;
231+ return array_values ( $ allowedKeys) ;
236232 }
237233
238234 private function throwOrLogError (InvalidMap $ error ): void
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Phpactor \MapResolver ;
4+
5+
6+ class UnknownKeys extends InvalidMap
7+ {
8+ /**
9+ * @param list<string> $allowedKeys
10+ * @param list<string> $keys
11+ */
12+ public function __construct (string $ message , private array $ keys , private array $ allowedKeys )
13+ {
14+ parent ::__construct ($ message );
15+ }
16+
17+ /**
18+ * @return list<string>
19+ */
20+ public function additionalKeys (): array
21+ {
22+ return $ this ->keys ;
23+ }
24+
25+ /**
26+ * @return list<string>
27+ */
28+ public function allowedKeys (): array
29+ {
30+ return $ this ->allowedKeys ;
31+ }
32+
33+ /**
34+ * @param list<string> $allowedKeys
35+ * @param list<string> $diff
36+ */
37+ public static function fromKeysAndAllowedKeys (array $ diff , array $ allowedKeys ): self
38+ {
39+ return new self (sprintf (
40+ 'Key(s) "%s" are not known, known keys: "%s" ' ,
41+ implode ('", " ' , ($ diff )),
42+ implode ('", " ' , $ allowedKeys ),
43+ ), $ diff , $ allowedKeys );
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments