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

wp-graphql / wp-graphql-woocommerce / 5604998080

pending completion
5604998080

push

github

web-flow
fix: Several minor obscured syntax errors fix (#771)

* fix: Several minor obscured syntax errors fix

* fix: more fixes.

* fix: attribute "name" and "label" inconsistencies resolved.

12 of 12 new or added lines in 7 files covered. (100.0%)

10302 of 12428 relevant lines covered (82.89%)

54.03 hits per line

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

89.66
/includes/utils/class-transfer-session-handler.php
1
<?php
2
/**
3
 * Handles data for the current customers session.
4
 *
5
 * @package WPGraphQL\WooCommerce\Utils
6
 * @since 0.12.5
7
 */
8

9
namespace WPGraphQL\WooCommerce\Utils;
10

11
/**
12
 * Class Transfer_Session_Handler
13
 *
14
 * @property string|int $_customer_id
15
 *
16
 * @package WPGraphQL\WooCommerce\Utils
17
 */
18
class Transfer_Session_Handler extends \WC_Session_Handler {
19
        /**
20
         * Setup cookie and customer ID.
21
         *
22
         * @return void
23
         */
24
        public function init_session_cookie() {
25
                // Retrieve a customer's previous session from DB.
26
                $this->set_session_expiration();
3✔
27
                $this->_customer_id = $this->generate_customer_id();
3✔
28
                $this->_data        = $this->get_session_data();
3✔
29
        }
30

31
        /**
32
         * Return true, if valid credential exists
33
         *
34
         * @return bool
35
         */
36
        protected function verify_auth_request_credentials_exists() {
37
                $possible_nonces = array_values( Protected_Router::get_nonce_names() );
3✔
38
                // Return false if not nonce names set.
39
                if ( empty( $possible_nonces ) ) {
3✔
40
                        return false;
×
41
                }
42

43
                // Return false if no matching nonces found in query parameters.
44
                $query_params = array_keys( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
3✔
45
                if ( empty( array_intersect( $possible_nonces, $query_params ) ) ) {
3✔
46
                        return false;
3✔
47
                }
48

49
                return true;
3✔
50
        }
51

52
        /**
53
         * Returns "session_id" if proper conditions met.
54
         *
55
         * @return int|string
56
         */
57
        protected function get_posted_session_id() {
58
                if ( ! $this->verify_auth_request_credentials_exists() ) {
3✔
59
                        return 0;
3✔
60
                }
61
                if ( ! isset( $_REQUEST['session_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
3✔
62
                        return 0;
2✔
63
                }
64

65
                return sanitize_text_field( wp_unslash( $_REQUEST['session_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
3✔
66
        }
67

68
        /**
69
         * Reads in customer ID from query parameters if specific conditions are met otherwise
70
         * a guest ID are generated as usual.
71
         *
72
         * @return int|string
73
         */
74
        public function generate_customer_id() {
75
                $session_id = $this->get_posted_session_id();
3✔
76
                if ( 0 !== $session_id ) {
3✔
77
                        return $session_id;
3✔
78
                }
79

80
                return parent::generate_customer_id();
3✔
81
        }
82

83
        /**
84
         * Returns client session ID.
85
         *
86
         * @return string
87
         */
88
        public function get_client_session_id() {
89
                $session_id = $this->get_posted_session_id();
1✔
90
                /**
91
                 * Get session data.
92
                 *
93
                 * @var null|array{ client_session_id: string, client_session_id_expiration: int } $session_data
94
                 */
95
                $session_data = 0 !== $session_id ? $this->get_session( (string) $session_id ) : null;
1✔
96

97
                if ( ! empty( $session_data ) ) {
1✔
98
                        $client_session_id            = ! empty( $session_data['client_session_id'] ) ? $session_data['client_session_id'] : false;
×
99
                        $client_session_id_expiration = ! empty( $session_data['client_session_id_expiration'] ) ? $session_data['client_session_id_expiration'] : 0;
×
100
                } else {
101
                        $client_session_id            = $this->get( 'client_session_id', false );
1✔
102
                        $client_session_id_expiration = absint( $this->get( 'client_session_id_expiration', 0 ) );
1✔
103
                }
104

105
                if ( false !== $client_session_id && time() < $client_session_id_expiration ) {
1✔
106
                        // @phpstan-ignore-next-line
107
                        return $client_session_id;
1✔
108
                }
109

110
                return '';
1✔
111
        }
112
}
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