Completed
Push — master ( 7023df...5e8065 )
by Tom
01:30
created
src/Hook/PseudoMatcher.php 1 patch
Braces   +25 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 			$parts = $this->getFuncParts($i, $tokens);
28 28
 			foreach ($this->functions as $function) {
29 29
 				$matches = $this->match($parts, $function, $element);
30
-				if ($matches === false) return false;
30
+				if ($matches === false) {
31
+					return false;
32
+				}
31 33
 			}
32 34
 		}
33 35
 		return true;
@@ -36,14 +38,17 @@  discard block
 block discarded – undo
36 38
 	private function match($parts, $function, $element) {
37 39
 		try {
38 40
 			$matches = $function->match($parts['name'], $parts['args'], $element);
39
-			if ($matches === false) return false;
40
-		}
41
-		catch (\Exception $e) {
41
+			if ($matches === false) {
42
+				return false;
43
+			}
44
+		} catch (\Exception $e) {
42 45
 			throw new \Transphporm\RunException(\Transphporm\Exception::PSEUDO, $parts['name'], $e);
43 46
 		}
44 47
 	}
45 48
 	private function getFuncParts($i, $tokens) {
46
-		if (isset($this->funcParts[$i])) return $this->funcParts[$i];
49
+		if (isset($this->funcParts[$i])) {
50
+			return $this->funcParts[$i];
51
+		}
47 52
 		$parts = [];
48 53
 		$canCache = true;
49 54
 		$parts['name'] = $this->getFuncName($tokens);
@@ -51,32 +56,40 @@  discard block
 block discarded – undo
51 56
 			//If the args are dynamic, it can't be cached as it may change between calls
52 57
 			$canCache = false;
53 58
 			$parts['args'] = $this->valueParser->parseTokens($tokens);
54
-		}
55
-		else if (count($tokens) > 1) {
59
+		} else if (count($tokens) > 1) {
56 60
 			$tokens->rewind();
57 61
 			$tokens->next();
58 62
 			$parts['args'] = $this->valueParser->parseTokens($tokens->current()['value']);
63
+		} else {
64
+			$parts['args'] = [['']];
65
+		}
66
+		if ($canCache) {
67
+			$this->funcParts[$i] = $parts;
59 68
 		}
60
-		else $parts['args'] = [['']];
61
-		if ($canCache) $this->funcParts[$i] = $parts;
62 69
 		return $parts;
63 70
 	}
64 71
 
65 72
 	private function getFuncName($tokens) {
66
-		if ($tokens->type() === Tokenizer::NAME) return $tokens->read();
73
+		if ($tokens->type() === Tokenizer::NAME) {
74
+			return $tokens->read();
75
+		}
67 76
 		return null;
68 77
 	}
69 78
 
70 79
 	public function hasFunction($name) {
71 80
 		foreach ($this->pseudo as $tokens) {
72
-			if ($name === $this->getFuncName($tokens)) return true;
81
+			if ($name === $this->getFuncName($tokens)) {
82
+				return true;
83
+			}
73 84
 		}
74 85
 	}
75 86
 
76 87
 	public function getFuncArgs($name) {
77 88
 		foreach ($this->pseudo as $i => $tokens) {
78 89
 			$parts = $this->getFuncParts($i, $tokens);
79
-			if ($name === $parts['name']) return $parts['args'];
90
+			if ($name === $parts['name']) {
91
+				return $parts['args'];
92
+			}
80 93
 		}
81 94
 	}
82 95
 }
Please login to merge, or discard this patch.