File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -279,24 +279,22 @@ private function handleDefaultNested(
279279
280280 private function assertArgumentCount (): void
281281 {
282- if ($ this ->parameters ()->requiredKeys ()->count () <= $ this ->count ) {
282+ $ requiredKeys = $ this ->parameters ()->requiredKeys ()->toArray ();
283+ if (count ($ requiredKeys ) <= $ this ->count ) {
283284 return ;
284285 }
285286 $ argumentKeys = array_keys ($ this ->arguments );
286287 if ($ this ->isPositional ) {
287288 $ missing = array_diff (
288- array_keys ($ this -> parameters ()-> keys () ),
289+ array_keys ($ requiredKeys ),
289290 $ argumentKeys
290291 );
291292 $ missing = array_map (
292- fn (int $ key ) => $ this -> parameters ()-> keys () [$ key ],
293+ fn (int $ key ) => $ requiredKeys [$ key ],
293294 $ missing
294295 );
295296 } else {
296- $ missing = array_diff (
297- $ this ->parameters ()->keys (),
298- $ argumentKeys
299- );
297+ $ missing = array_diff ($ requiredKeys , $ argumentKeys );
300298 }
301299
302300 throw new ArgumentCountError (
Original file line number Diff line number Diff line change 1313
1414namespace Chevere \Tests ;
1515
16+ use ArgumentCountError ;
1617use BadMethodCallException ;
1718use Chevere \Parameter \ArrayParameter ;
1819use Chevere \Parameter \BoolParameter ;
@@ -110,6 +111,19 @@ public function testOptionalMissing(): void
110111 $ parameters ->optional ('foo ' );
111112 }
112113
114+ public function testRequiredMissingNoOptional (): void
115+ {
116+ $ parameters = (new Parameters (foo: string ()))
117+ ->withOptional ('bar ' , string ());
118+ $ this ->expectException (ArgumentCountError::class);
119+ $ this ->expectExceptionMessage (
120+ <<<PLAIN
121+ Missing required argument(s): `foo`
122+ PLAIN
123+ );
124+ $ parameters ();
125+ }
126+
113127 public function testRequiredCasting (): void
114128 {
115129 $ parameter = string ();
You can’t perform that action at this time.
0 commit comments