33namespace WP_CLI \I18n ;
44
55use Gettext \Translation ;
6- use Gettext \Utils \JsFunctionsScanner as GettextJsFunctionsScanner ;
76use Peast \Peast ;
87use Peast \Syntax \Node ;
98use Peast \Traverser ;
109
11- final class JsFunctionsScanner extends GettextJsFunctionsScanner {
10+ final class JsFunctionsScanner {
11+
12+ /**
13+ * The JavaScript code to parse.
14+ *
15+ * @var string
16+ */
17+ protected $ code ;
1218
1319 /**
1420 * If not false, comments will be extracted.
@@ -17,6 +23,15 @@ final class JsFunctionsScanner extends GettextJsFunctionsScanner {
1723 */
1824 private $ extract_comments = false ;
1925
26+ /**
27+ * Constructor.
28+ *
29+ * @param string $code JavaScript code to parse.
30+ */
31+ public function __construct ( $ code ) {
32+ $ this ->code = $ code ;
33+ }
34+
2035 /**
2136 * Holds a list of source code comments already added to a string.
2237 *
@@ -31,21 +46,21 @@ final class JsFunctionsScanner extends GettextJsFunctionsScanner {
3146 *
3247 * @param mixed $tag
3348 */
34- public function enableCommentsExtraction ( $ tag = '' ) {
49+ public function enableCommentsExtraction ( $ tag = '' ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Legacy method name for compatibility.
3550 $ this ->extract_comments = $ tag ;
3651 }
3752
3853 /**
3954 * Disable comments extraction.
4055 */
41- public function disableCommentsExtraction () {
56+ public function disableCommentsExtraction () { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Legacy method name for compatibility.
4257 $ this ->extract_comments = false ;
4358 }
4459
4560 /**
4661 * {@inheritdoc}
4762 */
48- public function saveGettextFunctions ( $ translations , array $ options ) {
63+ public function saveGettextFunctions ( $ translations , array $ options ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Legacy method name for compatibility.
4964 // Ignore multiple translations for now.
5065 // @todo Add proper support for multiple translations.
5166 if ( is_array ( $ translations ) ) {
@@ -283,7 +298,7 @@ function ( $node ) use ( &$translations, $options, $scanner ) {
283298 *
284299 * @return array|bool Array containing the name and comments of the identifier if resolved. False if not.
285300 */
286- private function resolveExpressionCallee ( Node \CallExpression $ node ) {
301+ private function resolveExpressionCallee ( Node \CallExpression $ node ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Legacy method name for compatibility.
287302 $ callee = $ node ->getCallee ();
288303
289304 // If the callee is a simple identifier it can simply be returned.
@@ -393,7 +408,7 @@ private function resolveExpressionCallee( Node\CallExpression $node ) {
393408 *
394409 * @return bool Whether or not the comment precedes the node.
395410 */
396- private function commentPrecedesNode ( Node \Comment $ comment , Node \Node $ node ) {
411+ private function commentPrecedesNode ( Node \Comment $ comment , Node \Node $ node ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Legacy method name for compatibility.
397412 // Comments should be on the same or an earlier line than the translation.
398413 if ( $ node ->getLocation ()->getStart ()->getLine () - $ comment ->getLocation ()->getEnd ()->getLine () > 1 ) {
399414 return false ;
0 commit comments