Passed
Pull Request — master (#3)
by Chris
01:53
created
php/hamle/Grammar/Parser.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     private $peg_currPos          = 0;
68 68
     private $peg_reportedPos      = 0;
69 69
     private $peg_cachedPos        = 0;
70
-    private $peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
70
+    private $peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false);
71 71
     private $peg_maxFailPos       = 0;
72 72
     private $peg_maxFailExpected  = array();
73 73
     private $peg_silentFails      = 0;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
       $this->peg_currPos          = 0;
79 79
       $this->peg_reportedPos      = 0;
80 80
       $this->peg_cachedPos        = 0;
81
-      $this->peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
81
+      $this->peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false);
82 82
       $this->peg_maxFailPos       = 0;
83 83
       $this->peg_maxFailExpected  = array();
84 84
       $this->peg_silentFails      = 0;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     private function expected($description) {
122 122
       throw $this->peg_buildException(
123 123
         null,
124
-        array(array("type" => "other", "description" => $description )),
124
+        array(array("type" => "other", "description" => $description)),
125 125
         $this->peg_reportedPos
126 126
       );
127 127
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
       if ($this->peg_cachedPos !== $pos) {
153 153
         if ($this->peg_cachedPos > $pos) {
154 154
           $this->peg_cachedPos = 0;
155
-          $this->peg_cachedPosDetails = array( "line" => 1, "column" => 1, "seenCR" => false );
155
+          $this->peg_cachedPosDetails = array("line" => 1, "column" => 1, "seenCR" => false);
156 156
         }
157 157
         $this->peg_advancePos($this->peg_cachedPosDetails, $this->peg_cachedPos, $pos);
158 158
         $this->peg_cachedPos = $pos;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         $foundDesc = $found ? json_encode($found) : "end of input";
215 215
 
216
-        $message = "Expected " . $expectedDesc . " but " . $foundDesc . " found.";
216
+        $message = "Expected ".$expectedDesc." but ".$foundDesc." found.";
217 217
       }
218 218
 
219 219
       return new SyntaxError(
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
                                                   array_walk_recursive($i, function($a) use (&$return) { $return[] = $a; });
303 303
                                                   return $return;
304 304
                                          }
305
-    private function peg_f2($text) { return new \Seufert\Hamle\TextNode\StringLit(join('',$text)); }
305
+    private function peg_f2($text) { return new \Seufert\Hamle\TextNode\StringLit(join('', $text)); }
306 306
     private function peg_f3($body) { return $body; }
307 307
     private function peg_f4($name) {
308 308
             return new \Seufert\Hamle\TextNode\ScopeId(null, null, new \Seufert\Hamle\TextNode\ModelParam($name)); }
309
-    private function peg_f5($expr, $chain) { if(!$chain) return $expr;
309
+    private function peg_f5($expr, $chain) { if (!$chain) return $expr;
310 310
                            $top = array_pop($chain);
311
-                           while($chain) { $top = array_pop($chain)->withChain($top); } return $expr->withChain($top); }
311
+                           while ($chain) { $top = array_pop($chain)->withChain($top); } return $expr->withChain($top); }
312 312
     private function peg_f6($sub) { return $sub; }
313 313
     private function peg_f7($filter) { return $filter; }
314 314
     private function peg_f8($name) { return new \Seufert\Hamle\TextNode\ModelParam($name, null); }
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     private function peg_f15($query) { return new \Seufert\Hamle\TextNode\Query($query); }
322 322
     private function peg_f16($id, $query) { return array_merge([['q'=>'type', 'id'=> $id]], $query); }
323 323
     private function peg_f17($query) { return array_merge([['q'=>'type', 'id'=> '*']], $query); }
324
-    private function peg_f18($rel, $sub) { return \Seufert\Hamle\TextNode\RelQuery::for($rel, $sub); }
324
+    private function peg_f18($rel, $sub) { return \Seufert\Hamle\TextNode\RelQuery::for ($rel, $sub); }
325 325
     private function peg_f19($id) { return ['q'=>'id', 'id'=> $id]; }
326 326
     private function peg_f20($id) { return ['q'=>'type', 'id'=> $id]; }
327 327
     private function peg_f21($id) { return ['q'=>'tag', 'id'=> $id]; }
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
     private function peg_f29($func, $args) { return new \Seufert\Hamle\TextNode\FilterFunc($func, null, $args); }
336 336
     private function peg_f30($func) { return new \Seufert\Hamle\TextNode\FilterFunc($func); }
337 337
     private function peg_f31($arg) { return $arg; }
338
-    private function peg_f32($s, $n, $d) { return \Seufert\Hamle\TextNode\FloatLit((float)"$s$n.$d"); }
338
+    private function peg_f32($s, $n, $d) { return \Seufert\Hamle\TextNode\FloatLit((float) "$s$n.$d"); }
339 339
     private function peg_f33($parts) { return new \Seufert\Hamle\TextNode\StringLit($parts[1]); }
340 340
     private function peg_f34($chars) { return join('', $chars); }
341 341
     private function peg_f35($char_) { return $char_; }
342 342
     private function peg_f36($sequence) { return $sequence; }
343 343
     private function peg_f37($char) { return $char; }
344
-    private function peg_f38($n) { return (int)join('', $n); }
345
-    private function peg_f39($sign, $n) { return new \Seufert\Hamle\TextNode\IntLit((int)($sign.join('', $n))); }
346
-    private function peg_f40($name) { return join('',$name); }
344
+    private function peg_f38($n) { return (int) join('', $n); }
345
+    private function peg_f39($sign, $n) { return new \Seufert\Hamle\TextNode\IntLit((int) ($sign.join('', $n))); }
346
+    private function peg_f40($name) { return join('', $name); }
347 347
     private function peg_f41($p, $s) { return $p.join('', $s); }
348 348
     private function peg_f42($s) { return join('', $s); }
349 349
     private function peg_f43($c) { return $c; }
350
-    private function peg_f44($char_) { return str_replace(['n', 'r', 't'], ['\\n','\\r','\\t'], $char_); }
350
+    private function peg_f44($char_) { return str_replace(['n', 'r', 't'], ['\\n', '\\r', '\\t'], $char_); }
351 351
 
352 352
     private function peg_parseHtmlInput() {
353 353
 
@@ -2715,77 +2715,77 @@  discard block
 block discarded – undo
2715 2715
 
2716 2716
     $this->peg_FAILED = new \stdClass;
2717 2717
     $this->peg_c0 = "{";
2718
-    $this->peg_c1 = array( "type" => "literal", "value" => "{", "description" => "\"{\"" );
2718
+    $this->peg_c1 = array("type" => "literal", "value" => "{", "description" => "\"{\"");
2719 2719
     $this->peg_c2 = "}";
2720
-    $this->peg_c3 = array( "type" => "literal", "value" => "}", "description" => "\"}\"" );
2720
+    $this->peg_c3 = array("type" => "literal", "value" => "}", "description" => "\"}\"");
2721 2721
     $this->peg_c4 = "$";
2722
-    $this->peg_c5 = array( "type" => "literal", "value" => "$", "description" => "\"$\"" );
2722
+    $this->peg_c5 = array("type" => "literal", "value" => "$", "description" => "\"$\"");
2723 2723
     $this->peg_c6 = "|";
2724
-    $this->peg_c7 = array( "type" => "literal", "value" => "|", "description" => "\"|\"" );
2724
+    $this->peg_c7 = array("type" => "literal", "value" => "|", "description" => "\"|\"");
2725 2725
     $this->peg_c8 = "(";
2726
-    $this->peg_c9 = array( "type" => "literal", "value" => "(", "description" => "\"(\"" );
2726
+    $this->peg_c9 = array("type" => "literal", "value" => "(", "description" => "\"(\"");
2727 2727
     $this->peg_c10 = ")";
2728
-    $this->peg_c11 = array( "type" => "literal", "value" => ")", "description" => "\")\"" );
2728
+    $this->peg_c11 = array("type" => "literal", "value" => ")", "description" => "\")\"");
2729 2729
     $this->peg_c12 = "[";
2730
-    $this->peg_c13 = array( "type" => "literal", "value" => "[", "description" => "\"[\"" );
2730
+    $this->peg_c13 = array("type" => "literal", "value" => "[", "description" => "\"[\"");
2731 2731
     $this->peg_c14 = "]";
2732
-    $this->peg_c15 = array( "type" => "literal", "value" => "]", "description" => "\"]\"" );
2732
+    $this->peg_c15 = array("type" => "literal", "value" => "]", "description" => "\"]\"");
2733 2733
     $this->peg_c16 = "*";
2734
-    $this->peg_c17 = array( "type" => "literal", "value" => "*", "description" => "\"*\"" );
2734
+    $this->peg_c17 = array("type" => "literal", "value" => "*", "description" => "\"*\"");
2735 2735
     $this->peg_c18 = " ";
2736
-    $this->peg_c19 = array( "type" => "literal", "value" => " ", "description" => "\" \"" );
2736
+    $this->peg_c19 = array("type" => "literal", "value" => " ", "description" => "\" \"");
2737 2737
     $this->peg_c20 = "/^[><]/";
2738
-    $this->peg_c21 = array( "type" => "class", "value" => "[><]", "description" => "[><]" );
2738
+    $this->peg_c21 = array("type" => "class", "value" => "[><]", "description" => "[><]");
2739 2739
     $this->peg_c22 = "#";
2740
-    $this->peg_c23 = array( "type" => "literal", "value" => "#", "description" => "\"#\"" );
2740
+    $this->peg_c23 = array("type" => "literal", "value" => "#", "description" => "\"#\"");
2741 2741
     $this->peg_c24 = ",";
2742
-    $this->peg_c25 = array( "type" => "literal", "value" => ",", "description" => "\",\"" );
2742
+    $this->peg_c25 = array("type" => "literal", "value" => ",", "description" => "\",\"");
2743 2743
     $this->peg_c26 = ".";
2744
-    $this->peg_c27 = array( "type" => "literal", "value" => ".", "description" => "\".\"" );
2744
+    $this->peg_c27 = array("type" => "literal", "value" => ".", "description" => "\".\"");
2745 2745
     $this->peg_c28 = "^";
2746
-    $this->peg_c29 = array( "type" => "literal", "value" => "^", "description" => "\"^\"" );
2746
+    $this->peg_c29 = array("type" => "literal", "value" => "^", "description" => "\"^\"");
2747 2747
     $this->peg_c30 = "@";
2748
-    $this->peg_c31 = array( "type" => "literal", "value" => "@", "description" => "\"@\"" );
2748
+    $this->peg_c31 = array("type" => "literal", "value" => "@", "description" => "\"@\"");
2749 2749
     $this->peg_c32 = ":";
2750
-    $this->peg_c33 = array( "type" => "literal", "value" => ":", "description" => "\":\"" );
2750
+    $this->peg_c33 = array("type" => "literal", "value" => ":", "description" => "\":\"");
2751 2751
     $this->peg_c34 = "-";
2752
-    $this->peg_c35 = array( "type" => "literal", "value" => "-", "description" => "\"-\"" );
2752
+    $this->peg_c35 = array("type" => "literal", "value" => "-", "description" => "\"-\"");
2753 2753
     $this->peg_c36 = ">";
2754
-    $this->peg_c37 = array( "type" => "literal", "value" => ">", "description" => "\">\"" );
2754
+    $this->peg_c37 = array("type" => "literal", "value" => ">", "description" => "\">\"");
2755 2755
     $this->peg_c38 = "!";
2756
-    $this->peg_c39 = array( "type" => "literal", "value" => "!", "description" => "\"!\"" );
2756
+    $this->peg_c39 = array("type" => "literal", "value" => "!", "description" => "\"!\"");
2757 2757
     $this->peg_c40 = "/^[0-9]/";
2758
-    $this->peg_c41 = array( "type" => "class", "value" => "[0-9]", "description" => "[0-9]" );
2759
-    $this->peg_c42 = array("type" => "other", "description" => "string" );
2758
+    $this->peg_c41 = array("type" => "class", "value" => "[0-9]", "description" => "[0-9]");
2759
+    $this->peg_c42 = array("type" => "other", "description" => "string");
2760 2760
     $this->peg_c43 = "\"";
2761
-    $this->peg_c44 = array( "type" => "literal", "value" => "\"", "description" => "\"\\\"\"" );
2761
+    $this->peg_c44 = array("type" => "literal", "value" => "\"", "description" => "\"\\\"\"");
2762 2762
     $this->peg_c45 = "'";
2763
-    $this->peg_c46 = array( "type" => "literal", "value" => "'", "description" => "\"'\"" );
2763
+    $this->peg_c46 = array("type" => "literal", "value" => "'", "description" => "\"'\"");
2764 2764
     $this->peg_c47 = "\\";
2765
-    $this->peg_c48 = array( "type" => "literal", "value" => "\\", "description" => "\"\\\\\"" );
2766
-    $this->peg_c49 = array("type" => "any", "description" => "any character" );
2765
+    $this->peg_c48 = array("type" => "literal", "value" => "\\", "description" => "\"\\\\\"");
2766
+    $this->peg_c49 = array("type" => "any", "description" => "any character");
2767 2767
     $this->peg_c50 = "/^[a-zA-Z_]/";
2768
-    $this->peg_c51 = array( "type" => "class", "value" => "[a-zA-Z_]", "description" => "[a-zA-Z_]" );
2768
+    $this->peg_c51 = array("type" => "class", "value" => "[a-zA-Z_]", "description" => "[a-zA-Z_]");
2769 2769
     $this->peg_c52 = "/^[a-zA-Z_-]/";
2770
-    $this->peg_c53 = array( "type" => "class", "value" => "[a-zA-Z_-]", "description" => "[a-zA-Z_-]" );
2770
+    $this->peg_c53 = array("type" => "class", "value" => "[a-zA-Z_-]", "description" => "[a-zA-Z_-]");
2771 2771
     $this->peg_c54 = "/^[0-9a-zA-Z_-]/";
2772
-    $this->peg_c55 = array( "type" => "class", "value" => "[0-9a-zA-Z_-]", "description" => "[0-9a-zA-Z_-]" );
2772
+    $this->peg_c55 = array("type" => "class", "value" => "[0-9a-zA-Z_-]", "description" => "[0-9a-zA-Z_-]");
2773 2773
     $this->peg_c56 = "/^[^{\\\$]/";
2774
-    $this->peg_c57 = array( "type" => "class", "value" => "[{\$]", "description" => "[{\$]" );
2774
+    $this->peg_c57 = array("type" => "class", "value" => "[{\$]", "description" => "[{\$]");
2775 2775
     $this->peg_c58 = "/^[a-z]/";
2776
-    $this->peg_c59 = array( "type" => "class", "value" => "[a-z]", "description" => "[a-z]" );
2776
+    $this->peg_c59 = array("type" => "class", "value" => "[a-z]", "description" => "[a-z]");
2777 2777
     $this->peg_c60 = "/^[^{]/";
2778
-    $this->peg_c61 = array( "type" => "class", "value" => "[{]", "description" => "[{]" );
2778
+    $this->peg_c61 = array("type" => "class", "value" => "[{]", "description" => "[{]");
2779 2779
     $this->peg_c62 = "/^[\\n\\r\\x{2028}\\x{2029}]/";
2780
-    $this->peg_c63 = array( "type" => "class", "value" => "[\n\r\x{2028}\x{2029}]", "description" => "[\n\r\x{2028}\x{2029}]" );
2780
+    $this->peg_c63 = array("type" => "class", "value" => "[\n\r\x{2028}\x{2029}]", "description" => "[\n\r\x{2028}\x{2029}]");
2781 2781
     $this->peg_c64 = "/^['\"\\\\bfnrtv]/";
2782
-    $this->peg_c65 = array( "type" => "class", "value" => "['\"\\bfnrtv]", "description" => "['\"\\bfnrtv]" );
2782
+    $this->peg_c65 = array("type" => "class", "value" => "['\"\\bfnrtv]", "description" => "['\"\\bfnrtv]");
2783 2783
 
2784
-    $peg_startRuleFunctions = array( 'HtmlInput' => array($this, "peg_parseHtmlInput"), 'CodeInput' => array($this, "peg_parseCodeInput"), 'ControlInput' => array($this, "peg_parseControlInput") );
2784
+    $peg_startRuleFunctions = array('HtmlInput' => array($this, "peg_parseHtmlInput"), 'CodeInput' => array($this, "peg_parseCodeInput"), 'ControlInput' => array($this, "peg_parseControlInput"));
2785 2785
     $peg_startRuleFunction  = array($this, "peg_parseHtmlInput");
2786 2786
     if (isset($options["startRule"])) {
2787 2787
       if (!(isset($peg_startRuleFunctions[$options["startRule"]]))) {
2788
-        throw new \Exception("Can't start parsing from rule \"" + $options["startRule"] + "\".");
2788
+        throw new \Exception("Can't start parsing from rule \"" +$options["startRule"] + "\".");
2789 2789
       }
2790 2790
 
2791 2791
       $peg_startRuleFunction = $peg_startRuleFunctions[$options["startRule"]];
@@ -2799,7 +2799,7 @@  discard block
 block discarded – undo
2799 2799
       return $peg_result;
2800 2800
     } else {
2801 2801
       if ($peg_result !== $this->peg_FAILED && $this->peg_currPos < $this->input_length) {
2802
-        $this->peg_fail(array("type" => "end", "description" => "end of input" ));
2802
+        $this->peg_fail(array("type" => "end", "description" => "end of input"));
2803 2803
       }
2804 2804
 
2805 2805
       $exception = $this->peg_buildException(null, $this->peg_maxFailExpected, $this->peg_maxFailPos);
Please login to merge, or discard this patch.
php/hamle/Text/Filter.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -47,23 +47,23 @@  discard block
 block discarded – undo
47 47
 
48 48
   function __construct($s, Text $what) {
49 49
     var_dump($s, $what);
50
-    if(preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
50
+    if (preg_match("/^([a-z_]+)(?:\\((?P<vars>.*)\\))?(?:\\|(?P<chained>.+?))?$/", $s, $m)) {
51 51
       $this->filter = $m[1];
52 52
       $this->vars = isset($m['vars']) && strlen($m['vars']) ? explode(',', $m['vars']) : [];
53
-      foreach($this->vars as $k=>$v)
54
-        $this->vars[$k] = str_replace("&comma;",',',$v);
55
-      if(isset($m['chained']) && strlen($m['chained'])) {
56
-        $this->chained = new Filter($m['chained'],$what);
53
+      foreach ($this->vars as $k=>$v)
54
+        $this->vars[$k] = str_replace("&comma;", ',', $v);
55
+      if (isset($m['chained']) && strlen($m['chained'])) {
56
+        $this->chained = new Filter($m['chained'], $what);
57 57
       }
58 58
     } else {
59 59
       throw new ParseError("Unable to parse filter expression \"$s\"");
60 60
     }
61
-    if(method_exists(Filter::class, $this->filter)) {
61
+    if (method_exists(Filter::class, $this->filter)) {
62 62
       $this->filter = Filter::class.'::'.$this->filter;
63
-    } elseif(in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) {
64
-    } elseif($this->filter === 'json') {
63
+    } elseif (in_array($this->filter, ['round', 'strtoupper', 'strtolower', 'ucfirst'])) {
64
+    } elseif ($this->filter === 'json') {
65 65
       $this->filter = 'json_encode';
66
-    } elseif(self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) {
66
+    } elseif (self::$filterResolver && $filter = (self::$filterResolver)($this->filter)) {
67 67
       $this->filter = $filter;
68 68
     } else {
69 69
       throw new ParseError("Unknown Filter Type \"{$this->filter}\"");
@@ -72,24 +72,24 @@  discard block
 block discarded – undo
72 72
   }
73 73
 
74 74
   function toHTML($escape = false) {
75
-    if($escape)
76
-      return "<?=htmlspecialchars(" .$this->toPHP() . ")?>";
77
-    return "<?=" . $this->toPHP() . "?>";
75
+    if ($escape)
76
+      return "<?=htmlspecialchars(".$this->toPHP().")?>";
77
+    return "<?=".$this->toPHP()."?>";
78 78
   }
79 79
 
80 80
   function toPHPpre() {
81 81
     $pre = '';
82
-    if($this->chained)
82
+    if ($this->chained)
83 83
       $pre = $this->chained->toPHPpre();
84 84
     return "$pre{$this->filter}(";
85 85
   }
86 86
 
87 87
   function toPHPpost() {
88 88
     $post = '';
89
-    if($this->chained)
89
+    if ($this->chained)
90 90
       $post = $this->chained->toPHPpost();
91 91
     $o = '';
92
-    foreach($this->vars as $v)
92
+    foreach ($this->vars as $v)
93 93
       $o .= ','.$this->varToCode($v);
94 94
     return "$o)$post";
95 95
   }
@@ -104,24 +104,24 @@  discard block
 block discarded – undo
104 104
 
105 105
   static function itersplit($v, $sep = ",") {
106 106
     $o = [];
107
-    foreach(explode($sep, $v) as $k=>$i) {
108
-      if($i)
109
-        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k];
107
+    foreach (explode($sep, $v) as $k=>$i) {
108
+      if ($i)
109
+        $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k];
110 110
     }
111 111
     return new WrapArray($o);
112 112
   }
113 113
 
114 114
   static function newlinebr($v) {
115
-    return str_replace("\n","<br />\n",$v);
115
+    return str_replace("\n", "<br />\n", $v);
116 116
   }
117 117
 
118 118
   static function replace($v, $src, $dst) {
119
-    return str_replace($src,$dst,$v);
119
+    return str_replace($src, $dst, $v);
120 120
   }
121 121
 
122 122
   static function ascents($v) {
123
-    $v = str_replace(['$',' ',','],'', $v);
124
-    return (int) round($v * 100,0);
123
+    $v = str_replace(['$', ' ', ','], '', $v);
124
+    return (int) round($v * 100, 0);
125 125
   }
126 126
 
127 127
 }
Please login to merge, or discard this patch.