@@ -18,27 +18,7 @@ abstract class CodeScanner extends Scanner
1818
1919 protected $ commentsPrefixes = [];
2020
21- protected $ functions = [
22- 'gettext ' => 'gettext ' ,
23- '_ ' => 'gettext ' ,
24- '__ ' => 'gettext ' ,
25- 'ngettext ' => 'ngettext ' ,
26- 'n__ ' => 'ngettext ' ,
27- 'pgettext ' => 'pgettext ' ,
28- 'p__ ' => 'pgettext ' ,
29- 'dgettext ' => 'dgettext ' ,
30- 'd__ ' => 'dgettext ' ,
31- 'dngettext ' => 'dngettext ' ,
32- 'dn__ ' => 'dngettext ' ,
33- 'dpgettext ' => 'dpgettext ' ,
34- 'dp__ ' => 'dpgettext ' ,
35- 'npgettext ' => 'npgettext ' ,
36- 'np__ ' => 'npgettext ' ,
37- 'dnpgettext ' => 'dnpgettext ' ,
38- 'dnp__ ' => 'dnpgettext ' ,
39- 'noop ' => 'gettext ' ,
40- 'noop__ ' => 'gettext ' ,
41- ];
21+ protected $ functions = [];
4222
4323 /**
4424 * @param array $functions [fnName => handler]
@@ -93,122 +73,25 @@ abstract public function getFunctionsScanner(): FunctionsScannerInterface;
9373
9474 protected function handleFunction (ParsedFunction $ function )
9575 {
96- $ name = $ function ->getName ();
97- $ handler = $ this ->functions [$ name ] ?? null ;
76+ $ handler = $ this ->getFunctionHandler ($ function );
9877
9978 if (is_null ($ handler )) {
10079 return ;
10180 }
10281
103- $ translation = call_user_func ([ $ this , $ handler] , $ function );
82+ $ translation = call_user_func ($ handler , $ function );
10483
10584 if ($ translation && $ this ->addReferences ) {
10685 $ translation ->getReferences ()->add ($ function ->getFilename (), $ function ->getLine ());
10786 }
10887 }
10988
110- protected function gettext (ParsedFunction $ function ): ?Translation
111- {
112- if (!$ this ->checkFunction ($ function , 1 )) {
113- return null ;
114- }
115- list ($ original ) = $ function ->getArguments ();
116-
117- return $ this ->addComments (
118- $ function ,
119- $ this ->saveTranslation (null , null , $ original )
120- );
121- }
122-
123- protected function ngettext (ParsedFunction $ function ): ?Translation
124- {
125- if (!$ this ->checkFunction ($ function , 2 )) {
126- return null ;
127- }
128- list ($ original , $ plural ) = $ function ->getArguments ();
129-
130- return $ this ->addComments (
131- $ function ,
132- $ this ->saveTranslation (null , null , $ original , $ plural )
133- );
134- }
135-
136- protected function pgettext (ParsedFunction $ function ): ?Translation
137- {
138- if (!$ this ->checkFunction ($ function , 2 )) {
139- return null ;
140- }
141- list ($ context , $ original ) = $ function ->getArguments ();
142-
143- return $ this ->addComments (
144- $ function ,
145- $ this ->saveTranslation (null , $ context , $ original )
146- );
147- }
148-
149- protected function dgettext (ParsedFunction $ function ): ?Translation
150- {
151- if (!$ this ->checkFunction ($ function , 2 )) {
152- return null ;
153- }
154- list ($ domain , $ original ) = $ function ->getArguments ();
155-
156- return $ this ->addComments (
157- $ function ,
158- $ this ->saveTranslation ($ domain , null , $ original )
159- );
160- }
161-
162- protected function dpgettext (ParsedFunction $ function ): ?Translation
163- {
164- if (!$ this ->checkFunction ($ function , 3 )) {
165- return null ;
166- }
167- list ($ domain , $ context , $ original ) = $ function ->getArguments ();
168-
169- return $ this ->addComments (
170- $ function ,
171- $ this ->saveTranslation ($ domain , $ context , $ original )
172- );
173- }
174-
175- protected function npgettext (ParsedFunction $ function ): ?Translation
176- {
177- if (!$ this ->checkFunction ($ function , 3 )) {
178- return null ;
179- }
180- list ($ context , $ original , $ plural ) = $ function ->getArguments ();
181-
182- return $ this ->addComments (
183- $ function ,
184- $ this ->saveTranslation (null , $ context , $ original , $ plural )
185- );
186- }
187-
188- protected function dngettext (ParsedFunction $ function ): ?Translation
189- {
190- if (!$ this ->checkFunction ($ function , 3 )) {
191- return null ;
192- }
193- list ($ domain , $ original , $ plural ) = $ function ->getArguments ();
194-
195- return $ this ->addComments (
196- $ function ,
197- $ this ->saveTranslation ($ domain , null , $ original , $ plural )
198- );
199- }
200-
201- protected function dnpgettext (ParsedFunction $ function ): ?Translation
89+ protected function getFunctionHandler (ParsedFunction $ function ): ?callable
20290 {
203- if (!$ this ->checkFunction ($ function , 4 )) {
204- return null ;
205- }
206- list ($ domain , $ context , $ original , $ plural ) = $ function ->getArguments ();
91+ $ name = $ function ->getName ();
92+ $ handler = $ this ->functions [$ name ] ?? null ;
20793
208- return $ this ->addComments (
209- $ function ,
210- $ this ->saveTranslation ($ domain , $ context , $ original , $ plural )
211- );
94+ return is_null ($ handler ) ? null : [$ this , $ handler ];
21295 }
21396
21497 protected function addComments (ParsedFunction $ function , ?Translation $ translation ): ?Translation
0 commit comments