@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | $pos = 0; |
| 55 | 55 | $this->nodes = []; |
| 56 | 56 | $rFlag = PREG_OFFSET_CAPTURE + PREG_SET_ORDER; |
| 57 | - if(strlen(trim($s)) == 0) { |
|
| 57 | + if (strlen(trim($s)) == 0) { |
|
| 58 | 58 | $this->nodes[] = new Text\Plain($s, $mode); |
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | - if($mode == self::TOKEN_CONTROL) { |
|
| 62 | - if(preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
| 61 | + if ($mode == self::TOKEN_CONTROL) { |
|
| 62 | + if (preg_match('/^"(.*)"$/', trim($s), $m)) { |
|
| 63 | 63 | $this->nodes[] = new Text($m[1]); |
| 64 | 64 | } |
| 65 | 65 | else { |
@@ -68,20 +68,20 @@ discard block |
||
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | preg_match_all(self::REGEX_HTML, $s, $m, $rFlag); |
| 71 | - foreach($m as $match) { |
|
| 72 | - if($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
| 73 | - if($match[2][1] != $pos) { |
|
| 71 | + foreach ($m as $match) { |
|
| 72 | + if ($mode & self::FIND_BARDOLLAR && isset($match[2])) { |
|
| 73 | + if ($match[2][1] != $pos) { |
|
| 74 | 74 | $this->nodes[] = new Text\Plain( |
| 75 | 75 | substr($s, $pos, $match[2][1] - $pos), $mode); |
| 76 | 76 | } |
| 77 | 77 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
| 78 | 78 | $pos = $match[2][1] + strlen($match[2][0]); |
| 79 | 79 | } |
| 80 | - else if($mode & self::FIND_DOLLARVAR) { |
|
| 81 | - if($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
| 80 | + else if ($mode & self::FIND_DOLLARVAR) { |
|
| 81 | + if ($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
|
| 82 | 82 | continue; |
| 83 | 83 | } |
| 84 | - if($match[1][1] != $pos) { |
|
| 84 | + if ($match[1][1] != $pos) { |
|
| 85 | 85 | $this->nodes[] = new Text\Plain( |
| 86 | 86 | substr($s, $pos, $match[1][1] - $pos), $mode); |
| 87 | 87 | } |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | $pos = $match[1][1] + strlen($match[1][0]); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | - if($pos != strlen($s)) { |
|
| 92 | + if ($pos != strlen($s)) { |
|
| 93 | 93 | $this->nodes[] = new Text\Plain(substr($s, $pos), $mode); |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | function toHTML($escape = false) { |
| 98 | 98 | $out = []; |
| 99 | - foreach($this->nodes as $string) { |
|
| 99 | + foreach ($this->nodes as $string) { |
|
| 100 | 100 | $out[] = $string->toHTML($escape); |
| 101 | 101 | } |
| 102 | 102 | return implode("", $out); |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | function toPHP() { |
| 110 | 110 | $out = []; |
| 111 | - foreach($this->nodes as $string) { |
|
| 111 | + foreach ($this->nodes as $string) { |
|
| 112 | 112 | $out[] = $string->toPHP(); |
| 113 | 113 | } |
| 114 | 114 | return implode(".", $out); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | function doEval() { |
| 118 | - return eval('use Seufert\Hamle; return ' . $this->toPHP() . ';'); |
|
| 118 | + return eval('use Seufert\Hamle; return '.$this->toPHP().';'); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | static function varToCode($var) { |
| 122 | - if(is_array($var)) { |
|
| 122 | + if (is_array($var)) { |
|
| 123 | 123 | $code = []; |
| 124 | - foreach($var as $key => $value) { |
|
| 125 | - $code[] = self::varToCode($key) . "=>" . self::varToCode($value); |
|
| 124 | + foreach ($var as $key => $value) { |
|
| 125 | + $code[] = self::varToCode($key)."=>".self::varToCode($value); |
|
| 126 | 126 | } |
| 127 | - return 'array(' . implode(",", $code) . ')'; //remove unnecessary coma |
|
| 127 | + return 'array('.implode(",", $code).')'; //remove unnecessary coma |
|
| 128 | 128 | } |
| 129 | - if(is_bool($var)) { |
|
| 129 | + if (is_bool($var)) { |
|
| 130 | 130 | return ($var ? 'TRUE' : 'FALSE'); |
| 131 | 131 | } |
| 132 | - if(is_int($var) || is_float($var) || is_numeric($var)) { |
|
| 132 | + if (is_int($var) || is_float($var) || is_numeric($var)) { |
|
| 133 | 133 | return $var; |
| 134 | 134 | } |
| 135 | - if($var instanceof Text) { |
|
| 135 | + if ($var instanceof Text) { |
|
| 136 | 136 | return $var->toPHP(); |
| 137 | 137 | } |
| 138 | - return "'" . str_replace(['$', "'"], ['\\$', "\\'"], $var) . "'"; |
|
| 138 | + return "'".str_replace(['$', "'"], ['\\$', "\\'"], $var)."'"; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | if($mode == self::TOKEN_CONTROL) { |
| 62 | 62 | if(preg_match('/^"(.*)"$/', trim($s), $m)) { |
| 63 | 63 | $this->nodes[] = new Text($m[1]); |
| 64 | - } |
|
| 65 | - else { |
|
| 64 | + } else { |
|
| 66 | 65 | $this->nodes[] = new Text\Complex(trim($s)); |
| 67 | 66 | } |
| 68 | 67 | return; |
@@ -76,8 +75,7 @@ discard block |
||
| 76 | 75 | } |
| 77 | 76 | $this->nodes[] = new Text\Complex(substr($match[2][0], 1, -1)); |
| 78 | 77 | $pos = $match[2][1] + strlen($match[2][0]); |
| 79 | - } |
|
| 80 | - else if($mode & self::FIND_DOLLARVAR) { |
|
| 78 | + } else if($mode & self::FIND_DOLLARVAR) { |
|
| 81 | 79 | if($match[1][1] > 0 && $s[$match[1][1] - 1] === '\\') { |
| 82 | 80 | continue; |
| 83 | 81 | } |