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

Copy missing core function #137

Merged
merged 1 commit into from
Jul 22, 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
20 changes: 20 additions & 0 deletions Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* TODO: Use `Civi::entity()->getFields()` instead of DAO::fields()
* so we don't need this copied function
*/
private static function arrayToField(array $data, string $entityName): FieldSpec {

Check failure on line 49 in Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's cyclomatic complexity (26) exceeds allowed maximum of 20
$dataTypeName = self::getDataType($data);

$hasDefault = isset($data['default']) && $data['default'] !== '';
Expand Down Expand Up @@ -116,6 +116,26 @@
return $field;
}

/**
* Get the data type from an array. Defaults to 'data_type' with fallback to
* mapping for the integer value 'type'
*
* @param array $data
*
* @return string
*/
private static function getDataType(array $data) {
$dataType = $data['data_type'] ?? $data['dataType'] ?? NULL;
if (isset($dataType)) {
return !empty($data['time_format']) ? 'Timestamp' : $dataType;
}

$dataTypeInt = $data['type'] ?? NULL;
$dataTypeName = \CRM_Utils_Type::typeToString($dataTypeInt);

return $dataTypeName === 'Int' ? 'Integer' : $dataTypeName;
}

/**
* Copied from \Civi\Api4\Service\Spec\SpecFormatter
*
Expand All @@ -123,7 +143,7 @@
* @param array $data
* @param string $dataTypeName
*/
private static function setInputTypeAndAttrs(FieldSpec $fieldSpec, $data, $dataTypeName) {

Check failure on line 146 in Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's cyclomatic complexity (24) exceeds allowed maximum of 20
$inputType = $data['html']['type'] ?? $data['html_type'] ?? NULL;
$inputAttrs = $data['html'] ?? [];
unset($inputAttrs['type']);
Expand Down Expand Up @@ -211,7 +231,7 @@
if (empty(\Civi::$statics['legacyDatePrefs'][$inputAttrs['formatType']])) {
\Civi::$statics['legacyDatePrefs'][$inputAttrs['formatType']] = [];
$params = ['name' => $inputAttrs['formatType']];
\CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_PreferencesDate', $params, \Civi::$statics['legacyDatePrefs'][$inputAttrs['formatType']]);

Check warning on line 234 in Civi/Api4/Service/Spec/Provider/EckEntitySpecProvider.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Line exceeds 120 characters; contains 140 characters
}
$dateFormat = \Civi::$statics['legacyDatePrefs'][$inputAttrs['formatType']];
unset($inputAttrs['formatType']);
Expand Down
Loading