From 1c0b1fa3f4b99fec0c97881a315abde2b95b6303 Mon Sep 17 00:00:00 2001 From: Andy Pasztirak Date: Thu, 21 Jul 2022 22:47:08 +0100 Subject: [PATCH] Updated library to be php7.4 compatibility by replacing array_key_exists function calls with isset (#61) --- lib/Base/MixpanelBase.php | 4 ++-- lib/ConsumerStrategies/CurlConsumer.php | 10 +++++----- lib/ConsumerStrategies/FileConsumer.php | 4 ++-- lib/ConsumerStrategies/SocketConsumer.php | 6 +++--- lib/Producers/MixpanelBaseProducer.php | 6 +++--- lib/Producers/MixpanelEvents.php | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Base/MixpanelBase.php b/lib/Base/MixpanelBase.php index eccaa13..2264706 100644 --- a/lib/Base/MixpanelBase.php +++ b/lib/Base/MixpanelBase.php @@ -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; } -} \ No newline at end of file +} diff --git a/lib/ConsumerStrategies/CurlConsumer.php b/lib/ConsumerStrategies/CurlConsumer.php index ee52dc6..ae1b8b8 100644 --- a/lib/ConsumerStrategies/CurlConsumer.php +++ b/lib/ConsumerStrategies/CurlConsumer.php @@ -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) { diff --git a/lib/ConsumerStrategies/FileConsumer.php b/lib/ConsumerStrategies/FileConsumer.php index ba74cdf..b85374f 100644 --- a/lib/ConsumerStrategies/FileConsumer.php +++ b/lib/ConsumerStrategies/FileConsumer.php @@ -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"; } @@ -35,4 +35,4 @@ public function persist($batch) { return true; } } -} \ No newline at end of file +} diff --git a/lib/ConsumerStrategies/SocketConsumer.php b/lib/ConsumerStrategies/SocketConsumer.php index edc1cb6..ca233cf 100644 --- a/lib/ConsumerStrategies/SocketConsumer.php +++ b/lib/ConsumerStrategies/SocketConsumer.php @@ -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"; @@ -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"); diff --git a/lib/Producers/MixpanelBaseProducer.php b/lib/Producers/MixpanelBaseProducer.php index b96acd4..98f4c3c 100644 --- a/lib/Producers/MixpanelBaseProducer.php +++ b/lib/Producers/MixpanelBaseProducer.php @@ -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']; } @@ -228,4 +228,4 @@ protected function _persist($message) { */ abstract function _getEndpoint(); -} \ No newline at end of file +} diff --git a/lib/Producers/MixpanelEvents.php b/lib/Producers/MixpanelEvents.php index 58af308..c6a8ef2 100644 --- a/lib/Producers/MixpanelEvents.php +++ b/lib/Producers/MixpanelEvents.php @@ -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);