diff --git a/Civi/Api4/Query/Api4SelectQuery.php b/Civi/Api4/Query/Api4SelectQuery.php index db5016e88036..34d24f563b31 100644 --- a/Civi/Api4/Query/Api4SelectQuery.php +++ b/Civi/Api4/Query/Api4SelectQuery.php @@ -20,7 +20,6 @@ use Civi\Api4\Utils\CoreUtil; use Civi\Api4\Utils\SelectUtil; use CRM_Core_DAO_AllCoreTables as AllCoreTables; -use CRM_Utils_Array as UtilsArray; /** * A query `node` may be in one of three formats: @@ -200,7 +199,7 @@ protected function buildSelectFields() { $this->selectFields[$this->fkSelectAliases[$fieldName]] = $fieldName; } elseif ($field && in_array($field['name'], $this->entityFieldNames)) { - $this->selectFields[self::MAIN_TABLE_ALIAS . "." . UtilsArray::value('column_name', $field, $field['name'])] = $field['name']; + $this->selectFields[self::MAIN_TABLE_ALIAS . "." . ($field['column_name'] ?? $field['name'])] = $field['name']; } } } @@ -326,7 +325,7 @@ protected function getField($fieldName) { if (count($fieldPath) > 1) { $fieldName = implode('.', array_slice($fieldPath, -2)); } - return UtilsArray::value($fieldName, $this->apiFieldSpec); + return $this->apiFieldSpec[$fieldName] ?? NULL; } return NULL; } diff --git a/Civi/Api4/Service/Schema/SchemaMapBuilder.php b/Civi/Api4/Service/Schema/SchemaMapBuilder.php index 4a82d826b820..66efeb3a85e1 100644 --- a/Civi/Api4/Service/Schema/SchemaMapBuilder.php +++ b/Civi/Api4/Service/Schema/SchemaMapBuilder.php @@ -29,7 +29,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Civi\Api4\Service\Schema\Joinable\OptionValueJoinable; use CRM_Core_DAO_AllCoreTables as AllCoreTables; -use CRM_Utils_Array as UtilsArray; class SchemaMapBuilder { /** @@ -89,18 +88,18 @@ private function loadTables(SchemaMap $map) { * @param array $data */ private function addJoins(Table $table, $field, array $data) { - $fkClass = UtilsArray::value('FKClassName', $data); + $fkClass = $data['FKClassName'] ?? NULL; // can there be multiple methods e.g. pseudoconstant and fkclass if ($fkClass) { $tableName = AllCoreTables::getTableForClass($fkClass); - $fkKey = UtilsArray::value('FKKeyColumn', $data, 'id'); + $fkKey = $data['FKKeyColumn'] ?? 'id'; $alias = str_replace('_id', '', $field); $joinable = new Joinable($tableName, $fkKey, $alias); $joinable->setJoinType($joinable::JOIN_TYPE_MANY_TO_ONE); $table->addTableLink($field, $joinable); } - elseif (UtilsArray::value('pseudoconstant', $data)) { + elseif (!empty($data['pseudoconstant'])) { $this->addPseudoConstantJoin($table, $field, $data); } } @@ -111,22 +110,22 @@ private function addJoins(Table $table, $field, array $data) { * @param array $data */ private function addPseudoConstantJoin(Table $table, $field, array $data) { - $pseudoConstant = UtilsArray::value('pseudoconstant', $data); - $tableName = UtilsArray::value('table', $pseudoConstant); - $optionGroupName = UtilsArray::value('optionGroupName', $pseudoConstant); - $keyColumn = UtilsArray::value('keyColumn', $pseudoConstant, 'id'); + $pseudoConstant = $data['pseudoconstant'] ?? NULL; + $tableName = $pseudoConstant['table'] ?? NULL; + $optionGroupName = $pseudoConstant['optionGroupName'] ?? NULL; + $keyColumn = $pseudoConstant['keyColumn'] ?? 'id'; if ($tableName) { $alias = str_replace('civicrm_', '', $tableName); $joinable = new Joinable($tableName, $keyColumn, $alias); - $condition = UtilsArray::value('condition', $pseudoConstant); + $condition = $pseudoConstant['condition'] ?? NULL; if ($condition) { $joinable->addCondition($condition); } $table->addTableLink($field, $joinable); } elseif ($optionGroupName) { - $keyColumn = UtilsArray::value('keyColumn', $pseudoConstant, 'value'); + $keyColumn = $pseudoConstant['keyColumn'] ?? 'value'; $joinable = new OptionValueJoinable($optionGroupName, NULL, $keyColumn); if (!empty($data['serialize'])) { diff --git a/Civi/Api4/Service/Spec/SpecFormatter.php b/Civi/Api4/Service/Spec/SpecFormatter.php index 1cfc94561964..b09a47157ab2 100644 --- a/Civi/Api4/Service/Spec/SpecFormatter.php +++ b/Civi/Api4/Service/Spec/SpecFormatter.php @@ -21,7 +21,6 @@ namespace Civi\Api4\Service\Spec; -use CRM_Utils_Array as ArrayHelper; use CRM_Core_DAO_AllCoreTables as AllCoreTables; class SpecFormatter { @@ -64,32 +63,32 @@ public static function arrayToField(array $data, $entity) { $field->setCustomTableName($data['custom_group.table_name']); $field->setCustomFieldColumnName($data['column_name']); } - $field->setCustomFieldId(ArrayHelper::value('id', $data)); + $field->setCustomFieldId($data['id'] ?? NULL); $field->setCustomGroupName($data['custom_group.name']); - $field->setTitle(ArrayHelper::value('label', $data)); - $field->setHelpPre(ArrayHelper::value('help_pre', $data)); - $field->setHelpPost(ArrayHelper::value('help_post', $data)); + $field->setTitle($data['label'] ?? NULL); + $field->setHelpPre($data['help_pre'] ?? NULL); + $field->setHelpPost($data['help_post'] ?? NULL); $field->setOptions(self::customFieldHasOptions($data)); if (\CRM_Core_BAO_CustomField::isSerialized($data)) { $field->setSerialize(\CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND); } } else { - $name = ArrayHelper::value('name', $data); + $name = $data['name'] ?? NULL; $field = new FieldSpec($name, $entity, $dataTypeName); - $field->setRequired((bool) ArrayHelper::value('required', $data, FALSE)); - $field->setTitle(ArrayHelper::value('title', $data)); + $field->setRequired(!empty($data['required'])); + $field->setTitle($data['title'] ?? NULL); $field->setOptions(!empty($data['pseudoconstant'])); - $field->setSerialize(ArrayHelper::value('serialize', $data)); + $field->setSerialize($data['serialize'] ?? NULL); } - $field->setDefaultValue(ArrayHelper::value('default', $data)); - $field->setDescription(ArrayHelper::value('description', $data)); + $field->setDefaultValue($data['default'] ?? NULL); + $field->setDescription($data['description'] ?? NULL); self::setInputTypeAndAttrs($field, $data, $dataTypeName); - $field->setPermission(ArrayHelper::value('permission', $data)); - $fkAPIName = ArrayHelper::value('FKApiName', $data); - $fkClassName = ArrayHelper::value('FKClassName', $data); + $field->setPermission($data['permission'] ?? NULL); + $fkAPIName = $data['FKApiName'] ?? NULL; + $fkClassName = $data['FKClassName'] ?? NULL; if ($fkAPIName || $fkClassName) { $field->setFkEntity($fkAPIName ?: AllCoreTables::getBriefName($fkClassName)); } @@ -132,7 +131,7 @@ private static function getDataType(array $data) { return !empty($data['time_format']) ? 'Timestamp' : $data['data_type']; } - $dataTypeInt = ArrayHelper::value('type', $data); + $dataTypeInt = $data['type'] ?? NULL; $dataTypeName = \CRM_Utils_Type::typeToString($dataTypeInt); return $dataTypeName; @@ -144,8 +143,8 @@ private static function getDataType(array $data) { * @param string $dataTypeName */ public static function setInputTypeAndAttrs(FieldSpec &$fieldSpec, $data, $dataTypeName) { - $inputType = $data['html']['type'] ?? ArrayHelper::value('html_type', $data); - $inputAttrs = ArrayHelper::value('html', $data, []); + $inputType = $data['html']['type'] ?? $data['html_type'] ?? NULL; + $inputAttrs = $data['html'] ?? []; unset($inputAttrs['type']); if (strstr($inputType, 'Multi-Select') || ($inputType == 'Select' && !empty($data['serialize']))) { @@ -158,7 +157,7 @@ public static function setInputTypeAndAttrs(FieldSpec &$fieldSpec, $data, $dataT 'Select Date' => 'Date', 'Link' => 'Url', ]; - $inputType = ArrayHelper::value($inputType, $map, $inputType); + $inputType = $map[$inputType] ?? $inputType; if ($inputType == 'Date' && !empty($inputAttrs['formatType'])) { self::setLegacyDateFormat($inputAttrs); } diff --git a/Civi/Api4/Utils/ArrayInsertionUtil.php b/Civi/Api4/Utils/ArrayInsertionUtil.php index 0011a01b32d5..4c2d2f6b2d53 100644 --- a/Civi/Api4/Utils/ArrayInsertionUtil.php +++ b/Civi/Api4/Utils/ArrayInsertionUtil.php @@ -21,8 +21,6 @@ namespace Civi\Api4\Utils; -use CRM_Utils_Array as UtilsArray; - class ArrayInsertionUtil { /** @@ -67,11 +65,11 @@ public static function insert(&$array, $parts, $values) { * @return array|mixed */ private static function filterValues($parentArray, $isMulti, $values) { - $parentID = UtilsArray::value('id', $parentArray); + $parentID = $parentArray['id'] ?? NULL; if ($parentID) { $values = array_filter($values, function ($value) use ($parentID) { - return UtilsArray::value('_parent_id', $value) == $parentID; + return ($value['_parent_id'] ?? NULL) == $parentID; }); } diff --git a/tests/phpunit/api/v4/Traits/QueryCounterTrait.php b/tests/phpunit/api/v4/Traits/QueryCounterTrait.php index 8494ec1d0f5c..81c97b05e0bc 100644 --- a/tests/phpunit/api/v4/Traits/QueryCounterTrait.php +++ b/tests/phpunit/api/v4/Traits/QueryCounterTrait.php @@ -21,8 +21,6 @@ namespace api\v4\Traits; -use CRM_Utils_Array as ArrayHelper; - trait QueryCounterTrait { /** @@ -56,7 +54,7 @@ private function getCurrentGlobalQueryCount() { throw new \Exception('Database object not set so cannot count queries'); } - return ArrayHelper::value('RESULTSEQ', $_DB_DATAOBJECT, 0); + return $_DB_DATAOBJECT['RESULTSEQ'] ?? 0; } }