@@ -73,7 +73,7 @@ public function getArguments() {
7373 if (!isset ($ this ->_parsed )) {
7474 $ this ->parse ();
7575 }
76- return $ this ->_parsed ;
76+ return $ this ->_parsed ?? [] ;
7777 }
7878
7979 /**
@@ -110,7 +110,7 @@ public function offsetExists($offset) {
110110 $ offset = $ offset ->key ;
111111 }
112112
113- return array_key_exists ($ offset , $ this ->_parsed );
113+ return array_key_exists ($ offset , $ this ->_parsed ?? [] );
114114 }
115115
116116 /**
@@ -442,15 +442,20 @@ public function parse() {
442442
443443 $ this ->_applyDefaults ();
444444
445- foreach ($ this ->_lexer as $ argument ) {
446- if ($ this ->_parseFlag ($ argument )) {
447- continue ;
448- }
449- if ($ this ->_parseOption ($ argument )) {
450- continue ;
451- }
445+ if ($ this ->_lexer ) {
446+ foreach ($ this ->_lexer as $ argument ) {
447+ if (null === $ argument ) {
448+ continue ;
449+ }
450+ if ($ this ->_parseFlag ($ argument )) {
451+ continue ;
452+ }
453+ if ($ this ->_parseOption ($ argument )) {
454+ continue ;
455+ }
452456
453- array_push ($ this ->_invalid , $ argument ->raw ());
457+ array_push ($ this ->_invalid , $ argument ->raw ());
458+ }
454459 }
455460
456461 if ($ this ->_strict && !empty ($ this ->_invalid )) {
@@ -523,6 +528,8 @@ private function _parseOption($option) {
523528 return false ;
524529 }
525530
531+ assert (null !== $ this ->_lexer );
532+
526533 // Peak ahead to make sure we get a value.
527534 if ($ this ->_lexer ->end () || !$ this ->_lexer ->peek ->isValue ) {
528535 $ optionSettings = $ this ->getOption ($ option ->key );
@@ -546,6 +553,9 @@ private function _parseOption($option) {
546553 // Loop until we find a flag in peak-ahead
547554 while ( $ this ->_lexer ->valid () ) {
548555 $ value = $ this ->_lexer ->current ();
556+ if ( null === $ value ) {
557+ break ;
558+ }
549559 array_push ( $ values , $ value ->raw );
550560
551561 if ( ! $ this ->_lexer ->end () && ! $ this ->_lexer ->peek ->isValue ) {
0 commit comments