Skip to content

Commit

Permalink
Merge pull request #13911 from colemanw/shortCivi
Browse files Browse the repository at this point in the history
NFC - Short array syntax - auto-convert Civi dir
  • Loading branch information
eileenmcnaughton authored Mar 29, 2019
2 parents 3df2378 + c64f69d commit a073564
Show file tree
Hide file tree
Showing 80 changed files with 692 additions and 692 deletions.
22 changes: 11 additions & 11 deletions Civi/API/Api3SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Api3SelectQuery extends SelectQuery {
* @inheritDoc
*/
protected function buildWhereClause() {
$filters = array();
$filters = [];
foreach ($this->where as $key => $value) {
$table_name = NULL;
$column_name = NULL;
Expand All @@ -45,7 +45,7 @@ protected function buildWhereClause() {
// Legacy support for old filter syntax per the test contract.
// (Convert the style to the later one & then deal with them).
$filterArray = explode('.', $key);
$value = array($filterArray[1] => $value);
$value = [$filterArray[1] => $value];
$key = 'filters';
}

Expand All @@ -54,12 +54,12 @@ protected function buildWhereClause() {
foreach ($value as $filterKey => $filterValue) {
if (substr($filterKey, -4, 4) == 'high') {
$key = substr($filterKey, 0, -5);
$value = array('<=' => $filterValue);
$value = ['<=' => $filterValue];
}

if (substr($filterKey, -3, 3) == 'low') {
$key = substr($filterKey, 0, -4);
$value = array('>=' => $filterValue);
$value = ['>=' => $filterValue];
}

if ($filterKey == 'is_current' || $filterKey == 'isCurrent') {
Expand Down Expand Up @@ -110,7 +110,7 @@ protected function buildWhereClause() {
}
$operator = is_array($value) ? \CRM_Utils_Array::first(array_keys($value)) : NULL;
if (!in_array($operator, \CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
$value = array('=' => $value);
$value = ['=' => $value];
}
$filters[$key] = \CRM_Core_DAO::createSQLFilter("{$table_name}.{$column_name}", $value);
}
Expand All @@ -121,10 +121,10 @@ protected function buildWhereClause() {
$orGroups = array_map('trim', explode(',', $orGroups));
}
if (!is_array(\CRM_Utils_Array::first($orGroups))) {
$orGroups = array($orGroups);
$orGroups = [$orGroups];
}
foreach ($orGroups as $orGroup) {
$orClause = array();
$orClause = [];
foreach ($orGroup as $key) {
if (!isset($filters[$key])) {
throw new \CiviCRM_API3_Exception("'$key' specified in OR group but not added to params");
Expand All @@ -147,11 +147,11 @@ protected function buildWhereClause() {
protected function getFields() {
require_once 'api/v3/Generic.php';
// Call this function directly instead of using the api wrapper to force unique field names off
$apiSpec = \civicrm_api3_generic_getfields(array(
$apiSpec = \civicrm_api3_generic_getfields([
'entity' => $this->entity,
'version' => 3,
'params' => array('action' => 'get'),
), FALSE);
'params' => ['action' => 'get'],
], FALSE);
return $apiSpec['values'];
}

Expand All @@ -174,7 +174,7 @@ protected function getField($fieldName) {
foreach ($this->apiFieldSpec as $field) {
if (
$fieldName == \CRM_Utils_Array::value('uniqueName', $field) ||
array_search($fieldName, \CRM_Utils_Array::value('api.aliases', $field, array())) !== FALSE
array_search($fieldName, \CRM_Utils_Array::value('api.aliases', $field, [])) !== FALSE
) {
return $field;
}
Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ class Events {
* @return array<string>
*/
public static function allEvents() {
return array(
return [
self::AUTHORIZE,
self::EXCEPTION,
self::PREPARE,
self::RESOLVE,
self::RESPOND,
);
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Exception/NotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NotImplementedException extends \API_Exception {
* @param \Exception|NULL $previous
* A previous exception which caused this new exception.
*/
public function __construct($message, $extraParams = array(), \Exception $previous = NULL) {
public function __construct($message, $extraParams = [], \Exception $previous = NULL) {
parent::__construct($message, \API_Exception::NOT_IMPLEMENTED, $extraParams, $previous);
}

Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Exception/UnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UnauthorizedException extends \API_Exception {
* @param \Exception|NULL $previous
* A previous exception which caused this new exception.
*/
public function __construct($message, $extraParams = array(), \Exception $previous = NULL) {
public function __construct($message, $extraParams = [], \Exception $previous = NULL) {
parent::__construct($message, \API_Exception::UNAUTHORIZED, $extraParams, $previous);
}

Expand Down
22 changes: 11 additions & 11 deletions Civi/API/ExternalBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExternalBatch {
* @param array $defaultParams
* Default values to merge into any API calls.
*/
public function __construct($defaultParams = array()) {
public function __construct($defaultParams = []) {
global $civicrm_root;
$this->root = $civicrm_root;
$this->settingsPath = defined('CIVICRM_SETTINGS_PATH') ? CIVICRM_SETTINGS_PATH : NULL;
Expand All @@ -65,14 +65,14 @@ public function __construct($defaultParams = array()) {
* @param array $params
* @return ExternalBatch
*/
public function addCall($entity, $action, $params = array()) {
public function addCall($entity, $action, $params = []) {
$params = array_merge($this->defaultParams, $params);

$this->apiCalls[] = array(
$this->apiCalls[] = [
'entity' => $entity,
'action' => $action,
'params' => $params,
);
];
return $this;
}

Expand Down Expand Up @@ -124,15 +124,15 @@ public function wait() {
if (!$process->isRunning()) {
$parsed = json_decode($process->getOutput(), TRUE);
if ($process->getExitCode() || $parsed === NULL) {
$this->apiResults[] = array(
$this->apiResults[] = [
'is_error' => 1,
'error_message' => 'External API returned malformed response.',
'trace' => array(
'trace' => [
'code' => $process->getExitCode(),
'stdout' => $process->getOutput(),
'stderr' => $process->getErrorOutput(),
),
);
],
];
}
else {
$this->apiResults[] = $parsed;
Expand Down Expand Up @@ -183,7 +183,7 @@ public function isSupported() {
* @throws \CRM_Core_Exception
*/
public function createProcess($apiCall) {
$parts = array();
$parts = [];

if (defined('CIVICRM_TEST') && CIVICRM_TEST) {
// When testing, civicrm.settings.php may rely on $_CV, which is only
Expand Down Expand Up @@ -214,9 +214,9 @@ public function createProcess($apiCall) {
}

$command = implode(" ", $parts);
$env = array_merge($this->env, array(
$env = array_merge($this->env, [
'CIVICRM_SETTINGS' => $this->settingsPath,
));
]);
return new Process($command, $this->root, $env);
}

Expand Down
12 changes: 6 additions & 6 deletions Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Kernel {
* @param array $apiProviders
* Array of ProviderInterface.
*/
public function __construct($dispatcher, $apiProviders = array()) {
public function __construct($dispatcher, $apiProviders = []) {
$this->apiProviders = $apiProviders;
$this->dispatcher = $dispatcher;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public function resolve($apiRequest) {
if (!$resolveEvent->getApiProvider()) {
throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
}
return array($resolveEvent->getApiProvider(), $apiRequest);
return [$resolveEvent->getApiProvider(), $apiRequest];
}

/**
Expand Down Expand Up @@ -285,7 +285,7 @@ public function respond($apiProvider, $apiRequest, $result) {
*/
public function getEntityNames($version) {
// Question: Would it better to eliminate $this->apiProviders and just use $this->dispatcher?
$entityNames = array();
$entityNames = [];
foreach ($this->getApiProviders() as $provider) {
/** @var ProviderInterface $provider */
$entityNames = array_merge($entityNames, $provider->getEntityNames($version));
Expand All @@ -305,7 +305,7 @@ public function getEntityNames($version) {
*/
public function getActionNames($version, $entity) {
// Question: Would it better to eliminate $this->apiProviders and just use $this->dispatcher?
$actionNames = array();
$actionNames = [];
foreach ($this->getApiProviders() as $provider) {
/** @var ProviderInterface $provider */
$actionNames = array_merge($actionNames, $provider->getActionNames($version, $entity));
Expand All @@ -324,7 +324,7 @@ public function getActionNames($version, $entity) {
* API response.
*/
public function formatException($e, $apiRequest) {
$data = array();
$data = [];
if (!empty($apiRequest['params']['debug'])) {
$data['trace'] = $e->getTraceAsString();
}
Expand Down Expand Up @@ -362,7 +362,7 @@ public function formatApiException($e, $apiRequest) {
* API response.
*/
public function formatPearException($e, $apiRequest) {
$data = array();
$data = [];
$error = $e->getCause();
if ($error instanceof \DB_Error) {
$data["error_code"] = \DB::errorMessage($error->getCode());
Expand Down
26 changes: 13 additions & 13 deletions Civi/API/Provider/AdhocProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ public static function getSubscribedEvents() {
// Using a high priority allows adhoc implementations
// to override standard implementations -- which is
// handy for testing/mocking.
return array(
Events::RESOLVE => array(
array('onApiResolve', Events::W_EARLY),
),
Events::AUTHORIZE => array(
array('onApiAuthorize', Events::W_EARLY),
),
);
return [
Events::RESOLVE => [
['onApiResolve', Events::W_EARLY],
],
Events::AUTHORIZE => [
['onApiAuthorize', Events::W_EARLY],
],
];
}

/**
* @var array (string $name => array('perm' => string, 'callback' => callable))
*/
protected $actions = array();
protected $actions = [];

/**
* @var string
Expand Down Expand Up @@ -90,10 +90,10 @@ public function __construct($version, $entity) {
* @return AdhocProvider
*/
public function addAction($name, $perm, $callback) {
$this->actions[strtolower($name)] = array(
$this->actions[strtolower($name)] = [
'perm' => $perm,
'callback' => $callback,
);
];
return $this;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public function invoke($apiRequest) {
* @return array
*/
public function getEntityNames($version) {
return array($this->entity);
return [$this->entity];
}

/**
Expand All @@ -151,7 +151,7 @@ public function getActionNames($version, $entity) {
return array_keys($this->actions);
}
else {
return array();
return [];
}
}

Expand Down
Loading

0 comments on commit a073564

Please sign in to comment.