Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 13, 2022
1 parent 09b10dd commit 65da7f1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/AddToCampaignHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function getAvailableChangeSets()
*/
protected function getInChangeSets($object)
{
$inChangeSetIDs = array_unique(ChangeSetItem::get_for_object($object)->column('ChangeSetID'));
$inChangeSetIDs = array_unique(ChangeSetItem::get_for_object($object)->column('ChangeSetID') ?? []);
if ($inChangeSetIDs > 0) {
$changeSets = $this->getAvailableChangeSets()->filter([
'ID' => $inChangeSetIDs,
Expand Down
6 changes: 3 additions & 3 deletions src/CampaignAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function getPlaceholderGroups()
$classes = Config::inst()->get(ChangeSet::class, 'important_classes');

foreach ($classes as $class) {
if (!class_exists($class)) {
if (!class_exists($class ?? '')) {
continue;
}
/** @var DataObject $item */
Expand Down Expand Up @@ -441,7 +441,7 @@ public function readCampaign(HTTPRequest $request)
$accepts = $request->getAcceptMimetypes();

//accept 'text/json' for legacy reasons
if (in_array('application/json', $accepts) || in_array('text/json', $accepts)) {
if (in_array('application/json', $accepts ?? []) || in_array('text/json', $accepts ?? [])) {
$response->addHeader('Content-Type', 'application/json');
if (!$request->param('Name')) {
return (new HTTPResponse(null, 400));
Expand Down Expand Up @@ -788,7 +788,7 @@ public function save($data, $form)
$form->loadDataFrom($record);
$extra = ['record' => ['id' => $record->ID]];
$response = $this->getSchemaResponse($schemaId, $form, $errors, $extra);
$response->addHeader('X-Status', rawurlencode($message));
$response->addHeader('X-Status', rawurlencode($message ?? ''));
return $response;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/behat/src/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function assertMessageBoxContainsText($text)
$mainContext = $this->getMainContext();
$mainContext
->assertSession()
->elementTextContains('css', '.message-box', str_replace('\\"', '"', $text));
->elementTextContains('css', '.message-box', str_replace('\\"', '"', $text ?? ''));
}

/**
Expand Down Expand Up @@ -180,7 +180,7 @@ public function iClickTheGalleryItem($name)
public function iSeeTheCampaignItem($negate, $name)
{
$item = $this->getCampaignItem($name);
$shouldSee = !trim($negate);
$shouldSee = !trim($negate ?? '');

if ($shouldSee) {
Assert::assertNotNull($item, sprintf('Item "%s" could not be found', $name));
Expand Down Expand Up @@ -219,10 +219,10 @@ public function stepCreateCampaignWithItems($id, $data)

preg_match_all(
'/"(?<content_class>[^"]+)"\s*=\s*"(?<identifier>[^"]+)"/',
$data,
$data ?? '',
$matches
);
$itemMap = array_combine($matches['content_class'], $matches['identifier']);
$itemMap = array_combine($matches['content_class'] ?? [], $matches['identifier'] ?? []);
foreach ($itemMap as $contentClass => $identifier) {
$class = $this->convertTypeToClass($contentClass);
$record = $this->getFixtureFactory()->get($class, $identifier);
Expand Down

0 comments on commit 65da7f1

Please sign in to comment.