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

ENH PHP 8.1 compatibility #222

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/BulkManager/BulkAction/ArchiveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function archive(HTTPRequest $request)
}
}

$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,
Expand Down
2 changes: 1 addition & 1 deletion src/BulkManager/BulkAction/DeleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function delete(HTTPRequest $request)
$record->delete();
}

$doneCount = count($response->getSuccessRecords());
$doneCount = count($response->getSuccessRecords() ?? []);
$message = sprintf(
'Deleted %1$d records.',
$doneCount
Expand Down
4 changes: 2 additions & 2 deletions src/BulkManager/BulkAction/EditHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function bulkEditForm()
$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());
Expand Down Expand Up @@ -341,7 +341,7 @@ protected function escapeFieldName($recordID, $name)
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;
Expand Down
4 changes: 2 additions & 2 deletions src/BulkManager/BulkAction/PublishHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function publish(HTTPRequest $request)
}
}

$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,
Expand Down
4 changes: 2 additions & 2 deletions src/BulkManager/BulkAction/UnPublishHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function unPublish(HTTPRequest $request)
}
}

$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,
Expand Down
10 changes: 5 additions & 5 deletions src/BulkManager/BulkManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($editableFields = null, $defaultActions = true, $def
*/
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);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public function getConfig($reference = false)
*/
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);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public function getBulkActions()
*/
public function augmentColumns($gridField, &$columns)
{
if (!in_array('BulkSelect', $columns)) {
if (!in_array('BulkSelect', $columns ?? [])) {
$columns[] = 'BulkSelect';
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public function getHTMLFragments($gridField)
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);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ public function getHTMLFragments($gridField)
'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);
Expand Down
2 changes: 1 addition & 1 deletion src/BulkTools/HTTPBulkToolsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function createBody()
$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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BulkUploader/BulkUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function upload(HTTPRequest $request)
$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)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/BulkUploader/BulkUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct($fileRelationName = null, $recordClassName = null, $
*/
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);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public function getHTMLFragments($gridField)
$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
));

Expand Down