Passed
Push — master ( c162fe...9501f0 )
by Jesse
10:47 queued 07:59
created
src/Lexeme.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 	/**
24 24
 	 * LexItem constructor.
25 25
 	 */
26
-	public function __construct( string $lexItemType, string $val, int $pos ) {
26
+	public function __construct(string $lexItemType, string $val, int $pos) {
27 27
 		$this->lexItemType = $lexItemType;
28 28
 		$this->val         = $val;
29 29
 		$this->pos         = $pos;
Please login to merge, or discard this patch.
example/example.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require __DIR__ . '/../vendor/autoload.php';
3
+require __DIR__.'/../vendor/autoload.php';
4 4
 
5 5
 $emitter = new \donatj\Printf\LexemeEmitter;
6 6
 $parser  = new \donatj\Printf\Parser($emitter);
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 
10 10
 $lexemes = $emitter->getLexemes();
11 11
 
12
-foreach( $lexemes as $lexeme ) {
13
-	echo $lexeme->getLexItemType() . ' -> ';
12
+foreach ($lexemes as $lexeme) {
13
+	echo $lexeme->getLexItemType().' -> ';
14 14
 	echo var_export($lexeme->getVal(), true);
15 15
 
16
-	if( $lexeme instanceof \donatj\Printf\ArgumentLexeme ) {
17
-		echo ' arg type: ' . $lexeme->argType();
16
+	if ($lexeme instanceof \donatj\Printf\ArgumentLexeme) {
17
+		echo ' arg type: '.$lexeme->argType();
18 18
 	}
19 19
 
20 20
 	echo PHP_EOL;
Please login to merge, or discard this patch.
src/LexemeCollection.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @internal
17 17
 	 */
18
-	public function __construct( Lexeme ...$lexItems ) {
18
+	public function __construct(Lexeme ...$lexItems) {
19 19
 		$this->lexItems = $lexItems;
20 20
 	}
21 21
 
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 	 * This is useful for checking if a printf string parsed without error.
26 26
 	 */
27 27
 	public function getInvalid() : ?Lexeme {
28
-		foreach( $this->lexItems as $lexItem ) {
29
-			if( $lexItem->getLexItemType() === Lexeme::T_INVALID ) {
28
+		foreach ($this->lexItems as $lexItem) {
29
+			if ($lexItem->getLexItemType() === Lexeme::T_INVALID) {
30 30
 				return $lexItem;
31 31
 			}
32 32
 		}
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @internal
39 39
 	 */
40
-	public function offsetSet( $offset, $value ) : void {
41
-		if( $offset === null ) {
40
+	public function offsetSet($offset, $value) : void {
41
+		if ($offset === null) {
42 42
 			$this->lexItems[] = $value;
43 43
 		} else {
44 44
 			$this->lexItems[$offset] = $value;
@@ -48,21 +48,21 @@  discard block
 block discarded – undo
48 48
 	/**
49 49
 	 * @internal
50 50
 	 */
51
-	public function offsetExists( $offset ) : bool {
51
+	public function offsetExists($offset) : bool {
52 52
 		return isset($this->lexItems[$offset]);
53 53
 	}
54 54
 
55 55
 	/**
56 56
 	 * @internal
57 57
 	 */
58
-	public function offsetUnset( $offset ) : void {
58
+	public function offsetUnset($offset) : void {
59 59
 		unset($this->lexItems[$offset]);
60 60
 	}
61 61
 
62 62
 	/**
63 63
 	 * @internal
64 64
 	 */
65
-	public function offsetGet( $offset ) : ?Lexeme {
65
+	public function offsetGet($offset) : ?Lexeme {
66 66
 		return $this->lexItems[$offset] ?? null;
67 67
 	}
68 68
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	public function argTypes() : array {
98 98
 		$noNumInc = 1;
99 99
 		$args     = [];
100
-		foreach( $this->lexItems as $item ) {
101
-			if( $item instanceof ArgumentLexeme ) {
100
+		foreach ($this->lexItems as $item) {
101
+			if ($item instanceof ArgumentLexeme) {
102 102
 				$type = $item->argType();
103 103
 
104
-				if( $item->getArg() !== null ) {
104
+				if ($item->getArg() !== null) {
105 105
 					$args[$item->getArg()] = $type;
106 106
 				} else {
107 107
 					$args[$noNumInc] = $type;
Please login to merge, or discard this patch.
src/ArgumentLexeme.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	public const ARG_TYPE_STRING  = 'string';
64 64
 
65 65
 	/** @var string[] string    s */
66
-	public const STRING_TYPES = [ self::T_STRING ];
66
+	public const STRING_TYPES = [self::T_STRING];
67 67
 
68 68
 	/** @var string[] integer    d, u, c, o, x, X, b */
69 69
 	public const INTEGER_TYPES = [
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 	 *   ArgumentLexeme::ARG_TYPE_STRING
169 169
 	 */
170 170
 	public function argType() : string {
171
-		if( in_array($this->lexItemType, self::INTEGER_TYPES, true) ) {
171
+		if (in_array($this->lexItemType, self::INTEGER_TYPES, true)) {
172 172
 			return self::ARG_TYPE_INT;
173 173
 		}
174 174
 
175
-		if( in_array($this->lexItemType, self::DOUBLE_TYPES, true) ) {
175
+		if (in_array($this->lexItemType, self::DOUBLE_TYPES, true)) {
176 176
 			return self::ARG_TYPE_DOUBLE;
177 177
 		}
178 178
 
179
-		if( in_array($this->lexItemType, self::STRING_TYPES, true) ) {
179
+		if (in_array($this->lexItemType, self::STRING_TYPES, true)) {
180 180
 			return self::ARG_TYPE_STRING;
181 181
 		}
182 182
 
Please login to merge, or discard this patch.
src/LexemeEmitter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 	/**
11 11
 	 * @internal This is for use by the Parser
12 12
 	 */
13
-	public function emit( Lexeme $lexItem ) : void {
13
+	public function emit(Lexeme $lexItem) : void {
14 14
 		$this->lexemes[] = $lexItem;
15 15
 	}
16 16
 
Please login to merge, or discard this patch.
src/StringLexer.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 	/**
14 14
 	 * StringScanner constructor.
15 15
 	 */
16
-	public function __construct( string $string ) {
16
+	public function __construct(string $string) {
17 17
 		$this->string = $string;
18 18
 	}
19 19
 
20
-	public function peek( int $size = 1 ) : CharData {
20
+	public function peek(int $size = 1) : CharData {
21 21
 		$str = substr($this->string, $this->pos, $size);
22 22
 
23 23
 		return new CharData($str, strlen($str) < $size);
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 
38 38
 	public function rewind() : void {
39 39
 		$this->pos--;
40
-		if( $this->pos < 0 ) {
40
+		if ($this->pos < 0) {
41 41
 			//@todo custom exception
42 42
 			throw new \RuntimeException('cannot rewind');
43 43
 		}
44 44
 	}
45 45
 
46
-	public function hasPrefix( string $prefix ) : bool {
46
+	public function hasPrefix(string $prefix) : bool {
47 47
 		$peek = $this->peek(strlen($prefix));
48 48
 
49 49
 		return $peek->getString() === $prefix;
50 50
 	}
51 51
 
52
-	public function substr( int $start, int $length ) : string {
52
+	public function substr(int $start, int $length) : string {
53 53
 		return substr($this->string, $start, $length);
54 54
 	}
55 55
 
Please login to merge, or discard this patch.
src/Parser.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@  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
-		for(;;) {
30
+		for (;;) {
31 31
 			$next = $lexer->next();
32
-			if( $next->isEof() ) {
32
+			if ($next->isEof()) {
33 33
 				break;
34 34
 			}
35 35
 
36
-			if( $next->getString() === '%' ) {
37
-				if( $lexer->hasPrefix('%') ) {
36
+			if ($next->getString() === '%') {
37
+				if ($lexer->hasPrefix('%')) {
38 38
 					$this->emitter->emit(
39 39
 						new Lexeme(Lexeme::T_LITERAL_STRING, '%', $lexer->pos())
40 40
 					);
@@ -53,16 +53,16 @@  discard block
 block discarded – undo
53 53
 		}
54 54
 	}
55 55
 
56
-	private function lexString( Emitter $emitter, StringLexer $lexer ) : void {
56
+	private function lexString(Emitter $emitter, StringLexer $lexer) : void {
57 57
 		$pos    = $lexer->pos();
58 58
 		$buffer = '';
59
-		for(;;) {
59
+		for (;;) {
60 60
 			$next = $lexer->next();
61
-			if( $next->isEof() ) {
61
+			if ($next->isEof()) {
62 62
 				break;
63 63
 			}
64 64
 
65
-			if( $next->getString() === '%' ) {
65
+			if ($next->getString() === '%') {
66 66
 				$lexer->rewind();
67 67
 				break;
68 68
 			}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		);
76 76
 	}
77 77
 
78
-	private function lexSprintf( Emitter $emitter, StringLexer $lexer ) : void {
78
+	private function lexSprintf(Emitter $emitter, StringLexer $lexer) : void {
79 79
 		$pos  = $lexer->pos();
80 80
 		$next = $lexer->next();
81 81
 
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
 		$leftJustified = false;
87 87
 		$precision     = null;
88 88
 
89
-		if( $next->getString() !== '0' && ctype_digit($next->getString()) ) {
89
+		if ($next->getString() !== '0' && ctype_digit($next->getString())) {
90 90
 			$lexer->rewind();
91 91
 			$int = $this->eatInt($lexer);
92
-			if( $lexer->hasPrefix('$') ) {
92
+			if ($lexer->hasPrefix('$')) {
93 93
 				$lexer->next();
94 94
 				$next = $lexer->next();
95 95
 				$arg  = $int;
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 		}
98 98
 
99 99
 		// flag parsing
100
-		for(;;) {
101
-			switch( $next->getString() ) {
100
+		for (;;) {
101
+			switch ($next->getString()) {
102 102
 				case '0':
103 103
 					$padChar = '0';
104 104
 					$next    = $lexer->next();
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 					continue 2;
118 118
 			}
119 119
 
120
-			if( $next->getString() === '-' ) {
120
+			if ($next->getString() === '-') {
121 121
 				$leftJustified = true;
122 122
 				$next          = $lexer->next();
123 123
 
124 124
 				continue;
125 125
 			}
126 126
 
127
-			if( $next->getString() === '+' ) {
127
+			if ($next->getString() === '+') {
128 128
 				$showPositive = true;
129 129
 				$next         = $lexer->next();
130 130
 
@@ -134,18 +134,18 @@  discard block
 block discarded – undo
134 134
 			break;
135 135
 		}
136 136
 
137
-		if( $padChar !== null ) {
137
+		if ($padChar !== null) {
138 138
 			$lexer->rewind();
139 139
 			$peek = $lexer->peek();
140
-			if( ctype_digit($peek->getString()) ) {
140
+			if (ctype_digit($peek->getString())) {
141 141
 				$padWidth = $this->eatInt($lexer);
142 142
 			}
143 143
 
144 144
 			$next = $lexer->next();
145 145
 		}
146 146
 
147
-		if( $next->getString() === '.' ) {
148
-			if( ctype_digit($lexer->peek()->getString()) ) {
147
+		if ($next->getString() === '.') {
148
+			if (ctype_digit($lexer->peek()->getString())) {
149 149
 				$precision = $this->eatInt($lexer);
150 150
 			}
151 151
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 		}
154 154
 
155 155
 		$tType = Lexeme::T_INVALID;
156
-		if( in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true) ) {
156
+		if (in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true)) {
157 157
 			$tType = $next->getString();
158 158
 		}
159 159
 
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
 		);
175 175
 	}
176 176
 
177
-	private function eatInt( StringLexer $lexer ) : ?int {
177
+	private function eatInt(StringLexer $lexer) : ?int {
178 178
 		$int = '';
179
-		for(;;) {
179
+		for (;;) {
180 180
 			$next = $lexer->next();
181
-			if( $next->isEof() ) {
181
+			if ($next->isEof()) {
182 182
 				break;
183 183
 			}
184 184
 
185
-			if( !ctype_digit($next->getString()) ) {
185
+			if (!ctype_digit($next->getString())) {
186 186
 				$lexer->rewind();
187 187
 				break;
188 188
 			}
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 			$int .= $next->getString();
191 191
 		}
192 192
 
193
-		if( $int ) {
194
-			return (int)$int;
193
+		if ($int) {
194
+			return (int) $int;
195 195
 		}
196 196
 
197 197
 		return null;
Please login to merge, or discard this patch.
src/Emitter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,6 +7,6 @@
 block discarded – undo
7 7
 	/**
8 8
 	 * @internal This is for use by the Parser
9 9
 	 */
10
-	public function emit( Lexeme $lexItem ) : void;
10
+	public function emit(Lexeme $lexItem) : void;
11 11
 
12 12
 }
Please login to merge, or discard this patch.
src/CharData.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 	private string $string;
8 8
 	private bool $eof;
9 9
 
10
-	public function __construct( string $string, bool $eof ) {
10
+	public function __construct(string $string, bool $eof) {
11 11
 		$this->string = $string;
12 12
 		$this->eof    = $eof;
13 13
 	}
Please login to merge, or discard this patch.