diff --git a/lib/recurly/base_client.php b/lib/recurly/base_client.php index 6562e723..78d0dabe 100644 --- a/lib/recurly/base_client.php +++ b/lib/recurly/base_client.php @@ -8,7 +8,7 @@ abstract class BaseClient private $_baseUrl = 'https://v3.recurly.com'; private $_api_key; - protected $_http; + protected $http; /** * Constructor @@ -18,7 +18,7 @@ abstract class BaseClient public function __construct(string $api_key) { $this->_api_key = $api_key; - $this->_http = new HttpAdapter; + $this->http = new HttpAdapter; } /** @@ -61,7 +61,7 @@ private function _getResponse(string $method, string $path, ?array $body = [], ? $request = new \Recurly\Request($method, $path, $body, $params); $url = $this->_buildPath($path, $params); - list($result, $response_header) = $this->_http->execute($method, $url, $body, $this->_headers()); + list($result, $response_header) = $this->http->execute($method, $url, $body, $this->_headers()); // TODO: The $request should be added to the $response $response = new \Recurly\Response($result); diff --git a/lib/recurly/http_adapter.php b/lib/recurly/http_adapter.php index 4ec87411..ae7c9480 100644 --- a/lib/recurly/http_adapter.php +++ b/lib/recurly/http_adapter.php @@ -1,13 +1,13 @@ $method, 'content' => $body, - ]); + ] + ); $headers_str = ""; - foreach ($headers as $k => $v) - { + foreach ($headers as $k => $v) { $headers_str .= "$k: $v\r\n"; } $options['header'] = $headers_str; diff --git a/lib/recurly/recurly_traits.php b/lib/recurly/recurly_traits.php index bf4770df..4e5f00bd 100644 --- a/lib/recurly/recurly_traits.php +++ b/lib/recurly/recurly_traits.php @@ -4,13 +4,25 @@ trait RecurlyTraits { + /** + * Generates User-Agent for API requests + * + * @return string Recurly client User-Agent string + */ protected static function getUserAgent(): string { $php_version = phpversion(); return "Recurly/" . \Recurly\Version::CURRENT . "; php " . $php_version; } - protected static function encodeApiKey($key): string + /** + * Base64 encodes the API key + * + * @param string $key The API key to encode + * + * @return string base64 encoded API key + */ + protected static function encodeApiKey(string $key): string { return base64_encode($key); } diff --git a/tests/mock_client.php b/tests/mock_client.php index 667b4000..f0f371ec 100644 --- a/tests/mock_client.php +++ b/tests/mock_client.php @@ -14,7 +14,7 @@ class MockClient extends BaseClient public function __construct() { parent::__construct("apikey"); - $this->_http = (new Generator())->getMock(HttpAdapter::class); + $this->http = (new Generator())->getMock(HttpAdapter::class); } protected function apiVersion(): string @@ -55,7 +55,7 @@ public function deleteResource(string $resource_id): \Recurly\EmptyResource public function addScenario($method, $url, $body, $result, $status): void { $resp_header = self::_generateRespHeader($status); - $this->_http->method('execute')->with( + $this->http->method('execute')->with( $method, $url, $body, @@ -65,7 +65,7 @@ public function addScenario($method, $url, $body, $result, $status): void public function clearScenarios(): void { - $this->_http = (new Generator())->getMock(HttpAdapter::class); + $this->http = (new Generator())->getMock(HttpAdapter::class); } private static function _generateRespHeader($status): array