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

Commit

Permalink
Merge pull request #88 from klaviyo/202204_disable_php_8_1_deprecatio…
Browse files Browse the repository at this point in the history
…n_warnings

Add #[\ReturnTypeWillChange] to methods declarations in order to suppress deprecation warnings in php 8.1
  • Loading branch information
dano-klaviyo authored Apr 22, 2022
2 parents ba9ace0 + eb6f132 commit 1b31aed
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DataPrivacy.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
19 changes: 19 additions & 0 deletions src/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Lists extends KlaviyoAPI
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function createList( $listName )
{
$options = $this->createParams(self::LIST_NAME, $listName);
Expand All @@ -51,6 +52,7 @@ public function createList( $listName )
*
* @return bool/mixed
*/
#[\ReturnTypeWillChange]
public function getLists() {

return $this->v2Request( self::ENDPOINT_LISTS );
Expand All @@ -67,6 +69,7 @@ public function getLists() {
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getListDetails( $listId )
{
return $this->getListById($listId);
Expand All @@ -81,6 +84,7 @@ public function getListDetails( $listId )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getListById($listId)
{
$path = sprintf('%s/%s', self::ENDPOINT_LIST, $listId);
Expand All @@ -101,6 +105,7 @@ public function getListById($listId)
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function updateListDetails( $listId, $list_name )
{
return $this->updateListNameById($listId, $list_name);
Expand All @@ -118,6 +123,7 @@ public function updateListDetails( $listId, $list_name )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function updateListNameById($listId, $listName)
{
$params = $this->createRequestBody(
Expand All @@ -138,6 +144,7 @@ public function updateListNameById($listId, $listName)
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function deleteList( $listId )
{
$path = sprintf( '%s/%s', self::ENDPOINT_LIST, $listId );
Expand All @@ -162,6 +169,7 @@ public function deleteList( $listId )
* @return bool|mixed
* @throws Exception\KlaviyoException
*/
#[\ReturnTypeWillChange]
public function subscribeMembersToList( $listId, $profiles )
{
return $this->addSubscribersToList($listId, $profiles);
Expand All @@ -183,6 +191,7 @@ public function subscribeMembersToList( $listId, $profiles )
* @return bool|mixed
* @throws Exception\KlaviyoException
*/
#[\ReturnTypeWillChange]
public function addSubscribersToList($listId, $profiles)
{
$this->checkProfile($profiles);
Expand Down Expand Up @@ -219,6 +228,7 @@ function($profile) {
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers = null, $pushTokens = null )
{
$params = $this->createRequestJson(
Expand Down Expand Up @@ -250,6 +260,7 @@ public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function unsubscribeMembersFromList( $listId, $emails )
{
return $this->deleteSubscribersFromList($listId, $emails);
Expand All @@ -267,6 +278,7 @@ public function unsubscribeMembersFromList( $listId, $emails )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function deleteSubscribersFromList($listId, $emails)
{
$params = $this->createRequestJson(
Expand Down Expand Up @@ -299,6 +311,7 @@ public function deleteSubscribersFromList($listId, $emails)
*
* @throws Exception\KlaviyoException
*/
#[\ReturnTypeWillChange]
public function addMembersToList( $listId, $profiles )
{
$this->checkProfile( $profiles );
Expand Down Expand Up @@ -334,6 +347,7 @@ function( $profile ) {
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function checkListMembership( $listId, $emails = null, $phoneNumbers = null, $pushTokens = null )
{
$params = $this->createRequestJson(
Expand Down Expand Up @@ -363,6 +377,7 @@ public function checkListMembership( $listId, $emails = null, $phoneNumbers = n
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function removeMembersFromList( $listId, $emails )
{
$params = $this->createRequestJson(
Expand Down Expand Up @@ -393,6 +408,7 @@ public function removeMembersFromList( $listId, $emails )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getAllExclusionsOnList( $listId, $marker = null )
{
return $this->getListExclusions($listId, $marker);
Expand All @@ -411,6 +427,7 @@ public function getAllExclusionsOnList( $listId, $marker = null )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getListExclusions($listId, $marker = null)
{
$params = $this->createRequestBody(
Expand Down Expand Up @@ -441,6 +458,7 @@ public function getListExclusions($listId, $marker = null)
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getGroupMemberIdentifiers( $groupId, $marker = null )
{
return $this->getAllMembers($groupId, $marker);
Expand All @@ -459,6 +477,7 @@ public function getGroupMemberIdentifiers( $groupId, $marker = null )
*
* @return bool|mixed
*/
#[\ReturnTypeWillChange]
public function getAllMembers($groupId, $marker = null)
{
$params = $this->createRequestBody(
Expand Down
Loading

0 comments on commit 1b31aed

Please sign in to comment.