1 | <?php |
||
7 | class WhitespaceFormatter extends SpecializedFormatter { |
||
|
|||
8 | |||
9 | private static $BLOCK_CONTEXT_MAPPING = [ |
||
10 | T_IF => 'ifelse', |
||
11 | T_ELSEIF => 'ifelse', |
||
12 | T_WHILE => 'while', |
||
13 | T_FOREACH => 'foreach', |
||
14 | T_FOR => 'for', |
||
15 | T_CATCH => 'catch' |
||
16 | ]; |
||
17 | |||
18 | private static $SYNTAX = [ |
||
19 | ')' => 'close', |
||
20 | '(' => 'open', |
||
21 | ',' => 'comma', |
||
22 | ';' => 'semicolon', |
||
23 | ':' => 'colon', |
||
24 | '=>' => 'arrow', |
||
25 | '->' => 'arrow', // function invocation |
||
26 | '::' => 'doublecolon', // function invocation |
||
27 | '?' => 'questionmark' |
||
28 | ]; |
||
29 | |||
30 | 2 | protected function doVisitToken(Token $token) { |
|
38 | |||
39 | 2 | private function applyKeywords(Token $token) { |
|
40 | 2 | if ($this->matcher->isKeyword($token)) { |
|
41 | 1 | $this->defaultFormatter->addPostWrite(' '); |
|
42 | } |
||
43 | 2 | } |
|
44 | |||
45 | 2 | private function applyAssignments(Token $token) { |
|
46 | 2 | if ($this->matcher->isAssignment($token)) { |
|
47 | 2 | $this->whitespaceBeforeAfter('assignment', 'assignments'); |
|
48 | } |
||
49 | 2 | } |
|
50 | |||
51 | 2 | private function applyOperators(Token $token) { |
|
52 | 2 | if ($this->matcher->isOperator($token)) { |
|
53 | 2 | $this->whitespaceBeforeAfter('binary', 'operators'); |
|
54 | } |
||
55 | 2 | } |
|
56 | |||
57 | 2 | private function applyPrefixPostfix(Token $token) { |
|
58 | 2 | if ($token->type == T_INC || $token->type == T_DEC) { |
|
59 | // pre |
||
60 | 1 | if ($this->nextToken->type == T_VAR) { |
|
61 | $this->whitespaceBeforeAfter('prefix', 'operators'); |
||
62 | } |
||
63 | |||
64 | // post |
||
65 | 1 | else if ($this->prevToken->type == T_VAR) { |
|
66 | $this->whitespaceBeforeAfter('postfix', 'operators'); |
||
67 | } |
||
68 | } |
||
69 | 2 | } |
|
70 | |||
71 | /** |
||
72 | * @TODO |
||
73 | * @param Token $token |
||
74 | */ |
||
75 | 2 | private function applyUnary(Token $token) { |
|
78 | |||
79 | 2 | private function applySyntax(Token $token) { |
|
80 | 2 | if (array_key_exists($token->contents, self::$SYNTAX)) { |
|
81 | 2 | $key = self::$SYNTAX[$token->contents]; |
|
82 | 2 | $group = $this->context->getGroupContext(); |
|
94 | |||
95 | 2 | private function findContext(Token $token) { |
|
128 | |||
129 | 2 | private function whitespaceBeforeAfter($key, $context = 'default') { |
|
138 | |||
139 | } |
||
140 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.