Skip to content

Commit 7e6af47

Browse files
committed
fix - allow all the reserved works as parameters - kokororin/vscode-phpfmt#174
1 parent 91b1d28 commit 7e6af47

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

fmt.stub.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,6 +4790,32 @@ private function hasLnInBlock($tkns, $ptr, $start, $end) {
47904790
}
47914791

47924792
class ResizeSpaces extends FormatterPass {
4793+
4794+
public static $reservedWords = [
4795+
'__halt_compiler' => 1,
4796+
'abstract' => 1, 'and' => 1, 'array' => 1, 'as' => 1,
4797+
'break' => 1,
4798+
'callable' => 1, 'case' => 1, 'catch' => 1, 'class' => 1, 'clone' => 1, 'const' => 1, 'continue' => 1,
4799+
'declare' => 1, 'default' => 1, 'die' => 1, 'do' => 1,
4800+
'echo' => 1, 'else' => 1, 'elseif' => 1, 'empty' => 1, 'enddeclare' => 1, 'endfor' => 1, 'endforeach' => 1, 'endif' => 1, 'endswitch' => 1, 'endwhile' => 1, 'eval' => 1, 'exit' => 1, 'extends' => 1,
4801+
'final' => 1, 'for' => 1, 'foreach' => 1, 'function' => 1,
4802+
'global' => 1, 'goto' => 1,
4803+
'if' => 1, 'implements' => 1, 'include' => 1, 'include_once' => 1, 'instanceof' => 1, 'insteadof' => 1, 'interface' => 1, 'isset' => 1,
4804+
'list' => 1,
4805+
'namespace' => 1, 'new' => 1,
4806+
'or' => 1,
4807+
'print' => 1, 'private' => 1, 'protected' => 1, 'public' => 1,
4808+
'require' => 1, 'require_once' => 1, 'return' => 1,
4809+
'static' => 1, 'switch' => 1,
4810+
'throw' => 1, 'trait' => 1, 'try' => 1,
4811+
'unset' => 1, 'use' => 1, 'var' => 1,
4812+
'while' => 1, 'xor' => 1,
4813+
'match' => 1, 'readonly' => 1,
4814+
'enum' => 1, 'yield' => 1, "yield from" => 1,
4815+
"true" => 1, "false" => 1, "null" => false,
4816+
"self" => 1, "parent" => 1, "static" =>1
4817+
];
4818+
47934819
public function candidate($source, $foundTokens) {
47944820
$tkns = token_get_all($source);
47954821

@@ -4973,7 +4999,7 @@ public function format($source) {
49734999
break;
49745000

49755001
case ST_COLON:
4976-
list($prevId) = $this->inspectToken(-1);
5002+
list($prevId, $prevText) = $this->inspectToken(-1);
49775003
list($nextId, $nextText) = $this->inspectToken(+1);
49785004

49795005
if (
@@ -5022,7 +5048,7 @@ public function format($source) {
50225048
} elseif (T_STRING === $prevId) {
50235049
$this->appendCode($text . ' ');
50245050
break;
5025-
} elseif (T_CLASS === $prevId) {
5051+
} elseif (isset(static::$reservedWords[strtolower($prevText)])) {
50265052
$this->appendCode($text . ' ');
50275053
break;
50285054
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
//passes:ResizeSpaces
3+
4+
bar(empty: false, CLASS: false);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
//passes:ResizeSpaces
3+
4+
bar(empty: false, CLASS: false);

0 commit comments

Comments
 (0)