@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * LexemeCollection constructor. |
| 14 | 14 | */ |
| 15 | - public function __construct( Lexeme ...$lexItems ) { |
|
| 15 | + public function __construct(Lexeme ...$lexItems) { |
|
| 16 | 16 | $this->lexItems = $lexItems; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | * Retrieve the first invalid Lexeme or null if all are valid. |
| 21 | 21 | */ |
| 22 | 22 | public function getInvalid() : ?Lexeme { |
| 23 | - foreach( $this->lexItems as $lexItem ) { |
|
| 24 | - if( $lexItem->getLexItemType() === Lexeme::T_INVALID ) { |
|
| 23 | + foreach ($this->lexItems as $lexItem) { |
|
| 24 | + if ($lexItem->getLexItemType() === Lexeme::T_INVALID) { |
|
| 25 | 25 | return $lexItem; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -29,23 +29,23 @@ discard block |
||
| 29 | 29 | return null; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function offsetSet( $offset, $value ) { |
|
| 33 | - if( $offset === null ) { |
|
| 32 | + public function offsetSet($offset, $value) { |
|
| 33 | + if ($offset === null) { |
|
| 34 | 34 | $this->lexItems[] = $value; |
| 35 | 35 | } else { |
| 36 | 36 | $this->lexItems[$offset] = $value; |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function offsetExists( $offset ) { |
|
| 40 | + public function offsetExists($offset) { |
|
| 41 | 41 | return isset($this->lexItems[$offset]); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function offsetUnset( $offset ) { |
|
| 44 | + public function offsetUnset($offset) { |
|
| 45 | 45 | unset($this->lexItems[$offset]); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function offsetGet( $offset ) { |
|
| 48 | + public function offsetGet($offset) { |
|
| 49 | 49 | return isset($this->lexItems[$offset]) ? $this->lexItems[$offset] : null; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | public function argTypes() : array { |
| 74 | 74 | $noNumInc = 1; |
| 75 | 75 | $args = []; |
| 76 | - foreach( $this->lexItems as $item ) { |
|
| 77 | - if( $item instanceof ArgumentLexeme ) { |
|
| 76 | + foreach ($this->lexItems as $item) { |
|
| 77 | + if ($item instanceof ArgumentLexeme) { |
|
| 78 | 78 | $type = $item->argType(); |
| 79 | 79 | |
| 80 | - if( $item->getArg() !== null ) { |
|
| 80 | + if ($item->getArg() !== null) { |
|
| 81 | 81 | $args[$item->getArg()] = $type; |
| 82 | 82 | } else { |
| 83 | 83 | $args[$noNumInc] = $type; |
@@ -14,16 +14,16 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @param Emitter $emitter |
| 16 | 16 | */ |
| 17 | - public function __construct( Emitter $emitter ) { |
|
| 17 | + public function __construct(Emitter $emitter) { |
|
| 18 | 18 | $this->emitter = $emitter; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function parseStr( string $string ) : void { |
|
| 21 | + public function parseStr(string $string) : void { |
|
| 22 | 22 | $lexer = new StringLexer($string); |
| 23 | 23 | |
| 24 | - while( ($next = $lexer->next()) && !$next->isEof() ) { |
|
| 25 | - if( $next->getString() === '%' ) { |
|
| 26 | - if( $lexer->hasPrefix('%') ) { |
|
| 24 | + while (($next = $lexer->next()) && !$next->isEof()) { |
|
| 25 | + if ($next->getString() === '%') { |
|
| 26 | + if ($lexer->hasPrefix('%')) { |
|
| 27 | 27 | $this->emitter->emit( |
| 28 | 28 | new Lexeme(Lexeme::T_LITERAL_STRING, '%', $lexer->pos()) |
| 29 | 29 | ); |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - private function lexString( Emitter $emitter, StringLexer $lexer ) : void { |
|
| 45 | + private function lexString(Emitter $emitter, StringLexer $lexer) : void { |
|
| 46 | 46 | $pos = $lexer->pos(); |
| 47 | 47 | $buffer = ''; |
| 48 | - while( ($next = $lexer->next()) && !$next->isEof() ) { |
|
| 49 | - if( $next->getString() === '%' ) { |
|
| 48 | + while (($next = $lexer->next()) && !$next->isEof()) { |
|
| 49 | + if ($next->getString() === '%') { |
|
| 50 | 50 | $lexer->rewind(); |
| 51 | 51 | break; |
| 52 | 52 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - private function lexSprintf( Emitter $emitter, StringLexer $lexer ) : void { |
|
| 62 | + private function lexSprintf(Emitter $emitter, StringLexer $lexer) : void { |
|
| 63 | 63 | $pos = $lexer->pos(); |
| 64 | 64 | $next = $lexer->next(); |
| 65 | 65 | |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | $leftJustified = null; |
| 71 | 71 | $precision = null; |
| 72 | 72 | |
| 73 | - if( $next->getString() !== '0' && ctype_digit($next->getString()) ) { |
|
| 73 | + if ($next->getString() !== '0' && ctype_digit($next->getString())) { |
|
| 74 | 74 | $lexer->rewind(); |
| 75 | 75 | $int = $this->eatInt($lexer); |
| 76 | - if( $lexer->hasPrefix('$') ) { |
|
| 76 | + if ($lexer->hasPrefix('$')) { |
|
| 77 | 77 | $lexer->next(); |
| 78 | 78 | $next = $lexer->next(); |
| 79 | 79 | $arg = $int; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - switch( $next->getString() ) { |
|
| 83 | + switch ($next->getString()) { |
|
| 84 | 84 | case '0': |
| 85 | 85 | $padChar = '0'; |
| 86 | 86 | $next = $lexer->next(); |
@@ -95,23 +95,23 @@ discard block |
||
| 95 | 95 | $next = $lexer->next(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if( $next->getString() === '-' ) { |
|
| 98 | + if ($next->getString() === '-') { |
|
| 99 | 99 | $leftJustified = true; |
| 100 | 100 | $next = $lexer->next(); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if( $padChar !== null ) { |
|
| 103 | + if ($padChar !== null) { |
|
| 104 | 104 | $lexer->rewind(); |
| 105 | 105 | $peek = $lexer->peek(); |
| 106 | - if( ctype_digit($peek->getString()) ) { |
|
| 106 | + if (ctype_digit($peek->getString())) { |
|
| 107 | 107 | $padWidth = $this->eatInt($lexer); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $next = $lexer->next(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if( $next->getString() === '.' ) { |
|
| 114 | - if( ctype_digit($lexer->peek()->getString()) ) { |
|
| 113 | + if ($next->getString() === '.') { |
|
| 114 | + if (ctype_digit($lexer->peek()->getString())) { |
|
| 115 | 115 | $precision = $this->eatInt($lexer); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $tType = Lexeme::T_INVALID; |
| 122 | - if( isset(ArgumentLexeme::CHAR_MAP[$next->getString()]) ) { |
|
| 122 | + if (isset(ArgumentLexeme::CHAR_MAP[$next->getString()])) { |
|
| 123 | 123 | $tType = ArgumentLexeme::CHAR_MAP[$next->getString()]; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | ); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - private function eatInt( StringLexer $lexer ) : string { |
|
| 143 | + private function eatInt(StringLexer $lexer) : string { |
|
| 144 | 144 | $int = ''; |
| 145 | - while( ($next = $lexer->next()) && !$next->isEof() ) { |
|
| 146 | - if( !ctype_digit($next->getString()) ) { |
|
| 145 | + while (($next = $lexer->next()) && !$next->isEof()) { |
|
| 146 | + if (!ctype_digit($next->getString())) { |
|
| 147 | 147 | $lexer->rewind(); |
| 148 | 148 | break; |
| 149 | 149 | } |