Skip to content

Commit

Permalink
Updated library to be php7.4 compatibility by replacing array_key_exi…
Browse files Browse the repository at this point in the history
…sts function calls with isset (#61)
  • Loading branch information
andypasztirak authored Jul 21, 2022
1 parent ba5a4c6 commit 1c0b1fa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/Base/MixpanelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function _log($msg) {
* @return bool
*/
protected function _debug() {
return array_key_exists("debug", $this->_options) && $this->_options["debug"] == true;
return isset($this->_options["debug"]) && $this->_options["debug"] == true;
}

}
}
10 changes: 5 additions & 5 deletions lib/ConsumerStrategies/CurlConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ function __construct($options) {

$this->_host = $options['host'];
$this->_endpoint = $options['endpoint'];
$this->_connect_timeout = array_key_exists('connect_timeout', $options) ? $options['connect_timeout'] : 5;
$this->_timeout = array_key_exists('timeout', $options) ? $options['timeout'] : 30;
$this->_protocol = array_key_exists('use_ssl', $options) && $options['use_ssl'] == true ? "https" : "http";
$this->_fork = array_key_exists('fork', $options) ? ($options['fork'] == true) : false;
$this->_num_threads = array_key_exists('num_threads', $options) ? max(1, intval($options['num_threads'])) : 1;
$this->_connect_timeout = isset($options['connect_timeout']) ? $options['connect_timeout'] : 5;
$this->_timeout = isset($options['timeout']) ? $options['timeout'] : 30;
$this->_protocol = isset($options['use_ssl']) && $options['use_ssl'] == true ? "https" : "http";
$this->_fork = isset($options['fork']) ? ($options['fork'] == true) : false;
$this->_num_threads = isset($options['num_threads']) ? max(1, intval($options['num_threads'])) : 1;

// ensure the environment is workable for the given settings
if ($this->_fork == true) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ConsumerStrategies/FileConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function __construct($options) {
parent::__construct($options);

// what file to write to?
$this->_file = array_key_exists("file", $options) ? $options['file'] : dirname(__FILE__)."/../../messages.txt";
$this->_file = isset($options['file']) ? $options['file'] : dirname(__FILE__)."/../../messages.txt";
}


Expand All @@ -35,4 +35,4 @@ public function persist($batch) {
return true;
}
}
}
}
6 changes: 3 additions & 3 deletions lib/ConsumerStrategies/SocketConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function __construct($options = array()) {

$this->_host = $options['host'];
$this->_endpoint = $options['endpoint'];
$this->_connect_timeout = array_key_exists('connect_timeout', $options) ? $options['connect_timeout'] : 5;
$this->_async = array_key_exists('async', $options) && $options['async'] === false ? false : true;
$this->_connect_timeout = isset($options['connect_timeout']) ? $options['connect_timeout'] : 5;
$this->_async = isset($options['async']) && $options['async'] === false ? false : true;

if (array_key_exists('use_ssl', $options) && $options['use_ssl'] == true) {
$this->_protocol = "ssl";
Expand Down Expand Up @@ -289,7 +289,7 @@ private function handleResponse($response) {
$body = $lines[count($lines) - 1];

// if the connection has been closed lets kill the socket
if (array_key_exists("Connection", $headers) and $headers['Connection'] == "close") {
if (isset($headers["Connection"]) and $headers['Connection'] == "close") {
$this->_destroySocket();
if ($this->_debug()) {
$this->_log("Server told us connection closed so lets destroy the socket so it'll reconnect on next call");
Expand Down
6 changes: 3 additions & 3 deletions lib/Producers/MixpanelBaseProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function __construct($token, $options = array()) {
parent::__construct($options);

// register any customer consumers
if (array_key_exists("consumers", $options)) {
if (isset($options["consumers"])) {
$this->_consumers = array_merge($this->_consumers, $options['consumers']);
}

// set max queue size
if (array_key_exists("max_queue_size", $options)) {
if (isset($options["max_queue_size"])) {
$this->_max_queue_size = $options['max_queue_size'];
}

Expand Down Expand Up @@ -228,4 +228,4 @@ protected function _persist($message) {
*/
abstract function _getEndpoint();

}
}
4 changes: 2 additions & 2 deletions lib/Producers/MixpanelEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Producers_MixpanelEvents extends Producers_MixpanelBaseProducer {
public function track($event, $properties = array()) {

// if no token is passed in, use current token
if (!array_key_exists("token", $properties)) $properties['token'] = $this->_token;
if (!isset($properties["token"])) $properties['token'] = $this->_token;

// if no time is passed in, use the current time
if (!array_key_exists('time', $properties)) $properties['time'] = time();
if (!isset($properties["time"])) $properties['time'] = time();

$params['event'] = $event;
$params['properties'] = array_merge($this->_super_properties, $properties);
Expand Down

0 comments on commit 1c0b1fa

Please sign in to comment.