diff --git a/src/LaunchDarkly/EventProcessor.php b/src/LaunchDarkly/EventProcessor.php index f408ac635..9249cfd4d 100644 --- a/src/LaunchDarkly/EventProcessor.php +++ b/src/LaunchDarkly/EventProcessor.php @@ -4,52 +4,57 @@ /** * @internal */ -class EventProcessor { +class EventProcessor +{ + private $_eventPublisher; + private $_queue; + private $_capacity; + private $_timeout; - private $_eventPublisher; - private $_queue; - private $_capacity; - private $_timeout; + public function __construct($sdkKey, $options = array()) + { + $this->_eventPublisher = $this->getEventPublisher($sdkKey, $options); - public function __construct($sdkKey, $options = array()) { - $this->_eventPublisher = $this->getEventPublisher($sdkKey, $options); + $this->_capacity = $options['capacity']; + $this->_timeout = $options['timeout']; - $this->_capacity = $options['capacity']; - $this->_timeout = $options['timeout']; - - $this->_queue = array(); - } - - public function __destruct() { - $this->flush(); - } + $this->_queue = array(); + } - public function sendEvent($event) { - return $this->enqueue($event); - } + public function __destruct() + { + $this->flush(); + } - public function enqueue($event) { - if (count($this->_queue) > $this->_capacity) { - return false; + public function sendEvent($event) + { + return $this->enqueue($event); } - array_push($this->_queue, $event); + public function enqueue($event) + { + if (count($this->_queue) > $this->_capacity) { + return false; + } - return true; - } + array_push($this->_queue, $event); + + return true; + } /** * Publish events to LaunchDarkly * @return bool Whether the events were successfully published */ - public function flush() { - if (empty($this->_queue)) { - return null; - } + public function flush() + { + if (empty($this->_queue)) { + return null; + } - $payload = json_encode($this->_queue); + $payload = json_encode($this->_queue); - return $this->_eventPublisher->publish($payload); + return $this->_eventPublisher->publish($payload); } /** @@ -59,19 +64,19 @@ public function flush() { */ private function getEventPublisher($sdkKey, array $options) { - if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) { - return $options['event_publisher']; - } - - if (isset($options['event_publisher_class'])) { - $eventPublisherClass = $options['event_publisher_class']; - } else { - $eventPublisherClass = CurlEventPublisher::class; - } - - if (!is_a($eventPublisherClass, EventPublisher::class, true)) { - throw new \InvalidArgumentException; - } - return new $eventPublisherClass($sdkKey, $options); + if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) { + return $options['event_publisher']; + } + + if (isset($options['event_publisher_class'])) { + $eventPublisherClass = $options['event_publisher_class']; + } else { + $eventPublisherClass = CurlEventPublisher::class; + } + + if (!is_a($eventPublisherClass, EventPublisher::class, true)) { + throw new \InvalidArgumentException; + } + return new $eventPublisherClass($sdkKey, $options); } -} \ No newline at end of file +}