Completed
Pull Request — master (#140)
by
unknown
01:22
created

Options::getFollowRedirects()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
/**
3
 * WooCommerce REST API HTTP Client Options
4
 *
5
 * @category HttpClient
6
 * @package  Automattic/WooCommerce
7
 */
8
9
namespace Automattic\WooCommerce\HttpClient;
10
11
/**
12
 * REST API HTTP Client Options class.
13
 *
14
 * @package Automattic/WooCommerce
15
 */
16
class Options
17
{
18
19
    /**
20
     * Default WooCommerce REST API version.
21
     */
22
    const VERSION = 'v3';
23
24
    /**
25
     * Default request timeout.
26
     */
27
    const TIMEOUT = 15;
28
29
    /**
30
     * Default WP API prefix.
31
     * Including leading and trailing slashes.
32
     */
33
    const WP_API_PREFIX = '/wp-json/';
34
35
    /**
36
     * Default User Agent.
37
     * No version number.
38
     */
39
    const USER_AGENT = 'WooCommerce API Client-PHP';
40
41
    /**
42
     * Options.
43
     *
44
     * @var array
45
     */
46
    private $options;
47
48
    /**
49
     * Initialize HTTP client options.
50
     *
51
     * @param array $options Client options.
52
     */
53
    public function __construct($options)
54
    {
55
        $this->options = $options;
56
    }
57
58
    /**
59
     * Get API version.
60
     *
61
     * @return string
62
     */
63
    public function getVersion()
64
    {
65
        return isset($this->options['version']) ? $this->options['version'] : self::VERSION;
66
    }
67
68
    /**
69
     * Check if need to verify SSL.
70
     *
71
     * @return bool
72
     */
73
    public function verifySsl()
74
    {
75
        return isset($this->options['verify_ssl']) ? (bool) $this->options['verify_ssl'] : true;
76
    }
77
78
    /**
79
     * Get timeout.
80
     *
81
     * @return int
82
     */
83
    public function getTimeout()
84
    {
85
        return isset($this->options['timeout']) ? (int) $this->options['timeout'] : self::TIMEOUT;
86
    }
87
88
    /**
89
     * Basic Authentication as query string.
90
     * Some old servers are not able to use CURLOPT_USERPWD.
91
     *
92
     * @return bool
93
     */
94
    public function isQueryStringAuth()
95
    {
96
        return isset($this->options['query_string_auth']) ? (bool) $this->options['query_string_auth'] : false;
97
    }
98
99
    /**
100
     * Check if is WP REST API.
101
     *
102
     * @return bool
103
     */
104
    public function isWPAPI()
105
    {
106
        return isset($this->options['wp_api']) ? (bool) $this->options['wp_api'] : false;
107
    }
108
109
    /**
110
     * Custom API Prefix for WP API.
111
     *
112
     * @return string
113
     */
114
    public function apiPrefix()
115
    {
116
        return isset($this->options['wp_api_prefix']) ? $this->options['wp_api_prefix'] : self::WP_API_PREFIX;
117
    }
118
119
    /**
120
     * oAuth timestamp.
121
     *
122
     * @return string
123
     */
124
    public function oauthTimestamp()
125
    {
126
        return isset($this->options['oauth_timestamp']) ? $this->options['oauth_timestamp'] : \time();
127
    }
128
129
    /**
130
     * Custom user agent.
131
     * 
132
     * @return string
133
     */
134
    public function userAgent()
135
    {
136
        return isset($this->options['user_agent']) ? $this->options['user_agent'] : self::USER_AGENT;
137
    }
138
139
    /**
140
     * Get follow redirects
141
     *
142
     * @return bool
143
     */
144
    public function getFollowRedirects()
145
    {
146
        return isset($this->options['follow_redirects']) ? (bool)$this->options['follow_redirects'] : false;
147
148
    }
149
}
150