@@ -10,11 +10,11 @@ class PhpCodeStore extends CodeStore
1010{
1111 //--------------------------------------------------------------------------------------------------------------------
1212 /**
13- * The levels of nested switch statements .
13+ * The levels of nested default clauses .
1414 *
1515 * @var int[]
1616 */
17- private $ switchLevel = [];
17+ private $ defaultLevel = [];
1818
1919 //--------------------------------------------------------------------------------------------------------------------
2020 /**
@@ -48,6 +48,39 @@ protected function indentationMode(string $line): int
4848 return $ mode ;
4949 }
5050
51+ //--------------------------------------------------------------------------------------------------------------------
52+ /**
53+ * Decrements indent level of the current switch statement (if any).
54+ */
55+ private function defaultLevelDecrement (): void
56+ {
57+ if (!empty ($ this ->defaultLevel ) && $ this ->defaultLevel [sizeof ($ this ->defaultLevel ) - 1 ]>0 )
58+ {
59+ $ this ->defaultLevel [sizeof ($ this ->defaultLevel ) - 1 ]--;
60+ }
61+ }
62+
63+ //--------------------------------------------------------------------------------------------------------------------
64+ /**
65+ * Increments indent level of the current switch statement (if any).
66+ */
67+ private function defaultLevelIncrement (): void
68+ {
69+ if (!empty ($ this ->defaultLevel ))
70+ {
71+ $ this ->defaultLevel [sizeof ($ this ->defaultLevel ) - 1 ]++;
72+ }
73+ }
74+
75+ //--------------------------------------------------------------------------------------------------------------------
76+ /**
77+ * Returns true if the indent level of the current switch statement (if any) is zero. Otherwise, returns false.
78+ */
79+ private function defaultLevelIsZero (): bool
80+ {
81+ return (!empty ($ this ->defaultLevel ) && $ this ->defaultLevel [sizeof ($ this ->defaultLevel ) - 1 ]==0 );
82+ }
83+
5184 //--------------------------------------------------------------------------------------------------------------------
5285 /**
5386 * Returns the indentation mode based blocks of code.
@@ -56,26 +89,26 @@ protected function indentationMode(string $line): int
5689 *
5790 * @return int
5891 */
59- protected function indentationModeBlock (string $ line ): int
92+ private function indentationModeBlock (string $ line ): int
6093 {
6194 $ mode = 0 ;
6295
6396 if (substr ($ line , -1 , 1 )=='{ ' )
6497 {
6598 $ mode |= self ::C_INDENT_INCREMENT_AFTER ;
6699
67- $ this ->switchLevelIncrement ();
100+ $ this ->defaultLevelIncrement ();
68101 }
69102
70103 if (substr ($ line , 0 , 1 )=='} ' )
71104 {
72- $ this ->switchLevelDecrement ();
105+ $ this ->defaultLevelDecrement ();
73106
74- if ($ this ->switchLevelIsZero ())
107+ if ($ this ->defaultLevelIsZero ())
75108 {
76109 $ mode |= self ::C_INDENT_DECREMENT_BEFORE_DOUBLE ;
77110
78- array_pop ($ this ->switchLevel );
111+ array_pop ($ this ->defaultLevel );
79112 }
80113 else
81114 {
@@ -98,18 +131,15 @@ private function indentationModeSwitch(string $line): int
98131 {
99132 $ mode = 0 ;
100133
101- if (substr ($ line , 0 , 7 )=='switch ' )
102- {
103- $ this ->switchLevel [] = 0 ;
104- }
105-
106134 if (substr ($ line , 0 , 5 )=='case ' )
107135 {
108136 $ mode |= self ::C_INDENT_INCREMENT_AFTER ;
109137 }
110138
111139 if (substr ($ line , 0 , 8 )=='default: ' )
112140 {
141+ $ this ->defaultLevel [] = 0 ;
142+
113143 $ mode |= self ::C_INDENT_INCREMENT_AFTER ;
114144 }
115145
@@ -121,39 +151,6 @@ private function indentationModeSwitch(string $line): int
121151 return $ mode ;
122152 }
123153
124- //--------------------------------------------------------------------------------------------------------------------
125- /**
126- * Decrements indent level of the current switch statement (if any).
127- */
128- private function switchLevelDecrement (): void
129- {
130- if (!empty ($ this ->switchLevel ) && $ this ->switchLevel [sizeof ($ this ->switchLevel ) - 1 ]>0 )
131- {
132- $ this ->switchLevel [sizeof ($ this ->switchLevel ) - 1 ]--;
133- }
134- }
135-
136- //--------------------------------------------------------------------------------------------------------------------
137- /**
138- * Increments indent level of the current switch statement (if any).
139- */
140- private function switchLevelIncrement (): void
141- {
142- if (!empty ($ this ->switchLevel ))
143- {
144- $ this ->switchLevel [sizeof ($ this ->switchLevel ) - 1 ]++;
145- }
146- }
147-
148- //--------------------------------------------------------------------------------------------------------------------
149- /**
150- * Returns true if the indent level of the current switch statement (if any) is zero. Otherwise, returns false.
151- */
152- private function switchLevelIsZero (): bool
153- {
154- return (!empty ($ this ->switchLevel ) && $ this ->switchLevel [sizeof ($ this ->switchLevel ) - 1 ]==0 );
155- }
156-
157154 //--------------------------------------------------------------------------------------------------------------------
158155}
159156
0 commit comments