• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 23779262545

31 Mar 2026 03:37AM UTC coverage: 91.718% (+1.0%) from 90.757%
23779262545

push

github

web-flow
perf: Migrate type descriptions to lazy lambdas (#1005)

* perf: Migrate type descriptions to lazy lambdas

Convert all eager description strings from:
  'description' => __( '...', 'wp-graphql-woocommerce' ),
to deferred lambdas:
  'description' => static function () { return __( '...', 'wp-graphql-woocommerce' ); },

This defers the __() translation call until the description is actually
needed (e.g. during schema introspection), avoiding unnecessary
translation overhead on every GraphQL request. Mirrors the pattern
used in WPGraphQL core.

1206 descriptions converted across 169 files.

* chore: Linter compliances met

3598 of 3630 new or added lines in 167 files covered. (99.12%)

1 existing line in 1 file now uncovered.

18328 of 19983 relevant lines covered (91.72%)

145.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.73
/includes/type/object/class-payment-token-types.php
1
<?php
2
/**
3
 * WPObject Type - Payment_Token_Types
4
 *
5
 * Registers PaymentToken Interface child types.
6
 *
7
 * @package WPGraphQL\WooCommerce\Type\WPObject
8
 * @since   0.12.4
9
 */
10

11
namespace WPGraphQL\WooCommerce\Type\WPObject;
12

13
use WPGraphQL\WooCommerce\Type\WPInterface\Payment_Token_Interface;
14

15
/**
16
 * Class Payment_Token_Types
17
 */
18
class Payment_Token_Types {
19
        /**
20
         * Registers types
21
         *
22
         * @return void
23
         */
24
        public static function register() {
25
                register_graphql_object_type(
285✔
26
                        'PaymentToken',
285✔
27
                        [
285✔
28
                                'description' => static function () {
285✔
NEW
29
                                        return __( 'A payment token', 'wp-graphql-woocommerce' );
×
30
                                },
285✔
31
                                'interfaces'  => [ 'PaymentTokenInterface' ],
285✔
32
                                'fields'      => [],
285✔
33
                        ]
285✔
34
                );
285✔
35
                register_graphql_object_type(
285✔
36
                        'PaymentTokenCC',
285✔
37
                        [
285✔
38
                                'description' => static function () {
285✔
39
                                        return __( 'A credit card payment token', 'wp-graphql-woocommerce' );
2✔
40
                                },
285✔
41
                                'interfaces'  => [ 'PaymentTokenInterface' ],
285✔
42
                                'fields'      => Payment_Token_Interface::get_fields( self::get_credit_card_fields() ),
285✔
43
                        ]
285✔
44
                );
285✔
45

46
                register_graphql_object_type(
285✔
47
                        'PaymentTokenECheck',
285✔
48
                        [
285✔
49
                                'description' => static function () {
285✔
50
                                        return __( 'An electronic check payment token', 'wp-graphql-woocommerce' );
2✔
51
                                },
285✔
52
                                'interfaces'  => [ 'PaymentTokenInterface' ],
285✔
53
                                'fields'      => Payment_Token_Interface::get_fields( self::get_e_check_fields() ),
285✔
54
                        ]
285✔
55
                );
285✔
56
        }
57

58
        /**
59
         * Returns field definitions for PaymentTokenECheck  type.
60
         *
61
         * @return array
62
         */
63
        public static function get_e_check_fields() {
64
                return [
285✔
65
                        'last4' => [
285✔
66
                                'type'        => 'Integer',
285✔
67
                                'description' => static function () {
285✔
68
                                        return __( 'Last 4 digits of the stored account number', 'wp-graphql-woocommerce' );
2✔
69
                                },
285✔
70
                                'resolve'     => static function ( $source ) {
285✔
71
                                        return ! empty( $source->get_last4() ) ? $source->get_last4() : null;
2✔
72
                                },
285✔
73
                        ],
285✔
74
                ];
285✔
75
        }
76

77
        /**
78
         * Returns field definitions for PaymentTokenCC type.
79
         *
80
         * @return array
81
         */
82
        public static function get_credit_card_fields() {
83
                return [
285✔
84
                        'cardType'    => [
285✔
85
                                'type'        => 'String',
285✔
86
                                'description' => static function () {
285✔
87
                                        return __( 'Card type (visa, mastercard, etc)', 'wp-graphql-woocommerce' );
2✔
88
                                },
285✔
89
                                'resolve'     => static function ( $source ) {
285✔
90
                                        return ! empty( $source->get_card_type() ) ? $source->get_card_type() : null;
1✔
91
                                },
285✔
92
                        ],
285✔
93
                        'expiryYear'  => [
285✔
94
                                'type'        => 'String',
285✔
95
                                'description' => static function () {
285✔
96
                                        return __( 'Card\'s expiration year.', 'wp-graphql-woocommerce' );
2✔
97
                                },
285✔
98
                                'resolve'     => static function ( $source ) {
285✔
99
                                        return ! empty( $source->get_expiry_year() ) ? $source->get_expiry_year() : null;
1✔
100
                                },
285✔
101
                        ],
285✔
102
                        'expiryMonth' => [
285✔
103
                                'type'        => 'String',
285✔
104
                                'description' => static function () {
285✔
105
                                        return __( 'Card\'s expiration month', 'wp-graphql-woocommerce' );
2✔
106
                                },
285✔
107
                                'resolve'     => static function ( $source ) {
285✔
108
                                        return ! empty( $source->get_expiry_month() ) ? $source->get_expiry_month() : null;
1✔
109
                                },
285✔
110
                        ],
285✔
111
                        'last4'       => [
285✔
112
                                'type'        => 'Integer',
285✔
113
                                'description' => static function () {
285✔
114
                                        return __( 'Last 4 digits of the stored credit card number', 'wp-graphql-woocommerce' );
2✔
115
                                },
285✔
116
                                'resolve'     => static function ( $source ) {
285✔
117
                                        return ! empty( $source->get_last4() ) ? $source->get_last4() : null;
2✔
118
                                },
285✔
119
                        ],
285✔
120
                ];
285✔
121
        }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc