Passed
Push — master ( 0380ca...346253 )
by Jesse
04:05
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.
src/ArgumentLexeme.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public const ARG_TYPE_STRING  = 'string';
43 43
 
44 44
 	/** @var int[] string    s */
45
-	public const STRING_TYPES = [ self::T_STRING ];
45
+	public const STRING_TYPES = [self::T_STRING];
46 46
 
47 47
 	/** @var int[] integer    d, u, c, o, x, X, b */
48 48
 	public const INTEGER_TYPES = [
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 	 *   PrintfLexeme::ARG_TYPE_STRING
113 113
 	 */
114 114
 	public function argType() : string {
115
-		if( in_array($this->lexItemType, self::INTEGER_TYPES, true) ) {
115
+		if (in_array($this->lexItemType, self::INTEGER_TYPES, true)) {
116 116
 			return self::ARG_TYPE_INT;
117 117
 		}
118 118
 
119
-		if( in_array($this->lexItemType, self::DOUBLE_TYPES, true) ) {
119
+		if (in_array($this->lexItemType, self::DOUBLE_TYPES, true)) {
120 120
 			return self::ARG_TYPE_DOUBLE;
121 121
 		}
122 122
 
123
-		if( in_array($this->lexItemType, self::STRING_TYPES, true) ) {
123
+		if (in_array($this->lexItemType, self::STRING_TYPES, true)) {
124 124
 			return self::ARG_TYPE_STRING;
125 125
 		}
126 126
 
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
@@ -8,5 +8,5 @@
 block discarded – undo
8 8
 	 * @param \donatj\Printf\Lexeme $lexItem
9 9
 	 * @internal This is for use by the Parser
10 10
 	 */
11
-	public function emit( Lexeme $lexItem ) : void;
11
+	public function emit(Lexeme $lexItem) : void;
12 12
 }
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
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 	 * @param \donatj\Printf\Lexeme $lexItem
12 12
 	 * @internal This is for use by the Parser
13 13
 	 */
14
-	public function emit( Lexeme $lexItem ) : void {
14
+	public function emit(Lexeme $lexItem) : void {
15 15
 		$this->lexemes[] = $lexItem;
16 16
 	}
17 17
 
Please login to merge, or discard this patch.
src/Parser.php 1 patch
Spacing   +23 added lines, -23 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 ) : string {
167
+	private function eatInt(StringLexer $lexer) : string {
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
 			}
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
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
 	/**
13 13
 	 * StringScanner constructor.
14 14
 	 */
15
-	public function __construct( string $string ) {
15
+	public function __construct(string $string) {
16 16
 		$this->string = $string;
17 17
 	}
18 18
 
19
-	public function peek( $size = 1 ) : CharData {
19
+	public function peek($size = 1) : CharData {
20 20
 		$str = substr($this->string, $this->pos, $size);
21 21
 
22 22
 		return new CharData($str, strlen($str) < $size);
@@ -36,19 +36,19 @@  discard block
 block discarded – undo
36 36
 
37 37
 	public function rewind() : void {
38 38
 		$this->pos--;
39
-		if( $this->pos < 0 ) {
39
+		if ($this->pos < 0) {
40 40
 			//@todo custom exception
41 41
 			throw new \RuntimeException('cannot rewind');
42 42
 		}
43 43
 	}
44 44
 
45
-	public function hasPrefix( string $prefix ) : bool {
45
+	public function hasPrefix(string $prefix) : bool {
46 46
 		$peek = $this->peek(strlen($prefix));
47 47
 
48 48
 		return $peek->getString() === $prefix;
49 49
 	}
50 50
 
51
-	public function substr( $start, $length ) : string {
51
+	public function substr($start, $length) : string {
52 52
 		return substr($this->string, $start, $length);
53 53
 	}
54 54
 
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
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 	/** @var bool */
10 10
 	private $eof;
11 11
 
12
-	public function __construct( string $string, bool $eof ) {
12
+	public function __construct(string $string, bool $eof) {
13 13
 		$this->string = $string;
14 14
 		$this->eof    = $eof;
15 15
 	}
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.