From 11b9def49f8c59323cf461921357cf218d22e331 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 15 Sep 2022 15:27:00 -0400 Subject: [PATCH] Remove unused references to CRM_Core_Exception aliases --- .../API/Exception/NotImplementedException.php | 6 ++-- Civi/API/Exception/UnauthorizedException.php | 6 ++-- Civi/API/Kernel.php | 29 +++++++++---------- tests/phpunit/api/v4/Api4TestBase.php | 12 ++++---- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/Civi/API/Exception/NotImplementedException.php b/Civi/API/Exception/NotImplementedException.php index 6deb57071d..c3cf691dc3 100644 --- a/Civi/API/Exception/NotImplementedException.php +++ b/Civi/API/Exception/NotImplementedException.php @@ -1,13 +1,11 @@ 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) { @@ -136,7 +136,7 @@ class Kernel { * * @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 */ @@ -155,10 +155,9 @@ class Kernel { * 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. @@ -166,7 +165,7 @@ class Kernel { 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; @@ -176,13 +175,13 @@ class Kernel { 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) { } @@ -305,7 +304,7 @@ class Kernel { * * @return array * API response. - * @throws \API_Exception + * @throws \CRM_Core_Exception */ public function formatException($e, $apiRequest) { $data = []; @@ -316,14 +315,14 @@ class Kernel { } /** - * @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(); @@ -349,7 +348,7 @@ class Kernel { * @return array * API response. * - * @throws \API_Exception + * @throws \CRM_Core_Exception */ public function formatPearException($e, $apiRequest) { $data = []; @@ -384,7 +383,7 @@ class Kernel { * @param mixed $code * Doesn't appear to be used. * - * @throws \API_Exception + * @throws \CRM_Core_Exception * @return array * Array. */ @@ -404,7 +403,7 @@ class Kernel { 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; diff --git a/tests/phpunit/api/v4/Api4TestBase.php b/tests/phpunit/api/v4/Api4TestBase.php index 3b6f6f260e..49b5aab024 100644 --- a/tests/phpunit/api/v4/Api4TestBase.php +++ b/tests/phpunit/api/v4/Api4TestBase.php @@ -23,8 +23,6 @@ use Civi\Api4\UFMatch; use Civi\Api4\Utils\CoreUtil; use Civi\Test\HeadlessInterface; -require_once 'api/Exception.php'; - /** * @group headless */ @@ -123,7 +121,7 @@ class Api4TestBase extends \PHPUnit\Framework\TestCase implements HeadlessInterf * @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 = []) { @@ -138,7 +136,7 @@ class Api4TestBase extends \PHPUnit\Framework\TestCase implements HeadlessInterf * @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) { @@ -167,7 +165,7 @@ class Api4TestBase extends \PHPUnit\Framework\TestCase implements HeadlessInterf * @param array $values * * @return array - * @throws \API_Exception + * @throws \CRM_Core_Exception */ public function getRequiredValuesToCreate(string $entity, &$values = []) { $requiredFields = civicrm_api4($entity, 'getfields', [ @@ -313,7 +311,7 @@ class Api4TestBase extends \PHPUnit\Framework\TestCase implements HeadlessInterf return $randomValue; } - throw new \API_Exception('Could not provide default value'); + throw new \CRM_Core_Exception('Could not provide default value'); } /** @@ -323,7 +321,7 @@ class Api4TestBase extends \PHPUnit\Framework\TestCase implements HeadlessInterf * * @return int * - * @throws \API_Exception + * @throws \CRM_Core_Exception */ private function getFkID(string $fkEntity) { $params = ['checkPermissions' => FALSE]; -- 2.25.1