...
 
Commits (3)
bin/
vendor/
.phpunit.result.cache
bin
.php_cs.cache
\ No newline at end of file
<?php
$finder = PhpCsFixer\Finder::create()
->exclude(['vendor','lib','classes'])
->in(__DIR__);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'no_blank_lines_after_class_opening' => true,
])
->setFinder($finder);
......@@ -2,16 +2,26 @@
"name": "minds/unleash-client-php",
"type": "library",
"description": "PHP client for Unleash",
"keywords": ["unleash", "client", "minds"],
"keywords": [
"unleash",
"client",
"minds"
],
"homepage": "https://gitlab.com/minds/unleash-client-php",
"license": "MIT",
"authors": [
{
"name": "Brian Hatchet",
"email": "brian@minds.com",
"homepage": "http://www.minds.com/brianhatchet",
"role": "Developer"
}
{
"name": "Brian Hatchet",
"email": "brian@minds.com",
"homepage": "http://www.minds.com/brianhatchet",
"role": "Developer"
},
{
"name": "Emiliano Balbuena",
"email": "emiliano@minds.com",
"homepage": "http://www.minds.com/edgebal",
"role": "Developer"
}
],
"minimum-stability": "dev",
"config": {
......@@ -26,14 +36,15 @@
"zendframework/zend-serializer": "^2.9@dev"
},
"require-dev": {
"bossa/phpspec2-expect": "^3.0",
"phpspec/phpspec": "^4.0",
"phpspec/prophecy": "~1.0"
"bossa/phpspec2-expect": "^3.0",
"phpspec/phpspec": "^4.0",
"phpspec/prophecy": "~1.0",
"friendsofphp/php-cs-fixer": "^2.17@dev"
},
"autoload": {
"files": [
"src/Client.php",
"src/Unleash.php"
"src/Client.php",
"src/Unleash.php"
],
"psr-4": {
"Minds\\UnleashClient\\": "src/",
......@@ -44,4 +55,4 @@
"scripts": {
"test": "phpspec run"
}
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -8,6 +8,7 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use GuzzleHttp\Client as HttpClient;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
class ClientSpec extends ObjectBehavior
{
......@@ -16,22 +17,33 @@ class ClientSpec extends ObjectBehavior
private const TEST_INSTANCE_ID = "test_instance_id";
private const TEST_POLLING_INTERVAL_SECONDS = 15;
private const TEST_METRICS_INTERVAL_SECONDS = 20;
/** @var Config; */
private $config;
/** @var LoggerInterface */
private $logger;
/** @var HttpClient */
private $httpClient;
public function let(Config $config, HttpClient $httpClient)
{
public function let(
Config $config,
LoggerInterface $logger,
HttpClient $httpClient
) {
$this->config = $config;
$this->logger = $logger;
$this->httpClient = $httpClient;
$this->config->getApiUrl()->willReturn(ClientSpec::TEST_URL);
$this->config->getApplicationName()->willReturn(ClientSpec::TEST_APPLICATION_NAME);
$this->config->getInstanceId()->willReturn(ClientSpec::TEST_INSTANCE_ID);
$this->config->getPollingIntervalSeconds()->willReturn(ClientSpec::TEST_POLLING_INTERVAL_SECONDS);
$this->config->getMetricsIntervalSeconds()->willReturn(ClientSpec::TEST_METRICS_INTERVAL_SECONDS);
$this->config->getVersion()->willReturn(Config::VERSION);
$this->beConstructedWith($this->config, $this->httpClient);
$this->beConstructedWith($this->config, $this->logger, $this->httpClient);
}
public function it_is_initializable()
......
......@@ -64,7 +64,7 @@ class ConfigSpec extends ObjectBehavior
$applicationName = "new_application_name";
$pollingIntervalSeconds = 100;
$metricsIntervalSeconds = 200;
$metricsCacheTtl = 4500;
$metricsCacheTtl = 4500;
$this->getApiUrl()->shouldEqual(ConfigSpec::TEST_URL);
$this->getInstanceId()->shouldEqual(ConfigSpec::TEST_INSTANCE_ID);
......
......@@ -15,8 +15,7 @@ class SimpleCache extends SimpleCacheDecorator
public function __construct(
LoggerInterface $logger = null
)
{
) {
// Setup local dependencies
$this->logger = $logger ?: new Logger();
......@@ -26,10 +25,11 @@ class SimpleCache extends SimpleCacheDecorator
/**
* Builds the cache storage adapter
*
*
* @return StorageInterface
*/
protected function buildAdapter(): StorageInterface {
protected function buildAdapter(): StorageInterface
{
$this->logger->debug('Building cache storage adapter...');
// Build a simple filesystem based cache
......@@ -41,4 +41,4 @@ class SimpleCache extends SimpleCacheDecorator
return $cache;
}
}
\ No newline at end of file
}
......@@ -40,7 +40,7 @@ class Client
/**
* Calls the Unleash api and registers the client
*
*
* @return bool
*/
public function register(string $date = null): bool
......@@ -72,10 +72,10 @@ class Client
/**
* Calls the unleash api for getting feature flags.
*
*
* If HTTP 2xx, reconstitutes the feature flags and returns an array.
* Else, logs and error and returns an empty array.
*
*
* @return Feature[]
*/
public function getFeatureFlags(): array
......@@ -91,7 +91,7 @@ class Client
) {
$data = json_decode((string) $response->getBody(), true);
return array_map(function($feature) {
return array_map(function ($feature) {
return new Feature($feature);
}, $data['features']);
}
......
......@@ -45,7 +45,7 @@ class Config
/**
* Gets the current version number of the library
*
*
* @return string
*/
public function getVersion(): string
......@@ -55,7 +55,7 @@ class Config
/**
* Gets the Unleash server URL
*
*
* @return string
*/
public function getApiUrl(): string
......@@ -65,7 +65,7 @@ class Config
/**
* Sets the Unleash server URL
*
*
* @return Config
*/
public function setApiUrl(string $apiUrl): Config
......@@ -76,7 +76,7 @@ class Config
/**
* Gets the Unleash instance ID
*
*
* @return string
*/
public function getInstanceId(): string
......@@ -86,7 +86,7 @@ class Config
/**
* Sets the Unleash instance ID
*
*
* @return Config
*/
public function setInstanceID(string $instanceId): Config
......@@ -107,7 +107,7 @@ class Config
/**
* Sets the Unleash application name
*
*
* @return Config
*/
public function setApplicationName(string $applicationName): Config
......@@ -128,7 +128,7 @@ class Config
/**
* Sets the Unleash polling interval in seconds
*
*
* @return Config
*/
public function setPollingIntervalSeconds(int $pollingIntervalSeconds): Config
......@@ -149,7 +149,7 @@ class Config
/**
* Sets the Unleash metrics send interval in seconds
*
*
* @return Config
*/
public function setMetricsIntervalSeconds(int $metricsIntervalSeconds): Config
......@@ -160,7 +160,7 @@ class Config
/**
* Gets the cache TTL in seconds
*
*
* @return int
*/
public function getCacheTtl(): int
......@@ -170,7 +170,7 @@ class Config
/**
* Sets the cache TTL in seconds
*
*
* @return Config
*/
public function setCacheTtl(int $cacheTtl): Config
......
......@@ -69,7 +69,8 @@ class Unleash
* Fetches the current collection of feature flags from server, and
* caches it
*/
public function fetch(): void {
public function fetch(): void
{
$this->logger->debug('Fetching feature flags from server...');
foreach ($this->client->getFeatureFlags() as $feature) {
......