Skip to content

Commit

Permalink
Fix factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilari Moragrega committed Mar 9, 2018
1 parent d1e1c93 commit 6d6713f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 15 additions & 17 deletions spec/MonitorFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ function it_can_built_an_empty_monitor()
function it_can_built_an_working_monitor(LoggerInterface $logger)
{
$monitor = $this->create([
[
'hostname' => 'fooserver',
'default_tags' => ['foo' => 'bar'],
'logger' => [
'instance' => $logger,
'debug' => true,
'level' => LogLevel::WARNING,
'metrics' => true,
'events' => true,
],
'datadog' => [
'metrics' => true,
'events' => true,
'host' => '10.0.0.1',
'port' => 8822,
],
]
'hostname' => 'fooserver',
'default_tags' => ['foo' => 'bar'],
'logger' => [
'instance' => $logger,
'debug' => true,
'level' => LogLevel::WARNING,
'metrics' => true,
'events' => true,
],
'datadog' => [
'metrics' => true,
'events' => true,
'host' => '10.0.0.1',
'port' => 8822,
],
]);

$monitor->shouldBeAnInstanceOf(Monitor::class);
Expand Down
8 changes: 5 additions & 3 deletions src/MonitorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ class MonitorFactory
* See the method 'mergeDefaults' for info on the config format
*
* @param array $config
*
* @return Monitor
*/
public static function create(array $config = [])
{
$config = self::mergeDefaults($config);
$metricFactory = new MetricFactory($config['default_tags']);
$eventFactory = new EventFactory($config['hostname']);
$logger = $config['logger']['instance'] instanceof LoggerInterface ? $config['logger']['instance'] : null;
$debug = $config['logger']['debug'];
$debug = $config['logger']['debug'];
$monitor = new Monitor($metricFactory, $eventFactory, $debug ? $logger : null);

if (!empty($config['datadog']['metrics'])) {
Expand Down Expand Up @@ -55,7 +57,7 @@ public static function create(array $config = [])
*/
private static function mergeDefaults(array $config)
{
return array_merge($config, [
return array_merge([
'hostname' => gethostname(), # Hostname of the server
'default_tags' => [], # A key-value array with default tags for metrics and events
'logger' => [
Expand All @@ -71,6 +73,6 @@ private static function mergeDefaults(array $config)
'host' => null, # The datadog agent host, if null the default will be used
'port' => null, # The datadog agent port, if null the default will be used
],
]);
], $config);
}
}

0 comments on commit 6d6713f

Please sign in to comment.