Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] ContactType - Cleanup function docs & type hints #28996

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions CRM/Contact/BAO/ContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,27 @@ public static function isActive($contactType) {
}

/**
* Retrieve basic contact type information.
* Retrieve base contact type information.
*
* @param bool $includeInactive
*
* @return array
* Array of basic contact types information.
*
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
* @return array[]
* Array of base contact types keyed by name.
*/
public static function basicTypeInfo($includeInactive = FALSE) {
public static function basicTypeInfo($includeInactive = FALSE): array {
return array_filter(self::getAllContactTypes(), function($type) use ($includeInactive) {
return empty($type['parent']) && ($includeInactive || $type['is_active']);
});
}

/**
* Retrieve all basic contact types.
* Get names of base contact types e.g. [Individual, Household, Organization]
*
* @param bool $all
*
* @return array
* Array of basic contact types
*
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
* @param bool $includeInactive
* @return string[]
*/
public static function basicTypes($all = FALSE): array {
return array_keys(self::basicTypeInfo($all));
public static function basicTypes($includeInactive = FALSE): array {
return array_keys(self::basicTypeInfo($includeInactive));
}

/**
Expand Down Expand Up @@ -830,10 +822,9 @@ public static function deleteCustomRowsForEntityID($customTable, $entityID) {
* Note, this function is used within APIv4 Entity.get, so must use a
* SQL query instead of calling APIv4 to avoid an infinite loop.
*
* @return array
* @throws \CRM_Core_Exception
* @return array[]
*/
public static function getAllContactTypes() {
public static function getAllContactTypes(): array {
$cache = Civi::cache('contactTypes');
$cacheKey = 'all_' . $GLOBALS['tsLocale'];
$contactTypes = $cache->get($cacheKey);
Expand All @@ -844,7 +835,7 @@ public static function getAllContactTypes() {
$dao = CRM_Core_DAO::executeQuery($query->toSQL());
$contactTypes = array_column($dao->fetchAll(), NULL, 'name');
$parents = array_column($contactTypes, NULL, 'id');
foreach ($contactTypes as $name => &$contactType) {
foreach ($contactTypes as &$contactType) {
// Cast int/bool types.
self::formatFieldValues($contactType);
// Fill data from parents
Expand Down