Skip to content

Commit

Permalink
Fix deprecations & support current PHP versions (#624)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #624

Reviewed By: satwikareddy3

Differential Revision: D69256661

Pulled By: stcheng

fbshipit-source-id: c8c8420cc52d3954267f8bc10e0e284d99baa77d
  • Loading branch information
mpesari authored and facebook-github-bot committed Feb 6, 2025
1 parent ef5a6d9 commit 8193ecb
Show file tree
Hide file tree
Showing 37 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1', '8.2']
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
$return_prototype = null,
$api_type = null,
$accepted_fields = array(),
TypeChecker $param_checker = null,
?TypeChecker $param_checker = null,
$allow_file_upload = false,
$use_graph_video_endpoint = false) {
$this->fields = [];
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Cursor implements \Iterator, \Countable, \ArrayAccess {
public function __construct(
ResponseInterface $response,
AbstractObject $object_prototype,
Api $api = null) {
?Api $api = null) {
$this->response = $response;
$this->objectPrototype = $object_prototype;
$this->api = $api !== null ? $api : Api::instance();
Expand Down
4 changes: 2 additions & 2 deletions src/FacebookAds/Http/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CurlAdapter extends AbstractAdapter {
* @param Client $client
* @param CurlInterface $curl
*/
public function __construct(Client $client, CurlInterface $curl = null) {
public function __construct(Client $client, ?CurlInterface $curl = null) {
parent::__construct($client);
$this->curl = $curl ?: AbstractCurl::createOptimalVersion();
$this->curl->init();
Expand Down Expand Up @@ -90,7 +90,7 @@ public function setOpts(\ArrayObject $opts) {
* @return int
*/
protected function getheaderSize() {
return $this->getCurl()->getInfo(CURLINFO_HEADER_SIZE);
return $this->getCurl()->getInfo(CURLINFO_HEADER_SIZE) ?? 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Http/Exception/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(ResponseInterface $response) {
$this->response = $response;
$error_data = static::getErrorData($response);

parent::__construct($error_data['message'], $error_data['code'] ?? 0);
parent::__construct($error_data['message'] ?? '', $error_data['code'] ?? 0);

$this->errorSubcode = $error_data['error_subcode'];
$this->errorUserTitle = $error_data['error_user_title'];
Expand Down
8 changes: 4 additions & 4 deletions src/FacebookAds/Object/AbstractCrudObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AbstractCrudObject extends AbstractObject {
* @param string $parent_id Optional, needed for creating new objects.
* @param Api $api The Api instance this object should use to make calls
*/
public function __construct($id = null, $parent_id = null, Api $api = null) {
public function __construct($id = null, $parent_id = null, ?Api $api = null) {
parent::__construct();

// check that $id is an integer or a string integer or a string of
Expand Down Expand Up @@ -113,7 +113,7 @@ protected function getEndpoint() {
* @return Api
* @throws \InvalidArgumentException
*/
protected static function assureApi(Api $instance = null) {
protected static function assureApi(?Api $instance = null) {
$instance = $instance ?: Api::instance();
if (!$instance) {
throw new \InvalidArgumentException(
Expand Down Expand Up @@ -460,7 +460,7 @@ protected function createAsyncJob(
* @param Api $api Api Object to use
* @return bool Returns true on success
*/
public static function deleteIds(array $ids, Api $api = null) {
public static function deleteIds(array $ids, ?Api $api = null) {
$batch = array();
foreach ($ids as $id) {
$request = array(
Expand Down Expand Up @@ -495,7 +495,7 @@ public static function readIds(
array $ids,
array $fields = array(),
array $params = array(),
Api $api = null) {
?Api $api = null) {
if (empty($fields)) {
$fields = static::getDefaultReadFields();
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/AdImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getSelf(array $fields = array(), array $params = array(), $pendi
* @return array
*/
public static function createFromZip(
$file_path, $account_id, array $params = array(), Api $api = null) {
$file_path, $account_id, array $params = array(), ?Api $api = null) {

$image = new AdImage(null, $account_id, $api);
$image->{AdImageFields::FILENAME} = $file_path;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Content {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['product_id'] = isset($data['product_id']) ? $data['product_id'] : null;;
$this->container['quantity'] = isset($data['quantity']) ? $data['quantity'] : null;
$this->container['price'] = isset($data['price']) ? $data['price'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CustomData {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['value'] = isset($data['value']) ? $data['value'] : null;
$this->container['currency'] = isset($data['currency']) ? $data['currency'] : null;
$this->container['contents'] = isset($data['contents']) ? $data['contents'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Event {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['event_name'] = isset($data['event_name']) ? $data['event_name'] : null;
$this->container['event_time'] = isset($data['event_time']) ? $data['event_time'] : null;
$this->container['event_id'] = isset($data['event_id']) ? $data['event_id'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EventRequest {
* @param string $page_id page id
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(string $page_id, array $data = null) {
public function __construct(string $page_id, ?array $data = null) {
$this->container['page_id'] = $page_id;
$this->container['events'] = isset($data['events']) ? $data['events'] : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/EventResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EventResponse {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['events_received'] = isset($data['events_received']) ? $data['events_received'] : null;
$this->container['events_dropped'] = isset($data['events_dropped']) ? $data['events_dropped'] : null;
$this->container['message'] = isset($data['message']) ? $data['message'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/BusinessDataAPI/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UserData {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['email'] = isset($data['email']) ? $data['email'] : null;
$this->container['phone'] = isset($data['phone']) ? $data['phone'] : null;
$this->container['date_of_birth'] = isset($data['date_of_birth']) ? $data['date_of_birth'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/AdsPixelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AdsPixelSettings implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['enable_automatic_matching'] = isset($data['enableAutomaticMatching']) ? $data['enableAutomaticMatching'] : null;;
$this->container['enabled_automatic_matching_fields'] = isset($data['enabledAutomaticMatchingFields']) ? $data['enabledAutomaticMatchingFields'] : null;
$this->container['pixel_id'] = isset($data['pixel_id']) ? $data['pixel_id'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/AppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class AppData implements ArrayAccess {

protected $container = array();

public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['application_tracking_enabled'] = isset($data['application_tracking_enabled']) ? $data['application_tracking_enabled'] : null;
$this->container['advertiser_tracking_enabled'] = isset($data['advertiser_tracking_enabled']) ? $data['advertiser_tracking_enabled'] : null;
$this->container['app_user_id'] = isset($data['app_user_id']) ? $data['app_user_id'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/AttributionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AttributionData implements ArrayAccess {

protected $container = array();

public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['scope'] = isset($data['scope']) ? $data['scope'] : null;
$this->container['visit_time'] = isset($data['visit_time']) ? $data['visit_time'] : null;
$this->container['ad_id'] = isset($data['ad_id']) ? $data['ad_id'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Content implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['product_id'] = isset($data['product_id']) ? $data['product_id'] : null;;
$this->container['quantity'] = isset($data['quantity']) ? $data['quantity'] : null;
$this->container['item_price'] = isset($data['item_price']) ? $data['item_price'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CustomData implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['value'] = isset($data['value']) ? $data['value'] : null;
$this->container['currency'] = isset($data['currency']) ? $data['currency'] : null;
$this->container['content_name'] = isset($data['content_name']) ? $data['content_name'] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CustomEndpointResponse {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['message'] = isset($data['message']) ? $data['message'] : null;
$this->container['response_code'] = isset($data['response_code']) ? $data['response_code'] : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Event implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['event_name'] = isset($data['event_name']) ? $data['event_name'] : null;
$this->container['event_time'] = isset($data['event_time']) ? $data['event_time'] : null;
$this->container['event_source_url'] = isset($data['event_source_url']) ? $data['event_source_url'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class EventRequest implements ArrayAccess {
* @param string $pixel_id pixel id
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct($pixel_id, array $data = null) {
public function __construct($pixel_id, ?array $data = null) {
$this->container['pixel_id'] = $pixel_id;
$this->container['events'] = isset($data['events']) ? $data['events'] : null;
$this->container['test_event_code'] = isset($data['test_event_code']) ? $data['test_event_code'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/EventResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class EventResponse implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['events_received'] = isset($data['events_received']) ? $data['events_received'] : null;
$this->container['messages'] = isset($data['messages']) ? $data['messages'] : null;
$this->container['fbtrace_id'] = isset($data['fbtrace_id']) ? $data['fbtrace_id'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/ExtendedDeviceInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ExtendedDeviceInfo implements ArrayAccess {

protected $container = array();

public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['ext_info_version'] = isset($data['ext_info_version']) ? $data['ext_info_version'] : null;
$this->container['app_package_name'] = isset($data['app_package_name']) ? $data['app_package_name'] : null;
$this->container['short_version'] = isset($data['short_version']) ? $data['short_version'] : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/OriginalEventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OriginalEventData implements ArrayAccess {

protected $container = array();

public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->container['event_name'] = isset($data['event_name']) ? $data['event_name'] : null;
$this->container['event_time'] = isset($data['event_time']) ? $data['event_time'] : null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/ServerSide/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class UserData implements ArrayAccess {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {

# Let's make sure not both singular and plural parameters are set
if(isset($data['email']) And isset($data['emails'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/Signal/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Content {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->businessDataContent = new BusinessDataContent($data);
$this->serverSideContent = new ServerSideContent($data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/Signal/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CustomData {
* Constructor
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$business_contents = array();
$server_contents = array();
if(isset($data['contents'])){
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/Signal/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Event {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$business_data = $data;
$server_data = $data;
$business_data['user_data'] = isset($data['user_data']) ? $data['user_data']->getBusinessDataUserData() : null;
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/Signal/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EventRequest {
* @param string $page_id page id
* @param mixed[] $data Associated array of property value initializing the model
*/
public function __construct(string $pixel_id, string $page_id, array $data = null) {
public function __construct(string $pixel_id, string $page_id, ?array $data = null) {
$business_data = $data;
$server_data = $data;

Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/Signal/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UserData {
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null) {
public function __construct(?array $data = null) {
$this->businessDataUserData = new BusinessDataUserData($data);
$this->serverSideUserData = new ServerSideUserData($data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FacebookAds/Object/TargetingSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function search(
$class=null,
$query=null,
array $params = array(),
Api $api = null) {
?Api $api = null) {

$api = $api ?: Api::instance();
if (!$api) {
Expand Down
2 changes: 1 addition & 1 deletion test/FacebookAdsTest/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testDefaultGraphVersion() {
// Test default
$api = $this->createApi();
$this->assertTrue(is_string($api->getDefaultGraphVersion()));
$this->assertRegExp('/^\d+\.\d+$/', $api->getDefaultGraphVersion());
$this->assertMatchesRegularExpression('/^\d+\.\d+$/', $api->getDefaultGraphVersion());
}

public function testCall() {
Expand Down
2 changes: 1 addition & 1 deletion test/FacebookAdsTest/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function createUnparameterizedUrl() {
* @return Mock|ResponseInterface
*/
protected function createResponseChainMock(
$num_pages, RequestInterface $prev = null) {
$num_pages, ?RequestInterface $prev = null) {

$query_params = $prev ? clone $prev->getQueryParams() : new Parameters();
$sample_content = $this->createSampleResponseContent();
Expand Down
2 changes: 1 addition & 1 deletion test/FacebookAdsTest/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testDomain() {
->willReturn('not.facebook.com');
$request = new Request($client);
$domain = $request->getDomain();
$this->assertRegExp('/.+\.not\.facebook\.com/', $domain);
$this->assertMatchesRegularExpression('/.+\.not\.facebook\.com/', $domain);
$this->assertEquals($domain, $request->getDomain());

// Partially set
Expand Down
2 changes: 1 addition & 1 deletion test/init_integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace FacebookAdsTest\Bootstrap;

error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
Expand Down
2 changes: 1 addition & 1 deletion test/init_unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace FacebookAdsTest\Bootstrap;

error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
Expand Down
9 changes: 8 additions & 1 deletion test/phpunit-travis.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<phpunit bootstrap="init_unit.php" colors="true">
<phpunit
bootstrap="init_unit.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="Facebook AdsAPI PHP SDK">
<directory>./FacebookAdsTest</directory>
Expand Down

0 comments on commit 8193ecb

Please sign in to comment.