transport = $transport; } /** * Run the check. * * @return array Keys: ok, message, property, scopes, hmac_required, attribution_window_days. */ public function test(): array { $response = $this->transport->send( 'verify', array() ); if ( ! $response->is_ok() ) { return array( 'ok' => false, 'message' => $response->error(), ); } // The property is a nested object, not a flat property_id. Reading it from the wrong level is a // silent failure: the call succeeded, so the screen would report a healthy connection to a // property it could not name. $property = $response->get( 'property', array() ); $property = is_array( $property ) ? $property : array(); $scopes = $response->get( 'scopes', array() ); $scopes = is_array( $scopes ) ? array_map( 'strval', $scopes ) : array(); return array( 'ok' => true, 'message' => __( 'Connected.', 'adpix-analytics' ), 'property' => array( 'id' => isset( $property['id'] ) && is_scalar( $property['id'] ) ? (string) $property['id'] : '', 'name' => isset( $property['name'] ) && is_scalar( $property['name'] ) ? (string) $property['name'] : '', 'timezone' => isset( $property['timezone'] ) && is_scalar( $property['timezone'] ) ? (string) $property['timezone'] : '', ), 'scopes' => $scopes, 'hmac_required' => (bool) $response->get( 'hmac_required', false ), 'attribution_window_days' => (int) $response->get( 'attribution_window_days', 0 ), ); } }