Skip to content

Commit

Permalink
Fix PHP 8.2 deprecated issues (#182)
Browse files Browse the repository at this point in the history
* fix deprecated creation of dynamic properties

* use short syntax arrays
  • Loading branch information
oliubarskyi authored Apr 22, 2024
1 parent 6d0c928 commit 0cc53d2
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 51 deletions.
12 changes: 6 additions & 6 deletions get_attachment_example.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
require_once __DIR__ . '/autoload.php';

use \ATWS;
Expand All @@ -7,13 +7,13 @@
$username = 'INSERT USERNAME HERE';
$password = 'INSERT PASSWORD HERE';

$postAuthOpts = array(
'login' => $username,
$postAuthOpts = [
'login' => $username,
'password' => $password,
'trace' => 1, // Allows us to debug by getting the XML requests sent
);
'trace' => 1, // Allows us to debug by getting the XML requests sent
];

$opts = array('trace' => 1);
$opts = ['trace' => 1];
$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl';
$client = new ATWS\Client($authWsdl, $opts);
$zoneInfo = $client->getZoneInfo($username);
Expand Down
2 changes: 1 addition & 1 deletion src/AutotaskObjects/CreateParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class CreateParam
public $Entities;

public function __construct($param) {
$this->Entities = array($param);
$this->Entities = [$param];
}
}
2 changes: 1 addition & 1 deletion src/AutotaskObjects/DeleteParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class DeleteParam
public $Entities;

public function __construct($param) {
$this->Entities = array($param);
$this->Entities = [$param];
}
}
3 changes: 2 additions & 1 deletion src/AutotaskObjects/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Query
{
public $entity;
public $clauses;
public $query;
public $queryField;
Expand All @@ -11,7 +12,7 @@ class Query
public function __construct($entity)
{
$this->entity = $entity;
$this->clauses = array();
$this->clauses = [];
}

public function addField(QueryField $field)
Expand Down
2 changes: 1 addition & 1 deletion src/AutotaskObjects/QueryCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class QueryCondition

public function __construct($operator = null)
{
$this->clauses = array();
$this->clauses = [];

$this->operator = $operator;

Expand Down
3 changes: 2 additions & 1 deletion src/AutotaskObjects/QueryField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

class QueryField
{
public $isUDF;
public $name;
public $expressions;

public function __construct($name, $isUDF = false)
{
$this->name = $name;
$this->isUDF = $isUDF;
$this->expressions = array();
$this->expressions = [];
}

public function addExpression($op, $value)
Expand Down
4 changes: 2 additions & 2 deletions src/AutotaskObjects/QueryFieldExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class QueryFieldExpression
public $op;
public $value;

public static $validOperators = array(
public static $validOperators = [
'equals',
'notequal',
'greaterthan',
Expand All @@ -23,7 +23,7 @@ class QueryFieldExpression
'like',
'notlike',
'soundslike',
);
];

public function __construct($op, $value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AutotaskObjects/UpdateParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class UpdateParam
public $Entities;

public function __construct($param) {
$this->Entities = array($param);
$this->Entities = [$param];
}
}
47 changes: 21 additions & 26 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Client extends \SoapClient
protected $version;
protected $integrationCode;

public static $classMap = array(
public static $classMap = [
'Account' => 'ATWS\AutotaskObjects\Account',
'AccountAlert' => 'ATWS\AutotaskObjects\AccountAlert',
'AccountLocation' => 'ATWS\AutotaskObjects\AccountLocation',
Expand Down Expand Up @@ -169,10 +169,10 @@ class Client extends \SoapClient
'UserDefinedFieldDefinition' => 'ATWS\AutotaskObjects\UserDefinedFieldDefinition',
'UserDefinedFieldListItem' => 'ATWS\AutotaskObjects\UserDefinedFieldListItem',
'WorkTypeModifier' => 'ATWS\AutotaskObjects\WorkTypeModifier',
);
];

// @codeCoverageIgnoreStart
public function __construct($wsdl, $soapOpts = array(), $integrationCode = null)
public function __construct($wsdl, $soapOpts = [], $integrationCode = null)
{
foreach (static::$classMap as $external => $internal) {
if (!isset($soapOpts['classmap'][$external])) {
Expand All @@ -196,9 +196,7 @@ public function setIntegrationCode($code)
$header = new \SOAPHeader(
'http://autotask.net/ATWS/v' . str_replace('.', '_', $this->version) .'/',
'AutotaskIntegrations',
array(
'IntegrationCode' => $code,
)
['IntegrationCode' => $code]
);

$this->__setSoapHeaders($header);
Expand All @@ -212,10 +210,7 @@ public function setResourceImpersonation($resourceId)
$header = new \SOAPHeader(
'http://autotask.net/ATWS/v' . str_replace('.', '_', $this->version) .'/',
'AutotaskIntegrations',
array(
'IntegrationCode' => $this->integrationCode,
'ImpersonateAsResourceID' => $resourceId
)
['IntegrationCode' => $this->integrationCode, 'ImpersonateAsResourceID' => $resourceId]
);
$this->__setSoapHeaders($header);
return $this;
Expand All @@ -224,13 +219,13 @@ public function setResourceImpersonation($resourceId)
public function getZoneInfo($username)
{
$zoneInfoObject = new AutotaskObjects\ZoneInfo($username);
return $this->_call('getZoneInfo', array($zoneInfoObject));
return $this->_call('getZoneInfo', [$zoneInfoObject]);
}

public function create(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\CreateParam($obj);
return $this->_call('create', array($params));
return $this->_call('create', [$params]);
}

public function bulkCreate(array $objs)
Expand All @@ -246,13 +241,13 @@ public function bulkCreate(array $objs)
$createObjs->Entities[] = $obj;
}
}
return $this->_call('create', array($createObjs));
return $this->_call('create', [$createObjs]);
}

public function update(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\UpdateParam($obj);
return $this->_call('update', array($params));
return $this->_call('update', [$params]);
}

public function bulkUpdate(array $objs)
Expand All @@ -261,21 +256,21 @@ public function bulkUpdate(array $objs)
throw new \Exception('You can only execute a bulk update on a max of 200 objects per request');
}
$updateObjs = null;
$calls = array();
$calls = [];
foreach ($objs as $obj) {
if (!$updateObjs) {
$updateObjs = new AutotaskObjects\UpdateParam($obj);
} else {
$updateObjs->Entities[] = $obj;
}
}
return $this->_call('update', array($updateObjs));
return $this->_call('update', [$updateObjs]);
}

public function delete(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\DeleteParam($obj);
return $this->_call('delete', array($params));
return $this->_call('delete', [$params]);
}

public function bulkDelete(array $objs)
Expand All @@ -284,45 +279,45 @@ public function bulkDelete(array $objs)
throw new \Exception('You can only execute a bulk delete on a max of 200 objects per request');
}
$deleteObjs = null;
$calls = array();
$calls = [];
foreach ($objs as $obj) {
if (!$deleteObjs) {
$deleteObjs = new AutotaskObjects\DeleteParam($obj);
} else {
$deleteObjs->Entities[] = $obj;
}
}
return $this->_call('delete', array($deleteObjs));
return $this->_call('delete', [$deleteObjs]);
}

