Completed
Push — master ( ed4efe...199c93 )
by Jesse
01:47
created
src/StringLexer.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
14 14
 	/**
15 15
 	 * StringScanner constructor.
16 16
 	 */
17
-	public function __construct( string $string ) {
17
+	public function __construct(string $string) {
18 18
 		$this->string = $string;
19 19
 	}
20 20
 
21
-	public function peek( $size = 1 ) : CharData {
21
+	public function peek($size = 1) : CharData {
22 22
 		$str = substr($this->string, $this->pos, $size);
23 23
 
24 24
 		return new CharData($str, strlen($str) < $size);
@@ -38,19 +38,19 @@  discard block
 block discarded – undo
38 38
 
39 39
 	public function rewind() : void {
40 40
 		$this->pos--;
41
-		if( $this->pos < 0 ) {
41
+		if ($this->pos < 0) {
42 42
 			//@todo custom exception
43 43
 			throw new \RuntimeException('cannot rewind');
44 44
 		}
45 45
 	}
46 46
 
47
-	public function hasPrefix( string $prefix ) : bool {
47
+	public function hasPrefix(string $prefix) : bool {
48 48
 		$peek = $this->peek(strlen($prefix));
49 49
 
50 50
 		return $peek->getString() === $prefix;
51 51
 	}
52 52
 
53
-	public function substr( $start, $length ) : string {
53
+	public function substr($start, $length) : string {
54 54
 		return substr($this->string, $start, $length);
55 55
 	}
56 56
 }
Please login to merge, or discard this patch.
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/CharData.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
 	 */
14 14
 	private $eof;
15 15
 
16
-	public function __construct( string $string, bool $eof ) {
16
+	public function __construct(string $string, bool $eof) {
17 17
 		$this->string = $string;
18 18
 		$this->eof    = $eof;
19 19
 	}
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.
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/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/LexemeCollection.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @internal
19 19
 	 */
20
-	public function __construct( Lexeme ...$lexItems ) {
20
+	public function __construct(Lexeme ...$lexItems) {
21 21
 		$this->lexItems = $lexItems;
22 22
 	}
23 23
 
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 	 * This is useful for checking if a printf string parsed without error.
28 28
 	 */
29 29
 	public function getInvalid() : ?Lexeme {
30
-		foreach( $this->lexItems as $lexItem ) {
31
-			if( $lexItem->getLexItemType() === Lexeme::T_INVALID ) {
30
+		foreach ($this->lexItems as $lexItem) {
31
+			if ($lexItem->getLexItemType() === Lexeme::T_INVALID) {
32 32
 				return $lexItem;
33 33
 			}
34 34
 		}
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	/**
40 40
 	 * @internal
41 41
 	 */
42
-	public function offsetSet( $offset, $value ) {
43
-		if( $offset === null ) {
42
+	public function offsetSet($offset, $value) {
43
+		if ($offset === null) {
44 44
 			$this->lexItems[] = $value;
45 45
 		} else {
46 46
 			$this->lexItems[$offset] = $value;
@@ -50,21 +50,21 @@  discard block
 block discarded – undo
50 50
 	/**
51 51
 	 * @internal
52 52
 	 */
53
-	public function offsetExists( $offset ) {
53
+	public function offsetExists($offset) {
54 54
 		return isset($this->lexItems[$offset]);
55 55
 	}
56 56
 
57 57
 	/**
58 58
 	 * @internal
59 59
 	 */
60
-	public function offsetUnset( $offset ) {
60
+	public function offsetUnset($offset) {
61 61
 		unset($this->lexItems[$offset]);
62 62
 	}
63 63
 
64 64
 	/**
65 65
 	 * @internal
66 66
 	 */
67
-	public function offsetGet( $offset ) {
67
+	public function offsetGet($offset) {
68 68
 		return isset($this->lexItems[$offset]) ? $this->lexItems[$offset] : null;
69 69
 	}
70 70
 
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
 	public function argTypes() : array {
100 100
 		$noNumInc = 1;
101 101
 		$args     = [];
102
-		foreach( $this->lexItems as $item ) {
103
-			if( $item instanceof ArgumentLexeme ) {
102
+		foreach ($this->lexItems as $item) {
103
+			if ($item instanceof ArgumentLexeme) {
104 104
 				$type = $item->argType();
105 105
 
106
-				if( $item->getArg() !== null ) {
106
+				if ($item->getArg() !== null) {
107 107
 					$args[$item->getArg()] = $type;
108 108
 				} else {
109 109
 					$args[$noNumInc] = $type;
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   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@  discard block
 block discarded – undo
14 14
 	 *
15 15
 	 * @param \donatj\Printf\Emitter $emitter The given Emitter will be parsed Lexemes as parsed
16 16
 	 */
17
-	public function __construct( Emitter $emitter ) {
17
+	public function __construct(Emitter $emitter) {
18 18
 		$this->emitter = $emitter;
19 19
 	}
20 20
 
21 21
 	/**
22 22
 	 * Parses a printf string and pass parsed lexemes to the configured Emitter
23 23
 	 */
24
-	public function parseStr( string $string ) : void {
24
+	public function parseStr(string $string) : void {
25 25
 		$lexer = new StringLexer($string);
26 26
 
27
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
28
-			if( $next->getString() === '%' ) {
29
-				if( $lexer->hasPrefix('%') ) {
27
+		while (($next = $lexer->next()) && !$next->isEof()) {
28
+			if ($next->getString() === '%') {
29
+				if ($lexer->hasPrefix('%')) {
30 30
 					$this->emitter->emit(
31 31
 						new Lexeme(Lexeme::T_LITERAL_STRING, '%', $lexer->pos())
32 32
 					);
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 		}
46 46
 	}
47 47
 
48
-	private function lexString( Emitter $emitter, StringLexer $lexer ) : void {
48
+	private function lexString(Emitter $emitter, StringLexer $lexer) : void {
49 49
 		$pos    = $lexer->pos();
50 50
 		$buffer = '';
51
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
52
-			if( $next->getString() === '%' ) {
51
+		while (($next = $lexer->next()) && !$next->isEof()) {
52
+			if ($next->getString() === '%') {
53 53
 				$lexer->rewind();
54 54
 				break;
55 55
 			}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		);
63 63
 	}
64 64
 
65
-	private function lexSprintf( Emitter $emitter, StringLexer $lexer ) : void {
65
+	private function lexSprintf(Emitter $emitter, StringLexer $lexer) : void {
66 66
 		$pos  = $lexer->pos();
67 67
 		$next = $lexer->next();
68 68
 
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
 		$leftJustified = null;
74 74
 		$precision     = null;
75 75
 
76
-		if( $next->getString() !== '0' && ctype_digit($next->getString()) ) {
76
+		if ($next->getString() !== '0' && ctype_digit($next->getString())) {
77 77
 			$lexer->rewind();
78 78
 			$int = $this->eatInt($lexer);
79
-			if( $lexer->hasPrefix('$') ) {
79
+			if ($lexer->hasPrefix('$')) {
80 80
 				$lexer->next();
81 81
 				$next = $lexer->next();
82 82
 				$arg  = $int;
83 83
 			}
84 84
 		}
85 85
 
86
-		switch( $next->getString() ) {
86
+		switch ($next->getString()) {
87 87
 			case '0':
88 88
 				$padChar = '0';
89 89
 				$next    = $lexer->next();
@@ -98,23 +98,23 @@  discard block
 block discarded – undo
98 98
 				$next    = $lexer->next();
99 99
 		}
100 100
 
101
-		if( $next->getString() === '-' ) {
101
+		if ($next->getString() === '-') {
102 102
 			$leftJustified = true;
103 103
 			$next          = $lexer->next();
104 104
 		}
105 105
 
106
-		if( $padChar !== null ) {
106
+		if ($padChar !== null) {
107 107
 			$lexer->rewind();
108 108
 			$peek = $lexer->peek();
109
-			if( ctype_digit($peek->getString()) ) {
109
+			if (ctype_digit($peek->getString())) {
110 110
 				$padWidth = $this->eatInt($lexer);
111 111
 			}
112 112
 
113 113
 			$next = $lexer->next();
114 114
 		}
115 115
 
116
-		if( $next->getString() === '.' ) {
117
-			if( ctype_digit($lexer->peek()->getString()) ) {
116
+		if ($next->getString() === '.') {
117
+			if (ctype_digit($lexer->peek()->getString())) {
118 118
 				$precision = $this->eatInt($lexer);
119 119
 			}
120 120
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		}
123 123
 
124 124
 		$tType = Lexeme::T_INVALID;
125
-		if( in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true) ) {
125
+		if (in_array($next->getString(), ArgumentLexeme::VALID_T_TYPES, true)) {
126 126
 			$tType = $next->getString();
127 127
 		}
128 128
 
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 		);
144 144
 	}
145 145
 
146
-	private function eatInt( StringLexer $lexer ) : string {
146
+	private function eatInt(StringLexer $lexer) : string {
147 147
 		$int = '';
148
-		while( ($next = $lexer->next()) && !$next->isEof() ) {
149
-			if( !ctype_digit($next->getString()) ) {
148
+		while (($next = $lexer->next()) && !$next->isEof()) {
149
+			if (!ctype_digit($next->getString())) {
150 150
 				$lexer->rewind();
151 151
 				break;
152 152
 			}
Please login to merge, or discard this patch.