Test Setup Failed
Push — master ( 96bf95...c80778 )
by Martijn
02:10
created
src/Vanderlee/Comprehend/Parser/Terminal/Regex.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
  */
13 13
 class Regex extends Parser {
14 14
 	
15
-	use CaseSensitiveTrait;
15
+    use CaseSensitiveTrait;
16 16
 
17 17
     /**
18 18
      * @var string|null
19 19
      */
20
-	private $pattern = null;
20
+    private $pattern = null;
21 21
 
22
-	public function __construct($pattern)
23
-	{
24
-		if (empty($pattern)) {
25
-			throw new \InvalidArgumentException('Empty pattern');
26
-		}
22
+    public function __construct($pattern)
23
+    {
24
+        if (empty($pattern)) {
25
+            throw new \InvalidArgumentException('Empty pattern');
26
+        }
27 27
 		
28
-		if (@preg_match($pattern, null) === false) {
29
-			throw new \InvalidArgumentException('Invalid pattern');
30
-		}
28
+        if (@preg_match($pattern, null) === false) {
29
+            throw new \InvalidArgumentException('Invalid pattern');
30
+        }
31 31
 		
32
-		$this->pattern = $pattern;
33
-	}
34
-
35
-	protected function parse(&$input, $offset, Context $context)
36
-	{		
37
-		$this->pushCaseSensitivityToContext($context);
38
-		$pattern = $this->pattern . ($context->isCaseSensitive() ? '' : 'i');
39
-		$this->popCaseSensitivityFromContext($context);
40
-
41
-		if (preg_match($pattern, $input, $match, 0, $offset) !== FALSE) {
42
-			if (count($match) > 0 && mb_strlen($match[0]) > 0 && strpos($input, $match[0], $offset) == $offset) {
43
-				return $this->success($input, $offset, mb_strlen($match[0]));
44
-			}
45
-		}
32
+        $this->pattern = $pattern;
33
+    }
34
+
35
+    protected function parse(&$input, $offset, Context $context)
36
+    {		
37
+        $this->pushCaseSensitivityToContext($context);
38
+        $pattern = $this->pattern . ($context->isCaseSensitive() ? '' : 'i');
39
+        $this->popCaseSensitivityFromContext($context);
40
+
41
+        if (preg_match($pattern, $input, $match, 0, $offset) !== FALSE) {
42
+            if (count($match) > 0 && mb_strlen($match[0]) > 0 && strpos($input, $match[0], $offset) == $offset) {
43
+                return $this->success($input, $offset, mb_strlen($match[0]));
44
+            }
45
+        }
46 46
 		
47
-		return $this->failure($input, $offset);
48
-	}
47
+        return $this->failure($input, $offset);
48
+    }
49 49
 	
50
-	public function __toString()
51
-	{
52
-		return (string) $this->pattern;
53
-	}
50
+    public function __toString()
51
+    {
52
+        return (string) $this->pattern;
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Terminal/Nothing.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
  */
15 15
 class Nothing extends Parser {
16 16
 
17
-	protected function parse(&$input, $offset, Context $context)
18
-	{
19
-		return $this->makeMatch($offset <= mb_strlen($input), $input, 0);
20
-	}
17
+    protected function parse(&$input, $offset, Context $context)
18
+    {
19
+        return $this->makeMatch($offset <= mb_strlen($input), $input, 0);
20
+    }
21 21
 
22
-	public function __toString()
23
-	{
24
-		return '0.';
25
-	}
22
+    public function __toString()
23
+    {
24
+        return '0.';
25
+    }
26 26
 
27 27
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Output/AssignTrait.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,38 +8,38 @@
 block discarded – undo
8 8
  */
9 9
 trait AssignTrait {
10 10
 
11
-	/**
12
-	 * List of result names to assign the matched text to.
13
-	 * @var callable[]
14
-	 */
15
-	private $assignCallbacks = [];
11
+    /**
12
+     * List of result names to assign the matched text to.
13
+     * @var callable[]
14
+     */
15
+    private $assignCallbacks = [];
16 16
 
17 17
     /**
18 18
      * Resolve all callbacks registered to this trait
19 19
      *
20 20
      * @param $text
21 21
      */
22
-	private function resolveAssignCallbacks($text)
23
-	{
24
-		foreach ($this->assignCallbacks as $callback) {
25
-			$callback($text);
26
-		}
27
-	}
22
+    private function resolveAssignCallbacks($text)
23
+    {
24
+        foreach ($this->assignCallbacks as $callback) {
25
+            $callback($text);
26
+        }
27
+    }
28 28
 
29
-	/**
30
-	 * After parsing, assign the matched input to the specified local variable.
31
-	 * Only assign if successfully matched entire parent up to root.
32
-	 *  
33
-	 * @param mixed $variable
34
-	 * @return $this
35
-	 */
36
-	public function assignTo(&$variable)
37
-	{
38
-		$this->assignCallbacks[] = function($text) use (&$variable) {
39
-			$variable = $text;
40
-		};
29
+    /**
30
+     * After parsing, assign the matched input to the specified local variable.
31
+     * Only assign if successfully matched entire parent up to root.
32
+     *  
33
+     * @param mixed $variable
34
+     * @return $this
35
+     */
36
+    public function assignTo(&$variable)
37
+    {
38
+        $this->assignCallbacks[] = function($text) use (&$variable) {
39
+            $variable = $text;
40
+        };
41 41
 		
42
-		return $this;
43
-	}
42
+        return $this;
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Output/ResultTrait.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -8,97 +8,97 @@
 block discarded – undo
8 8
  */
9 9
 trait ResultTrait {
10 10
 
11
-	/**
12
-	 * List of result names to assign the matched text to.
13
-	 * @var callable[]
14
-	 */
15
-	private $resultCallbacks = [];
11
+    /**
12
+     * List of result names to assign the matched text to.
13
+     * @var callable[]
14
+     */
15
+    private $resultCallbacks = [];
16 16
 
17
-	private function resolveResultCallbacks(&$results, $text)
18
-	{
19
-		foreach ($this->resultCallbacks as $callback) {
20
-			$callback($results, $text);
21
-		}
22
-	}
17
+    private function resolveResultCallbacks(&$results, $text)
18
+    {
19
+        foreach ($this->resultCallbacks as $callback) {
20
+            $callback($results, $text);
21
+        }
22
+    }
23 23
 
24
-	/**
25
-	 * After parsing, assign the matched input of this parser to the named result.
24
+    /**
25
+     * After parsing, assign the matched input of this parser to the named result.
26 26
      * Only assign if successfully matched entire parent up to root.
27
-	 * 
28
-	 * @param string|integer $key
27
+     * 
28
+     * @param string|integer $key
29 29
      * @param null|callable|string $value
30
-	 * @return $this
31
-	 */
32
-	public function setResult($key = null, $value = null)
33
-	{
34
-		$this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
30
+     * @return $this
31
+     */
32
+    public function setResult($key = null, $value = null)
33
+    {
34
+        $this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
35 35
             if (is_callable($value)) {
36 36
                 $text = $value($text);
37 37
             } elseif ($value !== null) {
38 38
                 $text = $value;
39 39
             }
40 40
 
41
-	        $results[$key] = $text;
42
-		};
41
+            $results[$key] = $text;
42
+        };
43 43
 
44
-		return $this;
45
-	}
44
+        return $this;
45
+    }
46 46
 
47
-	/**
48
-	 * If result exists, concatenate the matched text as a string, otherwise
49
-	 * create it. If result is an array, concat to the last entry.
50
-	 * 
51
-	 * @param null|string $key
47
+    /**
48
+     * If result exists, concatenate the matched text as a string, otherwise
49
+     * create it. If result is an array, concat to the last entry.
50
+     * 
51
+     * @param null|string $key
52 52
      * @param null|callable|string $value
53 53
      * @return $this
54
-	 */
55
-	public function concatResult($key = null, $value = null)
56
-	{
57
-		$this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
54
+     */
55
+    public function concatResult($key = null, $value = null)
56
+    {
57
+        $this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
58 58
             if (is_callable($value)) {
59 59
                 $text = $value($text);
60 60
             } elseif ($value !== null) {
61 61
                 $text = $value;
62 62
             }
63 63
 
64
-			if (!isset($results[$key])) {
65
-				$results[$key] = (string) $text;
66
-			} elseif (is_array($results[$key])) {
67
-				$results[$key][] = array_pop($results[$key]) . $text;
68
-			} else {
69
-				$results[$key] .= $text;
70
-			}
71
-		};
64
+            if (!isset($results[$key])) {
65
+                $results[$key] = (string) $text;
66
+            } elseif (is_array($results[$key])) {
67
+                $results[$key][] = array_pop($results[$key]) . $text;
68
+            } else {
69
+                $results[$key] .= $text;
70
+            }
71
+        };
72 72
 
73
-		return $this;
74
-	}
73
+        return $this;
74
+    }
75 75
 
76
-	/**
77
-	 * Turn the result into an array and start a new entry.
78
-	 *
76
+    /**
77
+     * Turn the result into an array and start a new entry.
78
+     *
79 79
      * @param null|string $key
80 80
      * @param null|callable|string $value
81 81
      * @return $this
82
-	 */
83
-	public function pushResult($key = null, $value = null)
84
-	{
85
-		$this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
82
+     */
83
+    public function pushResult($key = null, $value = null)
84
+    {
85
+        $this->resultCallbacks[] = function(&$results, $text) use (&$key, &$value) {
86 86
             if (is_callable($value)) {
87 87
                 $text = $value($text);
88 88
             } elseif ($value !== null) {
89 89
                 $text = $value;
90 90
             }
91 91
 			
92
-			if (!isset($results[$key])) {
93
-				$results[$key] = [$text];
94
-			} elseif (is_array($results[$key])) {
95
-				$results[$key][] = $text;
96
-			} else {
97
-				$results[$key] = [$results[$key], $text];
98
-			}
99
-		};
92
+            if (!isset($results[$key])) {
93
+                $results[$key] = [$text];
94
+            } elseif (is_array($results[$key])) {
95
+                $results[$key][] = $text;
96
+            } else {
97
+                $results[$key] = [$results[$key], $text];
98
+            }
99
+        };
100 100
 
101
-		return $this;
102
-	}
101
+        return $this;
102
+    }
103 103
 
104 104
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Structure/All.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@
 block discarded – undo
13 13
  */
14 14
 class All extends Parser {
15 15
 
16
-	use ArgumentsTrait;
16
+    use ArgumentsTrait;
17 17
 
18 18
     /**
19 19
      * @var Parser[]
20 20
      */
21
-	private $parsers = [];
22
-
23
-	public function __construct(...$arguments)
24
-	{
25
-		if (count($arguments) < 2) {
26
-			throw new \InvalidArgumentException('Less than 2 arguments provided');
27
-		}
28
-		$this->parsers = self::getArguments($arguments);
29
-	}
30
-
31
-	protected function parse(&$input, $offset, Context $context)
32
-	{
33
-		$length = PHP_INT_MAX;
34
-		foreach ($this->parsers as $parser) {
35
-			$match = $parser->parse($input, $offset, $context);
36
-			$length = min($length, $match->length);
37
-			if (!$match->match) {
38
-				return $this->failure($input, $offset, $length);
39
-			}
40
-		}
41
-		return $this->success($input, $offset, $length);
42
-	}
43
-
44
-	public function __toString()
45
-	{
46
-		return '( ' . join(' + ', $this->parsers) . ' )';
47
-	}
21
+    private $parsers = [];
22
+
23
+    public function __construct(...$arguments)
24
+    {
25
+        if (count($arguments) < 2) {
26
+            throw new \InvalidArgumentException('Less than 2 arguments provided');
27
+        }
28
+        $this->parsers = self::getArguments($arguments);
29
+    }
30
+
31
+    protected function parse(&$input, $offset, Context $context)
32
+    {
33
+        $length = PHP_INT_MAX;
34
+        foreach ($this->parsers as $parser) {
35
+            $match = $parser->parse($input, $offset, $context);
36
+            $length = min($length, $match->length);
37
+            if (!$match->match) {
38
+                return $this->failure($input, $offset, $length);
39
+            }
40
+        }
41
+        return $this->success($input, $offset, $length);
42
+    }
43
+
44
+    public function __toString()
45
+    {
46
+        return '( ' . join(' + ', $this->parsers) . ' )';
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Structure/Except.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,37 +14,37 @@
 block discarded – undo
14 14
  */
15 15
 class Except extends Parser {
16 16
 	
17
-	use ArgumentsTrait;
18
-
19
-	private $parser_match = null;
20
-	private $parser_not = null;
21
-
22
-	/**
23
-	 * 
24
-	 * @param Parser|string $match
25
-	 * @param Parser|string $not
26
-	 */
27
-	public function __construct($match, $not)
28
-	{
29
-		$this->parser_match = self::getArgument($match);
30
-		$this->parser_not = self::getArgument($not);
31
-	}
32
-
33
-	protected function parse(&$input, $offset, Context $context)
34
-	{
35
-		$match = $this->parser_match->parse($input, $offset, $context);
36
-		$not = $this->parser_not->parse($input, $offset, $context);
37
-
38
-		if ($match->match && !$not->match) {
39
-			return $this->success($input, $offset, $match->length, $match);
40
-		}
41
-
42
-		return $this->failure($input, $offset, min($match->length, $not->length));
43
-	}
44
-
45
-	public function __toString()
46
-	{
47
-		return '( ' . $this->parser_match . ' - ' . $this->parser_not . ' )';
48
-	}
17
+    use ArgumentsTrait;
18
+
19
+    private $parser_match = null;
20
+    private $parser_not = null;
21
+
22
+    /**
23
+     * 
24
+     * @param Parser|string $match
25
+     * @param Parser|string $not
26
+     */
27
+    public function __construct($match, $not)
28
+    {
29
+        $this->parser_match = self::getArgument($match);
30
+        $this->parser_not = self::getArgument($not);
31
+    }
32
+
33
+    protected function parse(&$input, $offset, Context $context)
34
+    {
35
+        $match = $this->parser_match->parse($input, $offset, $context);
36
+        $not = $this->parser_not->parse($input, $offset, $context);
37
+
38
+        if ($match->match && !$not->match) {
39
+            return $this->success($input, $offset, $match->length, $match);
40
+        }
41
+
42
+        return $this->failure($input, $offset, min($match->length, $not->length));
43
+    }
44
+
45
+    public function __toString()
46
+    {
47
+        return '( ' . $this->parser_match . ' - ' . $this->parser_not . ' )';
48
+    }
49 49
 
50 50
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Structure/PreferTrait.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -13,52 +13,52 @@
 block discarded – undo
13 13
  */
14 14
 trait PreferTrait {
15 15
 
16
-	/**
17
-	 * Parser used for scanning the text
18
-	 * @var Parser 
19
-	 */
20
-	private $preference = null;
16
+    /**
17
+     * Parser used for scanning the text
18
+     * @var Parser 
19
+     */
20
+    private $preference = null;
21 21
 
22
-	private function pushPreferenceToContext(Context $context)
23
-	{
24
-		if ($this->preference) {
25
-			$context->pushPreference($this->preference);
26
-		}
27
-	}
22
+    private function pushPreferenceToContext(Context $context)
23
+    {
24
+        if ($this->preference) {
25
+            $context->pushPreference($this->preference);
26
+        }
27
+    }
28 28
 
29
-	private function popPreferenceFromContext(Context $context)
30
-	{
31
-		if ($this->preference) {
32
-			$context->popPreference();
33
-		}
34
-	}
29
+    private function popPreferenceFromContext(Context $context)
30
+    {
31
+        if ($this->preference) {
32
+            $context->popPreference();
33
+        }
34
+    }
35 35
 
36
-	public function setPreference(string $preference)
37
-	{
38
-		$this->preference = $preference;
36
+    public function setPreference(string $preference)
37
+    {
38
+        $this->preference = $preference;
39 39
 
40
-		return $this;
41
-	}
40
+        return $this;
41
+    }
42 42
 
43
-	public function preferShortest()
44
-	{
45
-		$this->preference = Prefer::SHORTEST;
43
+    public function preferShortest()
44
+    {
45
+        $this->preference = Prefer::SHORTEST;
46 46
 
47
-		return $this;
48
-	}
47
+        return $this;
48
+    }
49 49
 
50
-	public function preferLongest()
51
-	{
52
-		$this->preference = Prefer::LONGEST;
50
+    public function preferLongest()
51
+    {
52
+        $this->preference = Prefer::LONGEST;
53 53
 
54
-		return $this;
55
-	}
54
+        return $this;
55
+    }
56 56
 
57
-	public function preferFirst()
58
-	{
59
-		$this->preference = Prefer::FIRST;
57
+    public function preferFirst()
58
+    {
59
+        $this->preference = Prefer::FIRST;
60 60
 
61
-		return $this;
62
-	}
61
+        return $this;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Parser/Structure/Not.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -13,24 +13,24 @@
 block discarded – undo
13 13
  */
14 14
 class Not extends Parser {
15 15
 
16
-	use ArgumentsTrait;
16
+    use ArgumentsTrait;
17 17
 
18
-	private $parser = null;
18
+    private $parser = null;
19 19
 
20
-	public function __construct($parser)
21
-	{
22
-		$this->parser = self::getArgument($parser);
23
-	}
20
+    public function __construct($parser)
21
+    {
22
+        $this->parser = self::getArgument($parser);
23
+    }
24 24
 
25
-	protected function parse(&$input, $offset, Context $context)
26
-	{
27
-		$match = $this->parser->parse($input, $offset, $context);
28
-		return $match->match ? $this->failure($input, $offset, $match->length) : $this->success($input, $offset, 0);
29
-	}
25
+    protected function parse(&$input, $offset, Context $context)
26
+    {
27
+        $match = $this->parser->parse($input, $offset, $context);
28
+        return $match->match ? $this->failure($input, $offset, $match->length) : $this->success($input, $offset, 0);
29
+    }
30 30
 
31
-	public function __toString()
32
-	{
33
-		return '!' . $this->parser;
34
-	}
31
+    public function __toString()
32
+    {
33
+        return '!' . $this->parser;
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
src/Vanderlee/Comprehend/Builder/Definition.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -11,35 +11,35 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Definition {
13 13
 
14
-	public $generator  = null;
15
-	public $validators = [];
16
-	public $processors = [];
14
+    public $generator  = null;
15
+    public $validators = [];
16
+    public $processors = [];
17 17
 
18
-	/**
19
-	 * @param Parser|callable $generator Either a parser or a function returning a parser ('generator')
20
-	 * @param callable[] $validator
21
-	 */	
22
-	public function __construct($generator = null, $validator = null)
23
-	{
24
-		//@todo validate parser and validator
18
+    /**
19
+     * @param Parser|callable $generator Either a parser or a function returning a parser ('generator')
20
+     * @param callable[] $validator
21
+     */	
22
+    public function __construct($generator = null, $validator = null)
23
+    {
24
+        //@todo validate parser and validator
25 25
 		
26
-		$this->generator  = $generator;
27
-		if (is_callable($validator)) {
26
+        $this->generator  = $generator;
27
+        if (is_callable($validator)) {
28 28
             $this->validators[] = $validator;
29 29
         }
30
-	}
30
+    }
31 31
 
32
-	public function setGenerator($parser)
33
-	{
34
-		$this->generator = $parser;
32
+    public function setGenerator($parser)
33
+    {
34
+        $this->generator = $parser;
35 35
 
36
-		return $this;
37
-	}
36
+        return $this;
37
+    }
38 38
 
39
-	public function clearValidators() {
40
-	    $this->validators = [];
39
+    public function clearValidators() {
40
+        $this->validators = [];
41 41
 
42
-	    return $this;
42
+        return $this;
43 43
     }
44 44
     public function addValidator($validator)
45 45
     {
@@ -55,27 +55,27 @@  discard block
 block discarded – undo
55 55
         return $this;
56 56
     }
57 57
 
58
-	/**
59
-	 * Build an instance of this parser definition.
60
-	 * 
61
-	 * @param Mixed[] $arguments
62
-	 * @return Implementation
63
-	 */
64
-	public function build(...$arguments)
65
-	{
66
-		return new Implementation($this, $arguments);
67
-	}
58
+    /**
59
+     * Build an instance of this parser definition.
60
+     * 
61
+     * @param Mixed[] $arguments
62
+     * @return Implementation
63
+     */
64
+    public function build(...$arguments)
65
+    {
66
+        return new Implementation($this, $arguments);
67
+    }
68 68
 
69
-	/**
70
-	 * Build an instance of this parser definition.
71
-	 * Alias of `build()` method.
72
-	 * 
73
-	 * @param Mixed[] $arguments
74
-	 * @return Implementation
75
-	 */
76
-	public function __invoke(...$arguments)
77
-	{
78
-		return $this->build(...$arguments);
79
-	}
69
+    /**
70
+     * Build an instance of this parser definition.
71
+     * Alias of `build()` method.
72
+     * 
73
+     * @param Mixed[] $arguments
74
+     * @return Implementation
75
+     */
76
+    public function __invoke(...$arguments)
77
+    {
78
+        return $this->build(...$arguments);
79
+    }
80 80
 
81 81
 }
Please login to merge, or discard this patch.