public function GetAttachment(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\GetAttachment($obj);
return $this->_call('GetAttachment', array($params));
return $this->_call('GetAttachment', [$params]);
}

public function CreateAttachment(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\CreateAttachment($obj);
return $this->_call('CreateAttachment', array($params));
return $this->_call('CreateAttachment', [$params]);
}

public function query(AutotaskObjects\Query $obj)
{
$obj->asXml();
return $this->_call('query', array($obj));
return $this->_call('query', [$obj]);
}

public function getUDFInfo($type)
{
$param = new AutotaskObjects\UDFParam($type);
return $this->_call('getUDFInfo', array($param));
return $this->_call('getUDFInfo', [$param]);
}

public function getFieldInfo($type)
{
$fieldInfo = new AutotaskObjects\FieldInfo($type);
return $this->_call('getFieldInfo', array($fieldInfo));
return $this->_call('getFieldInfo', [$fieldInfo]);
}

public function getEntityInfo()
Expand All @@ -340,7 +335,7 @@ public function getInvoiceMarkup($invoiceId, $type)
$invoiceMarkup = new AutotaskObjects\InvoiceMarkup();
$invoiceMarkup->InvoiceId = (int)$invoiceId;
$invoiceMarkup->Format = $type;
return $this->_call('GetInvoiceMarkup', array($invoiceMarkup));
return $this->_call('GetInvoiceMarkup', [$invoiceMarkup]);
}

public function __doRequest($request, $location, $action, $version, $oneWay = 0): ?string
Expand All @@ -355,7 +350,7 @@ public function __doRequest($request, $location, $action, $version, $oneWay = 0)
return parent::__doRequest($request, $location, $action, $version, $oneWay);
}

private function _call($method, $params = array())
private function _call($method, $params = [])
{
return $this->__soapCall($method, $params);
}
Expand Down
13 changes: 7 additions & 6 deletions ticket_create_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once __DIR__ . '/src/autoload.php';

// Edit these variables to get this example to work for you
$accountId = '<YOUR ACCOUNT ID>';
$username = '<YOUR USERNAME>';
$password = '<YOUR PASSWORD>';

Expand All @@ -15,7 +16,7 @@
$ticket = new ATWS\AutotaskObjects\Ticket();
// Set required fields
$ticket->id= 0; // Set to 0 for create, or a ticket id for update
$ticket->AccountID = ;
$ticket->AccountID = $accountId;
$ticket->DueDateTime = '2018-12-17';
$ticket->Title = 'Test Ticket';
$ticket->Status = 1;
Expand All @@ -31,15 +32,15 @@
// End Edit Region

$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl';
$opts = array('trace' => 1);
$opts = ['trace' => 1];
$client = new ATWS\Client($authWsdl, $opts);
$zoneInfo = $client->getZoneInfo($username);

$authOpts = array(
'login' => $username,
$authOpts = [
'login' => $username,
'password' => $password,
'trace' => 1, // Allows us to debug by getting the XML requests sent
);
'trace' => 1, // Allows us to debug by getting the XML requests sent
];
$wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL);
$client = new ATWS\Client($wsdl, $authOpts);
$client->setIntegrationCode($integrationCode);
Expand Down
10 changes: 5 additions & 5 deletions udf_query_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
// End Edit Region

$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl';
$opts = array('trace' => 1);
$opts = ['trace' => 1];
$client = new ATWS\Client($authWsdl, $opts);
$zoneInfo = $client->getZoneInfo($username);

print_r($zoneInfo);

$authOpts = array(
'login' => $username,
$authOpts = [
'login' => $username,
'password' => $password,
'trace' => 1, // Allows us to debug by getting the XML requests sent
);
'trace' => 1, // Allows us to debug by getting the XML requests sent
];
$wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL);
$client = new ATWS\Client($wsdl, $authOpts);

Expand Down

0 comments on commit 0cc53d2

Please sign in to comment.