ENH PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-13 14:08:15 +12:00
parent c34bba4508
commit 81f34cdd7b
9 changed files with 18 additions and 18 deletions

View File

@ -111,8 +111,8 @@ class ArchiveHandler extends Handler
}
}
$doneCount = count($response->getSuccessRecords());
$failCount = count($response->getFailedRecords());
$doneCount = count($response->getSuccessRecords() ?? []);
$failCount = count($response->getFailedRecords() ?? []);
$message = sprintf(
'Archived %1$d of %2$d records.',
$doneCount,

View File

@ -104,7 +104,7 @@ class DeleteHandler extends Handler
$record->delete();
}
$doneCount = count($response->getSuccessRecords());
$doneCount = count($response->getSuccessRecords() ?? []);
$message = sprintf(
'Deleted %1$d records.',
$doneCount

View File

@ -148,7 +148,7 @@ class EditHandler extends Handler
$recordsFieldList = new FieldList();
$config = $this->component->getConfig();
$editingCount = count($recordList);
$editingCount = count($recordList ?? []);
$modelClass = $this->gridField->getModelClass();
$singleton = singleton($modelClass);
$titleModelClass = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());
@ -341,7 +341,7 @@ class EditHandler extends Handler
protected function unEscapeFieldName($fieldName)
{
$parts = array();
$match = preg_match('/record_(\d+)_(\w+)/i', $fieldName, $parts);
$match = preg_match('/record_(\d+)_(\w+)/i', $fieldName ?? '', $parts);
if (!$match) {
return false;

View File

@ -111,8 +111,8 @@ class PublishHandler extends Handler
}
}
$doneCount = count($response->getSuccessRecords());
$failCount = count($response->getFailedRecords());
$doneCount = count($response->getSuccessRecords() ?? []);
$failCount = count($response->getFailedRecords() ?? []);
$message = sprintf(
'Published %1$d of %2$d records.',
$doneCount,

View File

@ -111,8 +111,8 @@ class UnPublishHandler extends Handler
}
}
$doneCount = count($response->getSuccessRecords());
$failCount = count($response->getFailedRecords());
$doneCount = count($response->getSuccessRecords() ?? []);
$failCount = count($response->getFailedRecords() ?? []);
$message = sprintf(
'UnPublished %1$d of %2$d records.',
$doneCount,

View File

@ -79,7 +79,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
*/
public function setConfig($reference, $value)
{
if (!array_key_exists($reference, $this->config)) {
if (!array_key_exists($reference, $this->config ?? [])) {
user_error("Unknown option reference: $reference", E_USER_ERROR);
}
@ -123,7 +123,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
*/
public function addBulkAction($handlerClassName, $action = null)
{
if (!class_exists($handlerClassName)) {
if (!class_exists($handlerClassName ?? '')) {
user_error("Bulk action handler not found: $handlerClassName", E_USER_ERROR);
}
@ -188,7 +188,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('BulkSelect', $columns)) {
if (!in_array('BulkSelect', $columns ?? [])) {
$columns[] = 'BulkSelect';
}
}
@ -267,7 +267,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
Requirements::css('colymba/gridfield-bulk-editing-tools:client/dist/styles/main.css');
Requirements::add_i18n_javascript('colymba/gridfield-bulk-editing-tools:client/lang');
if (!count($this->config['actions'])) {
if (!count($this->config['actions'] ?? [])) {
user_error('Trying to use BulkManager without any bulk action.', E_USER_ERROR);
}
@ -302,7 +302,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
'Select' => array(
'Label' => _t('GRIDFIELD_BULK_MANAGER.SELECT_ALL_LABEL', 'Select all'),
),
'Colspan' => (count($gridField->getColumns()) - 1),
'Colspan' => (count($gridField->getColumns() ?? []) - 1),
);
$templateData = new ArrayData($templateData);

View File

@ -344,7 +344,7 @@ class HTTPBulkToolsResponse extends HTTPResponse
$body['records']['failed'] = $this->failedRecords;
}
if (isset($body['records']['success']) && count($body['records']['success']) === 0) {
if (isset($body['records']['success']) && count($body['records']['success'] ?? []) === 0) {
$body['isWarning'] = true;
}

View File

@ -121,7 +121,7 @@ class BulkUploadHandler extends RequestHandler
$bulkToolsResponse = new HTTPBulkToolsResponse(false, $this->gridField);
$bulkToolsResponse->addSuccessRecord($record);
$responseData['bulkTools'] = json_decode($bulkToolsResponse->getBody());
$responseData['bulkTools'] = json_decode($bulkToolsResponse->getBody() ?? '');
$uploadResponse->setBody(json_encode(array($responseData)));
}

View File

@ -86,7 +86,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
*/
public function setConfig($reference, $value)
{
if (!array_key_exists($reference, $this->config)) {
if (!array_key_exists($reference, $this->config ?? [])) {
user_error("Unknown option reference: $reference", E_USER_ERROR);
}
@ -291,7 +291,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
$uploadField = $this->bulkUploadField($gridField);
$data = ArrayData::create(array(
'Colspan' => (count($gridField->getColumns())),
'Colspan' => (count($gridField->getColumns() ?? [])),
'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order
));