Remove unused references to CRM_Core_Exception aliases
authorColeman Watts <coleman@civicrm.org>
Thu, 15 Sep 2022 19:27:00 +0000 (15:27 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 16 Sep 2022 14:36:25 +0000 (10:36 -0400)
Civi/API/Exception/NotImplementedException.php
Civi/API/Exception/UnauthorizedException.php
Civi/API/Kernel.php
tests/phpunit/api/v4/Api4TestBase.php

index 6deb57071d804fecda1b4e86097af15190df75b4..c3cf691dc3f47c94083bbb4ea585a289b9a67423 100644 (file)
@@ -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
@@ -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);
   }
 
 }
index 12e44bda3de5d4404db085b7275bdac0e2b8b159..1e284ee17ee8b929ddaf86124012249253ea72ba 100644 (file)
@@ -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
@@ -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);
   }
 
 }
index 8dae508a790b552d918d849347e68a7e5a3b4e64..8c393756c6e68ff7d2ec858f12b1762ef2b020e8 100644 (file)
@@ -52,7 +52,7 @@ class Kernel {
    *   Array to be passed to API function.
    *
    * @return array|int
-   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
    * @see runSafe
    * @deprecated
    */
@@ -72,7 +72,7 @@ class Kernel {
    *   Array to be passed to API function.
    *
    * @return array|int
-   * @throws \API_Exception
+   * @throws \CRM_Core_Exception
    */
   public function runSafe($entity, $action, $params) {
     $apiRequest = [];
@@ -86,7 +86,7 @@ class Kernel {
         $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) {
@@ -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<type>.
    */
@@ -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;
index 3b6f6f260e61ffcc14850b48384bf6a083712333..49b5aab024c59e5e62e135334f47ba0fe2457ce8 100644 (file)
@@ -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];