1 | <?php |
||
15 | class Client implements HttpContract |
||
16 | { |
||
17 | use ConfigurationTrait, |
||
18 | HttpTrait; |
||
19 | |||
20 | /** |
||
21 | * Consumer key |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $consumerKey; |
||
26 | |||
27 | /** |
||
28 | * Consumer secret |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $consumerSecret; |
||
33 | |||
34 | /** |
||
35 | * Access token |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $token; |
||
40 | |||
41 | /** |
||
42 | * Access token secret |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $tokenSecret; |
||
47 | |||
48 | /** |
||
49 | * Default search term |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $defaultTerm = 'bar'; |
||
54 | |||
55 | /** |
||
56 | * Default location |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $defaultLocation = 'Chicago, IL'; |
||
61 | |||
62 | /** |
||
63 | * Default search limit |
||
64 | * |
||
65 | * @var integer |
||
66 | */ |
||
67 | protected $searchLimit = 3; |
||
68 | |||
69 | /** |
||
70 | * Create new client |
||
71 | * |
||
72 | * @param array $options |
||
73 | */ |
||
74 | public function __construct(array $options = array()) |
||
91 | |||
92 | /** |
||
93 | * Creates default http client with appropriate authorization configuration. |
||
94 | * |
||
95 | * @return HttpClient |
||
96 | */ |
||
97 | public function createDefaultHttpClient() |
||
114 | |||
115 | /** |
||
116 | * Fetches a specific business by id. |
||
117 | * |
||
118 | * @param string $businessId |
||
119 | * @param array $parameters |
||
120 | * |
||
121 | * @return stdClass |
||
122 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
123 | */ |
||
124 | public function getBusiness($businessId, $parameters = []) |
||
131 | |||
132 | /** |
||
133 | * Sends a request instance and returns a response instance. |
||
134 | * |
||
135 | * WARNING: This method does not attempt to catch exceptions caused by HTTP |
||
136 | * errors! It is recommended to wrap this method in a try/catch block. |
||
137 | * |
||
138 | * @param RequestInterface $request |
||
139 | * @return ResponseInterface |
||
140 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
141 | */ |
||
142 | public function getResponse(RequestInterface $request) |
||
152 | |||
153 | /** |
||
154 | * Fetches results from the Business Search API. |
||
155 | * |
||
156 | * @param array $parameters |
||
157 | * |
||
158 | * @return stdClass |
||
159 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
160 | */ |
||
161 | public function search($parameters = []) |
||
174 | |||
175 | /** |
||
176 | * Fetches results from the Business Search API by Phone. |
||
177 | * |
||
178 | * @param array $parameters |
||
179 | * |
||
180 | * @return stdClass |
||
181 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
182 | */ |
||
183 | public function searchByPhone($parameters = []) |
||
190 | |||
191 | /** |
||
192 | * Set default location |
||
193 | * |
||
194 | * @param string $location |
||
195 | * |
||
196 | * @return Client |
||
197 | */ |
||
198 | public function setDefaultLocation($location) |
||
204 | |||
205 | /** |
||
206 | * Set default term |
||
207 | * |
||
208 | * @param string $term |
||
209 | * |
||
210 | * @return Client |
||
211 | */ |
||
212 | public function setDefaultTerm($term) |
||
218 | |||
219 | /** |
||
220 | * Set search limit |
||
221 | * |
||
222 | * @param integer $limit |
||
223 | * |
||
224 | * @return Client |
||
225 | */ |
||
226 | public function setSearchLimit($limit) |
||
234 | } |
||
235 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.