Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Add #[\ReturnTypeWillChange] to methods declarations in order to supp…
Browse files Browse the repository at this point in the history
…ress deprecation warnings
  • Loading branch information
dano-klaviyo committed Apr 18, 2022
1 parent 7e0516f commit 222dae4
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 1 deletion.
27 changes: 27 additions & 0 deletions client.php
@@ -0,0 +1,27 @@
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use Klaviyo\Klaviyo as Klaviyo;

// $client = new Klaviyo( 'PRIVATE_API_KEY', 'PUBLIC_API_KEY' );
$client = new Klaviyo( 'pk_e2c87144dc81bfd6f6418a1861e509e374', 'TzzGh5' );

use Klaviyo\Model\EventModel as KlaviyoEvent;

$event = new KlaviyoEvent(
array(
'event' => 'Filled out Profile',
'customer_properties' => array(
'$email' => 'someone@mailinator.com',
'$first_name' => 'Thomas',
'$last_name' => 'Jefferson'
),
'properties' => array(
'Added Social Accounts' => False
)
)
);

$client->publicAPI->track( $event, true );


?>
1 change: 1 addition & 0 deletions src/DataPrivacy.php
Expand Up @@ -40,6 +40,7 @@ class DataPrivacy extends KlaviyoAPI
* @return mixed
* @throws KlaviyoException
*/
#[\ReturnTypeWillChange]
public function requestProfileDeletion($identifier, $idType = self::EMAIL)
{
if (!in_array($idType, self::PROFILE_DELETION_VALID_ID_TYPES)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Klaviyo.php
Expand Up @@ -39,6 +39,7 @@ public function __construct($private_key, $public_key)
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getPrivateKey()
{
return $this->private_key;
Expand All @@ -47,6 +48,7 @@ public function getPrivateKey()
/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getPublicKey()
{
return $this->public_key;
Expand All @@ -58,6 +60,7 @@ public function getPublicKey()
*
* @param string $api API service
*/
#[\ReturnTypeWillChange]
public function __get($api)
{
$service = __NAMESPACE__ . '\\' . ucfirst($api);
Expand Down
27 changes: 27 additions & 0 deletions src/KlaviyoAPI.php
Expand Up @@ -107,6 +107,7 @@ public function __construct($public_key, $private_key)
* @param $path Endpoint to call
* @param $options API params to add to request
*/
#[\ReturnTypeWillChange]
protected function publicRequest($path, $options, $post)
{
$method = $post ? self::HTTP_POST : self::HTTP_GET;
Expand All @@ -123,6 +124,7 @@ protected function publicRequest($path, $options, $post)
*
* @throws KlaviyoException
*/
#[\ReturnTypeWillChange]
protected function v1Request($path, $options = [], $method = self::HTTP_GET)
{
$path = self::API_V1 . $this->trimPath($path);
Expand All @@ -140,6 +142,7 @@ protected function v1Request($path, $options = [], $method = self::HTTP_GET)
*
* @throws KlaviyoException
*/
#[\ReturnTypeWillChange]
protected function v2Request($path, $options = [], $method = self::HTTP_GET)
{
$path = self::API_V2 . $this->trimPath($path);
Expand All @@ -158,6 +161,7 @@ protected function v2Request($path, $options = [], $method = self::HTTP_GET)
*
* @throws KlaviyoException
*/
#[\ReturnTypeWillChange]
private function request($method, $path, $options, $isPublic = false, $isV1 = false)
{
$options = $this->prepareAuthentication($method, $options, $isPublic, $isV1);
Expand All @@ -180,6 +184,7 @@ private function request($method, $path, $options, $isPublic = false, $isV1 = fa
/**
* Handle response from API call
*/
#[\ReturnTypeWillChange]
private function handleResponse($response, $statusCode, $isPublic)
{
$decoded_response = $this->decodeJsonResponse($response);
Expand Down Expand Up @@ -211,6 +216,7 @@ private function handleResponse($response, $statusCode, $isPublic)
*
* @return array|array[]
*/
#[\ReturnTypeWillChange]
private function prepareAuthentication($method, $params, $isPublic, $isV1)
{
if ($isPublic && $method == self::HTTP_POST) {
Expand Down Expand Up @@ -238,6 +244,7 @@ private function prepareAuthentication($method, $params, $isPublic, $isV1)
* @param $params
* @return array[]
*/
#[\ReturnTypeWillChange]
protected function publicPostAuth($params)
{
unset($params[self::HEADERS][self::API_KEY_HEADER]);
Expand All @@ -254,6 +261,7 @@ protected function publicPostAuth($params)
* @param $params
* @return array[]
*/
#[\ReturnTypeWillChange]
protected function publicGetAuth($params)
{
unset($params[self::HEADERS][self::API_KEY_HEADER]);
Expand All @@ -280,6 +288,7 @@ protected function publicGetAuth($params)
* @param $params
* @return array
*/
#[\ReturnTypeWillChange]
protected function v1Auth($params)
{
$params[self::QUERY][self::API_KEY_PARAM] = $this->private_key;
Expand All @@ -295,6 +304,7 @@ protected function v1Auth($params)
* @param $params
* @return array
*/
#[\ReturnTypeWillChange]
protected function v2Auth($params)
{
$params = array_merge(
Expand All @@ -316,6 +326,7 @@ protected function v2Auth($params)
* @param $params
* @return array
*/
#[\ReturnTypeWillChange]
protected function setUserAgentHeader($params)
{
$params = array_merge(
Expand All @@ -333,6 +344,7 @@ protected function setUserAgentHeader($params)
/**
* Helper function to remove leading forward slashes
*/
#[\ReturnTypeWillChange]
private function trimPath($path)
{
return '/' . ltrim($path, '/');
Expand All @@ -346,6 +358,7 @@ private function trimPath($path)
* @param string $response
* @return mixed
*/
#[\ReturnTypeWillChange]
private function decodeJsonResponse($response)
{
if (!empty($response)) {
Expand All @@ -361,6 +374,7 @@ private function decodeJsonResponse($response)
* @param mixed $response
* @return string
*/
#[\ReturnTypeWillChange]
private function returnRateLimit($response)
{
$responseDetail = explode(" ", $response['detail']);
Expand All @@ -379,6 +393,7 @@ private function returnRateLimit($response)
* @param string $paramName Name of API Param to create
* @param mixed $paramValue Value of API params to create
*/
#[\ReturnTypeWillChange]
protected function createParams($paramName, $paramValue)
{
return [
Expand All @@ -395,6 +410,7 @@ protected function createParams($paramName, $paramValue)
* @param mixed $key Key of item in array.
* @param string $class Name of class against which items are validated.
*/
#[\ReturnTypeWillChange]
protected function isInstanceOf($value, $key, $class)
{
if (!($value instanceof $class)) {
Expand All @@ -411,6 +427,7 @@ protected function isInstanceOf($value, $key, $class)
* @param $uuid New token supplied by API response
* @return array
*/
#[\ReturnTypeWillChange]
protected function setSinceParameter($since, $uuid)
{
if (is_null($uuid)) {
Expand All @@ -430,6 +447,7 @@ protected function setSinceParameter($since, $uuid)
* @param array $params
* @return array
*/
#[\ReturnTypeWillChange]
protected function filterParams($params)
{
return array_filter(
Expand All @@ -446,6 +464,7 @@ function ($key) {
* @param array $params
* @return array[]
*/
#[\ReturnTypeWillChange]
protected function createRequestBody($params)
{
return array(
Expand All @@ -459,6 +478,7 @@ protected function createRequestBody($params)
* @param array $params
* @return array[]
*/
#[\ReturnTypeWillChange]
protected function createRequestJson($params)
{
return array(
Expand All @@ -472,6 +492,7 @@ protected function createRequestJson($params)
* @param ProfileModel|EventModel $model
* @return array
*/
#[\ReturnTypeWillChange]
protected function createOptionsArray($type, $model)
{
if ($type == self::TRACK) {
Expand All @@ -491,6 +512,7 @@ protected function createOptionsArray($type, $model)
* @param array $params Key/value pairs to be set as query string.
* @return array
*/
#[\ReturnTypeWillChange]
protected function createQueryParams($params)
{
return array(
Expand All @@ -504,6 +526,7 @@ protected function createQueryParams($params)
* @param array $profiles
* @throws KlaviyoException
*/
#[\ReturnTypeWillChange]
protected function checkProfile($profiles)
{
foreach ($profiles as $profile) {
Expand All @@ -524,6 +547,7 @@ protected function checkProfile($profiles)
* @param $method
* @return array
*/
#[\ReturnTypeWillChange]
protected function getDefaultCurlOptions($method)
{
return array(
Expand All @@ -542,6 +566,7 @@ protected function getDefaultCurlOptions($method)
* @param $options
* @return array
*/
#[\ReturnTypeWillChange]
protected function getCurlOptUrl($path, $options)
{
$url = self::BASE_URL . $path;
Expand All @@ -558,6 +583,7 @@ protected function getCurlOptUrl($path, $options)
* @param $options
* @return array
*/
#[\ReturnTypeWillChange]
protected function getSpecificCurlOptions($options)
{
$setopt_array = array();
Expand All @@ -581,6 +607,7 @@ protected function getSpecificCurlOptions($options)
* @param array $headers
* @return array
*/
#[\ReturnTypeWillChange]
protected function formatCurlHeaders($headers)
{
$formatted = array();
Expand Down

0 comments on commit 222dae4

Please sign in to comment.