Skip to content

Commit

Permalink
Remove unused references to CRM_Core_Exception aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Sep 15, 2022
1 parent 5800631 commit 6feb8b0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
6 changes: 0 additions & 6 deletions CRM/Core/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ public function register($prepend = FALSE) {
* @param $class
*/
public function loadClass($class) {
if ($class === 'CiviCRM_API3_Exception' || $class === 'API_Exception') {
//call internal error class api/Exception first
// allow api/Exception class call external error class
// CiviCRM_API3_Exception
require_once 'api/Exception.php';
}
if (
// Only load classes that clearly belong to CiviCRM.
// Note: api/v3 does not use classes, but api_v3's test-suite does
Expand Down
6 changes: 2 additions & 4 deletions Civi/API/Exception/NotImplementedException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php
namespace Civi\API\Exception;

require_once 'api/Exception.php';

/**
* Class NotImplementedException
* @package Civi\API\Exception
*/
class NotImplementedException extends \API_Exception {
class NotImplementedException extends \CRM_Core_Exception {

/**
* @param string $message
Expand All @@ -20,7 +18,7 @@ class NotImplementedException extends \API_Exception {
* A previous exception which caused this new exception.
*/
public function __construct($message, $extraParams = [], \Exception $previous = NULL) {
parent::__construct($message, \API_Exception::NOT_IMPLEMENTED, $extraParams, $previous);
parent::__construct($message, \CRM_Core_Exception::NOT_IMPLEMENTED, $extraParams, $previous);
}

}
6 changes: 2 additions & 4 deletions Civi/API/Exception/UnauthorizedException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php
namespace Civi\API\Exception;

require_once 'api/Exception.php';

/**
* Class UnauthorizedException
* @package Civi\API\Exception
*/
class UnauthorizedException extends \API_Exception {
class UnauthorizedException extends \CRM_Core_Exception {

/**
* @param string $message
Expand All @@ -20,7 +18,7 @@ class UnauthorizedException extends \API_Exception {
* A previous exception which caused this new exception.
*/
public function __construct($message, $extraParams = [], \Exception $previous = NULL) {
parent::__construct($message, \API_Exception::UNAUTHORIZED, $extraParams, $previous);
parent::__construct($message, \CRM_Core_Exception::UNAUTHORIZED, $extraParams, $previous);
}

}
29 changes: 14 additions & 15 deletions Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct($dispatcher, $apiProviders = []) {
* Array to be passed to API function.
*
* @return array|int
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @see runSafe
* @deprecated
*/
Expand All @@ -72,7 +72,7 @@ public function run($entity, $action, $params) {
* Array to be passed to API function.
*
* @return array|int
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function runSafe($entity, $action, $params) {
$apiRequest = [];
Expand All @@ -86,7 +86,7 @@ public function runSafe($entity, $action, $params) {
$this->dispatcher->dispatch('civi.api.exception', new ExceptionEvent($e, NULL, $apiRequest, $this));
}

if ($e instanceof \API_Exception) {
if ($e instanceof \CRM_Core_Exception) {
$err = $this->formatApiException($e, $apiRequest);
}
elseif ($e instanceof \PEAR_Exception) {
Expand Down Expand Up @@ -136,7 +136,7 @@ public function runAuthorize($entity, $action, $params) {
*
* @param array|\Civi\Api4\Generic\AbstractAction $apiRequest
* @return array|\Civi\Api4\Generic\Result
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
* @throws \Civi\API\Exception\UnauthorizedException
*/
Expand All @@ -155,18 +155,17 @@ public function runRequest($apiRequest) {
* Bootstrap - Load basic dependencies and sanity-check inputs.
*
* @param \Civi\Api4\Generic\AbstractAction|array $apiRequest
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function boot($apiRequest) {
require_once 'api/Exception.php';
// the create error function loads some functions from utils
// so this require is also needed for apiv4 until such time as
// we alter create error.
require_once 'api/v3/utils.php';
switch ($apiRequest['version']) {
case 3:
if (!is_array($apiRequest['params'])) {
throw new \API_Exception('Input variable `params` is not an array', 2000);
throw new \CRM_Core_Exception('Input variable `params` is not an array', 2000);
}
_civicrm_api3_initialize();
break;
Expand All @@ -176,13 +175,13 @@ public function boot($apiRequest) {
break;

default:
throw new \API_Exception('Unknown api version', 2000);
throw new \CRM_Core_Exception('Unknown api version', 2000);
}
}

/**
* @param array $apiRequest
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function validate($apiRequest) {
}
Expand Down Expand Up @@ -305,7 +304,7 @@ public function getActionNames($version, $entity) {
*
* @return array
* API response.
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function formatException($e, $apiRequest) {
$data = [];
Expand All @@ -316,14 +315,14 @@ public function formatException($e, $apiRequest) {
}

/**
* @param \API_Exception $e
* @param \CRM_Core_Exception $e
* An unhandled exception.
* @param array $apiRequest
* The full description of the API request.
*
* @return array
* (API response)
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function formatApiException($e, $apiRequest) {
$data = $e->getExtraParams();
Expand All @@ -349,7 +348,7 @@ public function formatApiException($e, $apiRequest) {
* @return array
* API response.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function formatPearException($e, $apiRequest) {
$data = [];
Expand Down Expand Up @@ -384,7 +383,7 @@ public function formatPearException($e, $apiRequest) {
* @param mixed $code
* Doesn't appear to be used.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @return array
* Array<type>.
*/
Expand All @@ -404,7 +403,7 @@ public function createError($msg, $data, $apiRequest, $code = NULL) {

if (isset($apiRequest['params']) && is_array($apiRequest['params']) && !empty($apiRequest['params']['api.has_parent'])) {
$errorCode = empty($data['error_code']) ? 'chained_api_failed' : $data['error_code'];
throw new \API_Exception('Error in call to ' . $apiRequest['entity'] . '_' . $apiRequest['action'] . ' : ' . $msg, $errorCode, $data);
throw new \CRM_Core_Exception('Error in call to ' . $apiRequest['entity'] . '_' . $apiRequest['action'] . ' : ' . $msg, $errorCode, $data);
}

return $data;
Expand Down
12 changes: 5 additions & 7 deletions tests/phpunit/api/v4/Api4TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use Civi\Api4\Utils\CoreUtil;
use Civi\Test\HeadlessInterface;

require_once 'api/Exception.php';

/**
* @group headless
*/
Expand Down Expand Up @@ -123,7 +121,7 @@ public function createLoggedInUser() {
* @param string $entityName
* @param array $values
* @return array|null
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
public function createTestRecord(string $entityName, array $values = []) {
Expand All @@ -138,7 +136,7 @@ public function createTestRecord(string $entityName, array $values = []) {
* @param string $entityName
* @param array $saveParams
* @return \Civi\Api4\Generic\Result
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
public function saveTestRecords(string $entityName, array $saveParams) {
Expand Down Expand Up @@ -167,7 +165,7 @@ public function saveTestRecords(string $entityName, array $saveParams) {
* @param array $values
*
* @return array
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function getRequiredValuesToCreate(string $entity, &$values = []) {
$requiredFields = civicrm_api4($entity, 'getfields', [
Expand Down Expand Up @@ -313,7 +311,7 @@ private function getRequiredValue(array $field) {
return $randomValue;
}

throw new \API_Exception('Could not provide default value');
throw new \CRM_Core_Exception('Could not provide default value');
}

/**
Expand All @@ -323,7 +321,7 @@ private function getRequiredValue(array $field) {
*
* @return int
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
private function getFkID(string $fkEntity) {
$params = ['checkPermissions' => FALSE];
Expand Down

0 comments on commit 6feb8b0

Please sign in to comment.