Passed
Push — master ( 346253...835c81 )
by Jesse
03:13
created
src/Parser.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @param \donatj\Printf\Emitter $emitter The given Emitter to emit Lexemes as parsed
19 19
 	 */
20
-	public function __construct( Emitter $emitter ) {
20
+	public function __construct(Emitter $emitter) {
21 21
 		$this->emitter = $emitter;
22 22
 	}
23 23
 
24 24
 	/**
25 25
 	 * Parses a printf string and emit parsed lexemes to the configured Emitter
26 26
 	 */
27
-	public function parseStr( string $string ) : void {
27
+	public function parseStr(string $string) : void {
28 28
 		$lexer = new StringLexer($string);
29 29
 
30
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
31
-			if( $next->getString() === '%' ) {
32
-				if( $lexer->hasPrefix('%') ) {
30
+		while (($next = $lexer->next()) && !$next->isEof()) {
31
+			if ($next->getString() === '%') {
32
+				if ($lexer->hasPrefix('%')) {
33 33
 					$this->emitter->emit(
34 34
 						new Lexeme(Lexeme::T_LITERAL_STRING, '%', $lexer->pos())
35 35
 					);
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
 		}
49 49
 	}
50 50
 
51
-	private function lexString( Emitter $emitter, StringLexer $lexer ) : void {
51
+	private function lexString(Emitter $emitter, StringLexer $lexer) : void {
52 52
 		$pos    = $lexer->pos();
53 53
 		$buffer = '';
54
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
55
-			if( $next->getString() === '%' ) {
54
+		while (($next = $lexer->next()) && !$next->isEof()) {
55
+			if ($next->getString() === '%') {
56 56
 				$lexer->rewind();
57 57
 				break;
58 58
 			}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		);
66 66
 	}
67 67
 
68
-	private function lexSprintf( Emitter $emitter, StringLexer $lexer ) : void {
68
+	private function lexSprintf(Emitter $emitter, StringLexer $lexer) : void {
69 69
 		$pos  = $lexer->pos();
70 70
 		$next = $lexer->next();
71 71
 
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
 		$leftJustified = false;
77 77
 		$precision     = null;
78 78
 
79
-		if( $next->getString() !== '0' && ctype_digit($next->getString()) ) {
79
+		if ($next->getString() !== '0' && ctype_digit($next->getString())) {
80 80
 			$lexer->rewind();
81 81
 			$int = $this->eatInt($lexer);
82
-			if( $lexer->hasPrefix('$') ) {
82
+			if ($lexer->hasPrefix('$')) {
83 83
 				$lexer->next();
84 84
 				$next = $lexer->next();
85 85
 				$arg  = $int;
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 		}
88 88
 
89 89
 		// flag parsing
90
-		for(;;) {
91
-			switch( $next->getString() ) {
90
+		for (;;) {
91
+			switch ($next->getString()) {
92 92
 				case '0':
93 93
 					$padChar = '0';
94 94
 					$next    = $lexer->next();
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 					continue 2;
108 108
 			}
109 109
 
110
-			if( $next->getString() === '-' ) {
110
+			if ($next->getString() === '-') {
111 111
 				$leftJustified = true;
112 112
 				$next          = $lexer->next();
113 113
 
114 114
 				continue;
115 115
 			}
116 116
 
117
-			if( $next->getString() === '+' ) {
117
+			if ($next->getString() === '+') {
118 118
 				$showPositive = true;
119 119
 				$next         = $lexer->next();
120 120
 
@@ -124,18 +124,18 @@  discard block
 block discarded – undo
124 124
 			break;
125 125
 		}
126 126
 
127
-		if( $padChar !== null ) {
127
+		if ($padChar !== null) {
128 128
 			$lexer->rewind();
129 129
 			$peek = $lexer->peek();
130
-			if( ctype_digit($peek->getString()) ) {
130
+			if (ctype_digit($peek->getString())) {
131 131
 				$padWidth = $this->eatInt($lexer);
132 132
 			}
133 133
 
134 134
 			$next = $lexer->next();
135 135
 		}
136 136
 
137
-		if( $next->getString() === '.' ) {
138
-			if( ctype_digit($lexer->peek()->getString()) ) {
137
+		if ($next->getString() === '.') {
138
+			if (ctype_digit($lexer->peek()->getString())) {
139 139
 				$precision = $this->eatInt($lexer);
140 140
 			}
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		}
144 144
 
145 145
 		$tType = Lexeme::T_INVALID;
146
-		if( in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true) ) {
146
+		if (in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true)) {
147 147
 			$tType = $next->getString();
148 148
 		}
149 149
 
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 		);
165 165
 	}
166 166
 
167
-	private function eatInt( StringLexer $lexer ) : ?int {
167
+	private function eatInt(StringLexer $lexer) : ?int {
168 168
 		$int = '';
169
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
170
-			if( !ctype_digit($next->getString()) ) {
169
+		while (($next = $lexer->next()) && !$next->isEof()) {
170
+			if (!ctype_digit($next->getString())) {
171 171
 				$lexer->rewind();
172 172
 				break;
173 173
 			}
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 			$int .= $next->getString();
176 176
 		}
177 177
 
178
-		if( $int ) {
179
-			return (int)$int;
178
+		if ($int) {
179
+			return (int) $int;
180 180
 		}
181 181
 
182 182
 		return null;
Please login to merge, or discard this patch.