File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,30 @@ public function convertParameterArray(array $parameters): array
156156 return $ parameters ;
157157 }
158158
159+ /**
160+ * @param array $parameters
161+ * @return array
162+ */
163+ public function remapNumericParameterIndexes (array $ parameters ): array
164+ {
165+ $ index = 0 ;
166+ $ remapTo = $ this ->keys ();
167+ $ remappedParameters = [];
168+
169+ foreach ($ parameters as $ key => $ value ) {
170+ $ newIndex = $ key ;
171+
172+ if (is_numeric ($ key )) {
173+ $ newIndex = $ remapTo [$ index ];
174+ }
175+
176+ $ remappedParameters [$ newIndex ] = $ value ;
177+ $ index ++;
178+ }
179+
180+ return $ remappedParameters ;
181+ }
182+
159183 /**
160184 * @return bool
161185 */
Original file line number Diff line number Diff line change @@ -66,6 +66,22 @@ public function testValidateParameter()
6666 $ this ->assertFalse ($ parameterStrategy ->validateParameter ('test ' , 'ing ' ));
6767 }
6868
69+ public function testRemapNumericParameterIndexes ()
70+ {
71+ $ parameterStrategy = new ParameterStrategy (1 , 1 , [
72+ 'test ' => new \WildPHP \Commands \Parameters \NumericParameter (),
73+ 'ing ' => new \WildPHP \Commands \Parameters \NumericParameter ()
74+ ]);
75+
76+ $ parameters = [1 , 2 ];
77+ $ expected = ['test ' => 1 , 'ing ' => 2 ];
78+ $ this ->assertEquals ($ expected , $ parameterStrategy ->remapNumericParameterIndexes ($ parameters ));
79+
80+ $ parameters = [1 , 'foo ' => 2 ];
81+ $ expected = ['test ' => 1 , 'foo ' => 2 ];
82+ $ this ->assertEquals ($ expected , $ parameterStrategy ->remapNumericParameterIndexes ($ parameters ));
83+ }
84+
6985 public function testConvertParameter ()
7086 {
7187 $ parameterStrategy = new \WildPHP \Commands \ParameterStrategy (1 , 4 , [
You can’t perform that action at this time.
0 commit comments