1 | <?php |
||
12 | class Client |
||
13 | { |
||
14 | /** |
||
15 | * $apiEndpoint. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $apiEndpoint = 'http://api.every8d.com/API21/HTTP'; |
||
20 | |||
21 | /** |
||
22 | * $credit. |
||
23 | * |
||
24 | * @var float |
||
25 | */ |
||
26 | public $credit = null; |
||
27 | |||
28 | /** |
||
29 | * __construct. |
||
30 | * |
||
31 | * @param string $userId |
||
32 | * @param string $password |
||
33 | * @param \Http\Client\HttpClient $httpClient |
||
34 | * @param \Http\Message\MessageFactory $messageFactory |
||
35 | */ |
||
36 | 2 | public function __construct($userId, $password, HttpClient $httpClient = null, MessageFactory $messageFactory = null) |
|
37 | { |
||
38 | 2 | $this->userId = $userId; |
|
|
|||
39 | 2 | $this->password = $password; |
|
40 | 2 | $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
|
41 | 2 | $this->messageFactory = $messageFactory ?: MessageFactoryDiscovery::find(); |
|
42 | 2 | } |
|
43 | |||
44 | /** |
||
45 | * setCredit. |
||
46 | * |
||
47 | * @param string $credit |
||
48 | */ |
||
49 | 2 | protected function setCredit($credit) |
|
50 | { |
||
51 | 2 | $this->credit = (float) $credit; |
|
52 | |||
53 | 2 | return $this; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * credit. |
||
58 | * |
||
59 | * @return float |
||
60 | */ |
||
61 | 2 | public function credit() |
|
79 | |||
80 | /** |
||
81 | * send. |
||
82 | * |
||
83 | * @param array $params |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 1 | public function send($params) |
|
112 | |||
113 | /** |
||
114 | * isValidResponse. |
||
115 | * |
||
116 | * @param string $response |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | 2 | protected function isValidResponse($response) |
|
124 | |||
125 | /** |
||
126 | * doRequest. |
||
127 | * |
||
128 | * @param string $uri |
||
129 | * @param array $params |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 2 | protected function doRequest($uri, $params) |
|
145 | } |
||
146 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: