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 11, 2022
1 parent 6f24df9 commit 1e6272b
Show file tree
Hide file tree
Showing 32 changed files with 149 additions and 149 deletions.
2 changes: 1 addition & 1 deletion code/BatchActions/CMSBatchAction_Restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public function applicablePages($ids)

// Get pages that exist in stage and remove them from the restore-able set
$stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID');
return array_values(array_diff($ids, $stageIDs));
return array_values(array_diff($ids ?: [], $stageIDs));
}
}
34 changes: 17 additions & 17 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function LinkPageAdd($extra = null, $placeholders = null)
}

if ($placeholders) {
$link .= (strpos($link, '?') === false ? "?$placeholders" : "&$placeholders");
$link .= (strpos((string) $link, '?') === false ? "?$placeholders" : "&$placeholders");
}

return $link;
Expand Down Expand Up @@ -627,7 +627,7 @@ public function getTreeNodeClasses(SiteTree $node)
// Get status flag classes
$flags = $node->getStatusFlags();
if ($flags) {
$statuses = array_keys($flags);
$statuses = array_keys($flags ?: []);
foreach ($statuses as $s) {
$classes .= ' status-' . $s;
}
Expand All @@ -642,7 +642,7 @@ public function getTreeNodeClasses(SiteTree $node)
$classes .= ' ' . $filterClasses;
}

return trim($classes);
return trim((string) $classes);
}

