Skip to content

Commit e8e3536

Browse files
committed
Clean up LDCLient ctor
1 parent a96222f commit e8e3536

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/LaunchDarkly/LDClient.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class LDClient {
2727
*/
2828
public function __construct($apiKey, $options = []) {
2929
$this->_apiKey = $apiKey;
30-
$this->_baseUri = $options['base_uri'] ? rtrim($options['base_uri'], '/') : self::DEFAULT_BASE_URI;
30+
if (!isset($options['base_uri'])) {
31+
$this->_baseUri = self::DEFAULT_BASE_URI;
32+
} else {
33+
$this->_baseUri = rtrim($options['base_uri'], '/');
34+
}
3135
if (!isset($options['timeout'])) {
3236
$options['timeout'] = 3;
3337
}
@@ -68,21 +72,26 @@ protected function _getFlag($key, $user, $default) {
6872
}
6973
}
7074

71-
protected function _make_client() {
75+
protected function _make_client($options) {
7276
$client = new \GuzzleHttp\Client([
7377
'base_url' => $this->_baseUri,
7478
'defaults' => [
7579
'headers' => [
7680
'Authorization' => "api_key {$this->_apiKey}",
7781
'Content-Type' => 'application/json',
78-
'User-Agent' => 'PHPClient/' . VERSION
82+
'User-Agent' => 'PHPClient/' . self::VERSION
7983
],
8084
'timeout' => $options['timeout'],
8185
'connect_timeout' => $options['connect_timeout']
8286
]
8387
]);
8488

85-
$csOptions = $options['cache_storage'] ? ['storage' => $options['cache_storage']] : [];
89+
if (!isset($options['cache_storage'])) {
90+
$csOptions = [];
91+
} else {
92+
$csOptions = ['storage' => $options['cache_storage']];
93+
}
94+
8695
CacheSubscriber::attach($client, $csOptions);
8796
return $client;
8897
}

tests/LDClientTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace LaunchDarkly\Tests;
3+
4+
use LaunchDarkly\LDClient;
5+
6+
class LDClientTest extends \PHPUnit_Framework_TestCase {
7+
8+
public function testDefaultCtor() {
9+
$client = new LDClient("BOGUS_API_KEY");
10+
}
11+
}
12+

0 commit comments

Comments
 (0)