From 8d6ceca5483b69b072534c837c5e4f836c8305db Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 21 Sep 2023 21:58:29 -0400 Subject: [PATCH] APIv4 - Remove function that doesn't do anything, add some type hints --- Civi/Api4/EntitySet.php | 2 +- Civi/Api4/Generic/AbstractEntity.php | 15 +++------------ Civi/Api4/Utils/ReflectionUtils.php | 4 ++-- ext/civi_case/Civi/Api4/CaseContact.php | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Civi/Api4/EntitySet.php b/Civi/Api4/EntitySet.php index b77fdae15a..d11b33e7c8 100644 --- a/Civi/Api4/EntitySet.php +++ b/Civi/Api4/EntitySet.php @@ -57,7 +57,7 @@ class EntitySet extends Generic\AbstractEntity { * @param bool $plural * @return string */ - protected static function getEntityTitle($plural = FALSE) { + protected static function getEntityTitle(bool $plural = FALSE): string { return $plural ? ts('Entity Sets') : ts('Entity Set'); } diff --git a/Civi/Api4/Generic/AbstractEntity.php b/Civi/Api4/Generic/AbstractEntity.php index cf5066410b..5caca47384 100644 --- a/Civi/Api4/Generic/AbstractEntity.php +++ b/Civi/Api4/Generic/AbstractEntity.php @@ -85,21 +85,12 @@ abstract class AbstractEntity { * Whether to return a plural title. * @return string */ - protected static function getEntityTitle($plural = FALSE) { + protected static function getEntityTitle(bool $plural = FALSE): string { $name = static::getEntityName(); $dao = \CRM_Core_DAO_AllCoreTables::getFullName($name); return $dao ? $dao::getEntityTitle($plural) : ($plural ? \CRM_Utils_String::pluralize($name) : $name); } - /** - * Overridable function to return menu paths related to this entity. - * - * @return array - */ - protected static function getEntityPaths() { - return []; - } - /** * Magic method to return the action object for an api. * @@ -138,7 +129,7 @@ abstract class AbstractEntity { 'title' => static::getEntityTitle(), 'title_plural' => static::getEntityTitle(TRUE), 'type' => [self::stripNamespace(get_parent_class(static::class))], - 'paths' => static::getEntityPaths(), + 'paths' => [], 'class' => static::class, 'primary_key' => ['id'], // Entities without a @searchable annotation will default to secondary, @@ -194,7 +185,7 @@ abstract class AbstractEntity { * @param string $className * @return string */ - private static function stripNamespace($className) { + private static function stripNamespace(string $className): string { return substr($className, strrpos($className, '\\') + 1); } diff --git a/Civi/Api4/Utils/ReflectionUtils.php b/Civi/Api4/Utils/ReflectionUtils.php index 409c87db04..cc9b78d189 100644 --- a/Civi/Api4/Utils/ReflectionUtils.php +++ b/Civi/Api4/Utils/ReflectionUtils.php @@ -142,9 +142,9 @@ class ReflectionUtils { * List all traits used by a class and its parents. * * @param object|string $class - * @return array + * @return string[] */ - public static function getTraits($class) { + public static function getTraits($class): array { $traits = []; // Get traits of this class + parent classes do { diff --git a/ext/civi_case/Civi/Api4/CaseContact.php b/ext/civi_case/Civi/Api4/CaseContact.php index da651d499f..ec24f1f281 100644 --- a/ext/civi_case/Civi/Api4/CaseContact.php +++ b/ext/civi_case/Civi/Api4/CaseContact.php @@ -23,7 +23,7 @@ namespace Civi\Api4; class CaseContact extends Generic\DAOEntity { use Generic\Traits\EntityBridge; - protected static function getEntityTitle($plural = FALSE) { + protected static function getEntityTitle(bool $plural = FALSE): string { return $plural ? ts('Case Clients') : ts('Case Client'); } -- 2.25.1