/**
Expand All @@ -664,8 +664,8 @@ public function getsubtree($request)
);

// Trim off the outer tag
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html);
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html);
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html ?: '');
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html ?: '');

return $html;
}
Expand All @@ -682,7 +682,7 @@ public function getsubtree($request)
public function updatetreenodes($request)
{
$data = [];
$ids = explode(',', $request->getVar('ids'));
$ids = explode(',', (string) $request->getVar('ids'));
foreach ($ids as $id) {
if ($id === "") {
continue; // $id may be a blank string, which is invalid and should be skipped over
Expand Down Expand Up @@ -923,7 +923,7 @@ public function getSearchFieldSchema()

$searchParams = array_combine(array_map(function ($key) {
return 'Search__' . $key;
}, array_keys($searchParams)), $searchParams);
}, array_keys($searchParams ?: [])), $searchParams ?: []);

$schema = [
'formSchemaUrl' => $schemaUrl,
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public function SiteTreeHints()
// Check if can be created at the root
$needsPerm = $obj->config()->get('need_permission');
if (!$obj->config()->get('can_be_root')
|| (!array_key_exists($class, $canCreate) || !$canCreate[$class])
|| (!array_key_exists($class, $canCreate ?: []) || !$canCreate[$class])
|| ($needsPerm && !$this->can($needsPerm))
) {
$def['Root']['disallowedChildren'][] = $class;
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public function getRecord($id, $versionID = null)
if ($id instanceof $treeClass) {
return $id;
}
if (substr($id, 0, 3) == 'new') {
if (substr((string) $id, 0, 3) == 'new') {
return $this->getNewItem($id);
}
if (!is_numeric($id)) {
Expand Down Expand Up @@ -1459,18 +1459,18 @@ protected function getArchiveWarningMessage($record)

// Count number of affected change set
$affectedChangeSetCount = 0;
if (count($inChangeSetIDs) > 0) {
if (count($inChangeSetIDs ?: []) > 0) {
$affectedChangeSetCount = ChangeSet::get()
->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
->count();
}

$numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
$numCampaigns = mb_strtolower($numCampaigns);
$numCampaigns = mb_strtolower((string) $numCampaigns);

if (count($descendants) > 0 && $affectedChangeSetCount > 0) {
if (count($descendants ?: []) > 0 && $affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
} elseif (count($descendants) > 0) {
} elseif (count($descendants ?: []) > 0) {
$archiveWarningMsg = $defaultMessage;
} elseif ($affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
Expand Down Expand Up @@ -1752,7 +1752,7 @@ public function save($data, $form)

// Existing or new record?
$id = $data['ID'];
if (substr($id, 0, 3) != 'new') {
if (substr((string) $id, 0, 3) != 'new') {
/** @var SiteTree $record */
$record = DataObject::get_by_id($className, $id);
// Check edit permissions
Expand Down Expand Up @@ -1825,9 +1825,9 @@ public function save($data, $form)
public function getNewItem($id, $setID = true)
{
$parentClass = $this->config()->get('tree_class');
list(, $className, $parentID) = array_pad(explode('-', $id), 3, null);
list(, $className, $parentID) = array_pad(explode('-', (string) $id), 3, null);

if (!is_a($className, $parentClass, true)) {
if (!is_a($className, (string) $parentClass, true)) {
$response = Security::permissionFailure($this);
if (!$response) {
$response = $this->getResponse();
Expand Down Expand Up @@ -2370,7 +2370,7 @@ protected function generateHintsCacheKey($memberID)

$this->extend('updateHintsCacheKey', $baseKey);

return md5($baseKey);
return md5((string) $baseKey);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/CMSSiteTreeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function get_all_filters()
uasort($filterMap, function ($a, $b) {
return ($a === CMSSiteTreeFilter_Search::title())
? -1
: strcasecmp($a, $b);
: strcasecmp((string) $a, (string) $b);
});

return $filterMap;
Expand Down
10 changes: 5 additions & 5 deletions code/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected function init()
$getVars = $_GET;
unset($getVars['url']);
if ($getVars) {
$url = "?" . http_build_query($getVars);
$url = "?" . http_build_query($getVars ?: []);
} else {
$url = "";
}
Expand Down Expand Up @@ -494,7 +494,7 @@ public function successfullyinstalled()
// TODO Allow this to work when allow_url_fopen=0
if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
@file_get_contents($url);
@file_get_contents((string) $url);
}

global $project;
Expand Down Expand Up @@ -532,11 +532,11 @@ public function deleteinstallfiles()
$unsuccessful = new ArrayList();
foreach ($installfiles as $installfile) {
$installfilepath = PUBLIC_PATH . '/' . $installfile;
if (file_exists($installfilepath)) {
@unlink($installfilepath);
if (file_exists((string) $installfilepath)) {
@unlink((string) $installfilepath);
}

if (file_exists($installfilepath)) {
if (file_exists((string) $installfilepath)) {
$unsuccessful->push(new ArrayData(['File' => $installfile]));
}
}
Expand Down
6 changes: 3 additions & 3 deletions code/Controllers/ModelAsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static function controller_for(SiteTree $sitetree, $action = null)
{
$controller = $sitetree->getControllerName();

if ($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
if ($action && class_exists($controller . '_' . ucfirst((string) $action))) {
$controller = $controller . '_' . ucfirst((string) $action);
}

return Injector::inst()->create($controller, $sitetree);
Expand Down Expand Up @@ -131,7 +131,7 @@ public function getNestedController()
// url encode unless it's multibyte (already pre-encoded in the database)
$filter = URLSegmentFilter::create();
if (!$filter->getAllowMultibyte()) {
$URLSegment = rawurlencode($URLSegment);
$URLSegment = rawurlencode((string) $URLSegment);
}

// Select child page
Expand Down
10 changes: 5 additions & 5 deletions code/Controllers/OldPageRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class OldPageRedirector extends Extension
public function onBeforeHTTPError404($request)
{
// We need to get the URL ourselves because $request->allParams() only has a max of 4 params
$params = preg_split('|/+|', $request->getURL());
$cleanURL = trim(Director::makeRelative($request->getURL(false)), '/');
$params = preg_split('|/+|', (string) $request->getURL());
$cleanURL = trim((string) Director::makeRelative($request->getURL(false)), '/');

$getvars = $request->getVars();
unset($getvars['url']);
Expand All @@ -33,7 +33,7 @@ public function onBeforeHTTPError404($request)
if (!$page) {
$page = self::find_old_page($params);
}
$cleanPage = trim(Director::makeRelative($page), '/');
$cleanPage = trim((string) Director::makeRelative($page), '/');
if (!$cleanPage) {
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link());
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public static function find_old_page($params, $parent = null, $redirect = false)
{
$parent = is_numeric($parent) && $parent > 0 ? SiteTree::get()->byID($parent) : $parent;
$params = (array)$params;
$URL = rawurlencode(array_shift($params));
$URL = rawurlencode((string) array_shift($params));
if (empty($URL)) {
return false;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function find_old_page($params, $parent = null, $redirect = false)
}

if ($page && $page->canView()) {
if (count($params)) {
if (count($params ?: [])) {
// We have to go deeper!
$ret = self::find_old_page($params, $page, $redirect);
if ($ret) {
Expand Down
2 changes: 1 addition & 1 deletion code/Controllers/RootURLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function get_homepage_link()
*/
public static function should_be_on_root(SiteTree $page)
{
return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/'));
return (!self::$is_at_root && self::get_homepage_link() == trim((string) $page->RelativeLink(true), '/'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions code/Forms/SiteTreeURLSegmentField.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SiteTreeURLSegmentField extends TextField

public function Value()
{
return rawurldecode($this->value);
return rawurldecode((string) $this->value);
}

public function getAttributes()
Expand Down Expand Up @@ -82,7 +82,7 @@ public function suggest($request)
$page->URLSegment = $page->generateURLSegment($request->getVar('value'));
$count = 2;
while (!$page->validURLSegment()) {
$page->URLSegment = preg_replace('/-[0-9]+$/', null, $page->URLSegment) . '-' . $count;
$page->URLSegment = preg_replace('/-[0-9]+$/', null, $page->URLSegment ?: '') . '-' . $count;
$count++;
}

Expand Down
4 changes: 2 additions & 2 deletions code/Model/RedirectorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ protected function onBeforeWrite()
{
parent::onBeforeWrite();

if ($this->ExternalURL && substr($this->ExternalURL, 0, 2) !== '//') {
$urlParts = parse_url($this->ExternalURL);
if ($this->ExternalURL && substr((string) $this->ExternalURL, 0, 2) !== '//') {
$urlParts = parse_url((string) $this->ExternalURL);
if ($urlParts) {
if (empty($urlParts['scheme'])) {
// no scheme, assume http
Expand Down
Loading

0 comments on commit 1e6272b

Please sign in to comment.