Skip to content

Commit 04d3f6f

Browse files
authored
Merge pull request #86 from valerianpereira/feature/PSR2_Standards
Fixing PSR2 standards
2 parents 909ccbc + 4cc095e commit 04d3f6f

File tree

1 file changed

+51
-46
lines changed

1 file changed

+51
-46
lines changed

src/LaunchDarkly/EventProcessor.php

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,57 @@
44
/**
55
* @internal
66
*/
7-
class EventProcessor {
7+
class EventProcessor
8+
{
9+
private $_eventPublisher;
10+
private $_queue;
11+
private $_capacity;
12+
private $_timeout;
813

9-
private $_eventPublisher;
10-
private $_queue;
11-
private $_capacity;
12-
private $_timeout;
14+
public function __construct($sdkKey, $options = array())
15+
{
16+
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
1317

14-
public function __construct($sdkKey, $options = array()) {
15-
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
18+
$this->_capacity = $options['capacity'];
19+
$this->_timeout = $options['timeout'];
1620

17-
$this->_capacity = $options['capacity'];
18-
$this->_timeout = $options['timeout'];
19-
20-
$this->_queue = array();
21-
}
22-
23-
public function __destruct() {
24-
$this->flush();
25-
}
21+
$this->_queue = array();
22+
}
2623

27-
public function sendEvent($event) {
28-
return $this->enqueue($event);
29-
}
24+
public function __destruct()
25+
{
26+
$this->flush();
27+
}
3028

31-
public function enqueue($event) {
32-
if (count($this->_queue) > $this->_capacity) {
33-
return false;
29+
public function sendEvent($event)
30+
{
31+
return $this->enqueue($event);
3432
}
3533

36-
array_push($this->_queue, $event);
34+
public function enqueue($event)
35+
{
36+
if (count($this->_queue) > $this->_capacity) {
37+
return false;
38+
}
3739

38-
return true;
39-
}
40+
array_push($this->_queue, $event);
41+
42+
return true;
43+
}
4044

4145
/**
4246
* Publish events to LaunchDarkly
4347
* @return bool Whether the events were successfully published
4448
*/
45-
public function flush() {
46-
if (empty($this->_queue)) {
47-
return null;
48-
}
49+
public function flush()
50+
{
51+
if (empty($this->_queue)) {
52+
return null;
53+
}
4954

50-
$payload = json_encode($this->_queue);
55+
$payload = json_encode($this->_queue);
5156

52-
return $this->_eventPublisher->publish($payload);
57+
return $this->_eventPublisher->publish($payload);
5358
}
5459

5560
/**
@@ -59,19 +64,19 @@ public function flush() {
5964
*/
6065
private function getEventPublisher($sdkKey, array $options)
6166
{
62-
if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) {
63-
return $options['event_publisher'];
64-
}
65-
66-
if (isset($options['event_publisher_class'])) {
67-
$eventPublisherClass = $options['event_publisher_class'];
68-
} else {
69-
$eventPublisherClass = CurlEventPublisher::class;
70-
}
71-
72-
if (!is_a($eventPublisherClass, EventPublisher::class, true)) {
73-
throw new \InvalidArgumentException;
74-
}
75-
return new $eventPublisherClass($sdkKey, $options);
67+
if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) {
68+
return $options['event_publisher'];
69+
}
70+
71+
if (isset($options['event_publisher_class'])) {
72+
$eventPublisherClass = $options['event_publisher_class'];
73+
} else {
74+
$eventPublisherClass = CurlEventPublisher::class;
75+
}
76+
77+
if (!is_a($eventPublisherClass, EventPublisher::class, true)) {
78+
throw new \InvalidArgumentException;
79+
}
80+
return new $eventPublisherClass($sdkKey, $options);
7681
}
77-
}
82+
}

0 commit comments

Comments
 (0)