diff --git a/src/Caching/ProxyCacheAdapter.php b/src/Caching/ProxyCacheAdapter.php index 8a3cf902..daf05aa9 100644 --- a/src/Caching/ProxyCacheAdapter.php +++ b/src/Caching/ProxyCacheAdapter.php @@ -114,10 +114,10 @@ public function getMultiple($keys, $default = null) // Enforce $poolResult is same length / order as $keyIDs prior to combining back $items = array_map(function ($keyID) use ($default, $itemsByID) { return isset($itemsByID[$keyID]) ? $itemsByID[$keyID] : $default; - }, $keyIDs); + }, $keyIDs ?? []); // Combine back with original keys - return array_combine($keys, $items); + return array_combine($keys ?? [], $items ?? []); } /** diff --git a/src/Caching/VersionedCacheAdapter.php b/src/Caching/VersionedCacheAdapter.php index b130b277..0464b0c0 100644 --- a/src/Caching/VersionedCacheAdapter.php +++ b/src/Caching/VersionedCacheAdapter.php @@ -17,7 +17,7 @@ protected function getKeyID($key) { $state = Versioned::get_reading_mode(); if ($state) { - return $key . '_' . md5($state); + return $key . '_' . md5($state ?? ''); } return $key; } diff --git a/src/ChangeSet.php b/src/ChangeSet.php index b4067fde..feeaef67 100644 --- a/src/ChangeSet.php +++ b/src/ChangeSet.php @@ -278,7 +278,7 @@ protected function calculateImplicit() $all = array_merge($referenced, $explicit); /** @var string[][] $implicit Anything that is in $all, but not in $explicit, is an implicit inclusion */ - $implicit = array_diff_key($all, $explicit); + $implicit = array_diff_key($all ?? [], $explicit); foreach ($implicit as $key => $object) { $implicit[$key]['ReferencedBy'] = $references[$key]; @@ -315,7 +315,7 @@ public function sync() $objectKey = $this->implicitKey($item); // If a ChangeSetItem exists, but isn't in $implicit, it's no longer required, so delete it - if (!array_key_exists($objectKey, $implicit)) { + if (!array_key_exists($objectKey, $implicit ?? [])) { $item->delete(); } else { // Otherwise it is required, so update ReferencedBy and remove from $implicit @@ -352,7 +352,7 @@ public function isSynced() $objectKey = $this->implicitKey($item); // If a ChangeSetItem exists, but isn't in $implicit -> validation failure - if (!array_key_exists($objectKey, $implicit)) { + if (!array_key_exists($objectKey, $implicit ?? [])) { return false; } // Exists, remove from $implicit diff --git a/src/ChangeSetItem.php b/src/ChangeSetItem.php index 260cf4b9..edbf1ca9 100644 --- a/src/ChangeSetItem.php +++ b/src/ChangeSetItem.php @@ -123,7 +123,7 @@ public function ThumbnailURL($width, $height) */ public function getChangeType() { - if (!class_exists($this->ObjectClass)) { + if (!class_exists($this->ObjectClass ?? '')) { throw new UnexpectedDataException("Invalid Class '{$this->ObjectClass}' in ChangeSetItem #{$this->ID}"); } @@ -175,7 +175,7 @@ public function getChangeType() */ protected function getObjectInStage($stage) { - if (!class_exists($this->ObjectClass)) { + if (!class_exists($this->ObjectClass ?? '')) { throw new UnexpectedDataException("Invalid Class '{$this->ObjectClass}' in ChangeSetItem #{$this->ID}"); } @@ -195,7 +195,7 @@ protected function getObjectInStage($stage) */ protected function getObjectLatestVersion() { - if (!class_exists($this->ObjectClass)) { + if (!class_exists($this->ObjectClass ?? '')) { throw new UnexpectedDataException("Invalid Class '{$this->ObjectClass}' in ChangeSetItem #{$this->ID}"); } @@ -257,7 +257,7 @@ public function findReferenced() */ public function publish() { - if (!class_exists($this->ObjectClass)) { + if (!class_exists($this->ObjectClass ?? '')) { throw new UnexpectedDataException("Invalid Class '{$this->ObjectClass}' in ChangeSetItem #{$this->ID}"); } @@ -554,7 +554,7 @@ public function CMSEditLink() */ public function isVersioned() { - if (!$this->ObjectClass || !class_exists($this->ObjectClass)) { + if (!$this->ObjectClass || !class_exists($this->ObjectClass ?? '')) { return false; } /** @var Versioned|DataObject $singleton */ diff --git a/src/DataDifferencer.php b/src/DataDifferencer.php index 07491e95..8a522d92 100644 --- a/src/DataDifferencer.php +++ b/src/DataDifferencer.php @@ -92,17 +92,17 @@ public function diffedData() $fields = array_keys($diffed->toMap() + $this->toRecord->toMap()); } else { $diffed = clone $this->toRecord; - $fields = array_keys($this->toRecord->toMap()); + $fields = array_keys($this->toRecord->toMap() ?? []); } $hasOnes = array_merge($this->fromRecord->hasOne(), $this->toRecord->hasOne()); // Loop through properties foreach ($fields as $field) { - if (in_array($field, $this->ignoredFields)) { + if (in_array($field, $this->ignoredFields ?? [])) { continue; } - if (in_array($field, array_keys($hasOnes))) { + if (in_array($field, array_keys($hasOnes ?? []))) { continue; } @@ -134,7 +134,7 @@ public function diffedData() // Loop through has_one foreach ($hasOnes as $relName => $relSpec) { - if (in_array($relName, $this->ignoredFields)) { + if (in_array($relName, $this->ignoredFields ?? [])) { continue; } @@ -246,11 +246,11 @@ public function ChangedFields() public function changedFieldNames() { $base = $this->fromRecord ?: $this->toRecord; - $fields = array_keys($base->toMap()); + $fields = array_keys($base->toMap() ?? []); $changedFields = []; foreach ($fields as $field) { - if (in_array($field, $this->ignoredFields)) { + if (in_array($field, $this->ignoredFields ?? [])) { continue; } if (!$this->fromRecord || $this->fromRecord->$field != $this->toRecord->$field) { diff --git a/src/GraphQL/Operations/CopyToStageCreator.php b/src/GraphQL/Operations/CopyToStageCreator.php index e6a1a7a8..46ca27d6 100644 --- a/src/GraphQL/Operations/CopyToStageCreator.php +++ b/src/GraphQL/Operations/CopyToStageCreator.php @@ -56,7 +56,7 @@ public function createOperation( $plugins = $config['plugins'] ?? []; $mutationName = $config['name'] ?? null; if (!$mutationName) { - $mutationName = 'copy' . ucfirst($typeName) . 'ToStage'; + $mutationName = 'copy' . ucfirst($typeName ?? '') . 'ToStage'; } return ModelMutation::create($model, $mutationName) diff --git a/src/GraphQL/Operations/PublishCreator.php b/src/GraphQL/Operations/PublishCreator.php index b1b8b1ac..70f8ea18 100644 --- a/src/GraphQL/Operations/PublishCreator.php +++ b/src/GraphQL/Operations/PublishCreator.php @@ -22,7 +22,7 @@ class PublishCreator extends AbstractPublishOperationCreator */ protected function createOperationName(string $typeName): string { - return 'publish' . ucfirst($typeName); + return 'publish' . ucfirst($typeName ?? ''); } /** diff --git a/src/GraphQL/Operations/RollbackCreator.php b/src/GraphQL/Operations/RollbackCreator.php index e63f12a9..86bf9a70 100644 --- a/src/GraphQL/Operations/RollbackCreator.php +++ b/src/GraphQL/Operations/RollbackCreator.php @@ -54,7 +54,7 @@ public function createOperation( $defaultPlugins = $this->config()->get('default_plugins'); $configPlugins = $config['plugins'] ?? []; $plugins = array_merge($defaultPlugins, $configPlugins); - $mutationName = 'rollback' . ucfirst($typeName); + $mutationName = 'rollback' . ucfirst($typeName ?? ''); return ModelMutation::create($model, $mutationName) ->setPlugins($plugins) ->setType($typeName) diff --git a/src/GraphQL/Operations/UnpublishCreator.php b/src/GraphQL/Operations/UnpublishCreator.php index ec9c3a8e..fb279d0a 100644 --- a/src/GraphQL/Operations/UnpublishCreator.php +++ b/src/GraphQL/Operations/UnpublishCreator.php @@ -21,7 +21,7 @@ class UnpublishCreator extends AbstractPublishOperationCreator */ protected function createOperationName(string $typeName): string { - return 'unpublish' . ucfirst($typeName); + return 'unpublish' . ucfirst($typeName ?? ''); } /** diff --git a/src/GraphQL/Resolvers/VersionFilters.php b/src/GraphQL/Resolvers/VersionFilters.php index 4975474c..1faae0ed 100644 --- a/src/GraphQL/Resolvers/VersionFilters.php +++ b/src/GraphQL/Resolvers/VersionFilters.php @@ -91,7 +91,7 @@ public function applyToList(DataList $list, array $versioningArgs): DataList $statuses = $versioningArgs['status']; // If we need to search archived records, we need to manually join draft table - if (in_array('archived', $statuses)) { + if (in_array('archived', $statuses ?? [])) { $list = $list ->setDataQueryParam('Versioned.mode', 'latest_versions'); // Join a temporary alias BaseTable_Draft, renaming this on execution to BaseTable @@ -120,32 +120,32 @@ public function applyToList(DataList $list, array $versioningArgs): DataList $conditions = []; // Modified exist on both stages, but differ - if (in_array('modified', $statuses)) { + if (in_array('modified', $statuses ?? [])) { $conditions[] = "\"{$liveTable}\".\"ID\" IS NOT NULL AND \"{$draftTable}\".\"ID\" IS NOT NULL" . " AND \"{$draftTable}\".\"Version\" <> \"{$liveTable}\".\"Version\""; } // Is deleted and sent to archive - if (in_array('archived', $statuses)) { + if (in_array('archived', $statuses ?? [])) { // Note: Include items staged for deletion for the time being, as these are effectively archived // we could split this out into "staged for deletion" in the future $conditions[] = "\"{$draftTable}\".\"ID\" IS NULL"; } // Is on draft only - if (in_array('draft', $statuses)) { + if (in_array('draft', $statuses ?? [])) { $conditions[] = "\"{$liveTable}\".\"ID\" IS NULL AND \"{$draftTable}\".\"ID\" IS NOT NULL"; } - if (in_array('published', $statuses)) { + if (in_array('published', $statuses ?? [])) { $conditions[] = "\"{$liveTable}\".\"ID\" IS NOT NULL"; } // Validate that all statuses have been handled - if (empty($conditions) || count($statuses) !== count($conditions)) { + if (empty($conditions) || count($statuses ?? []) !== count($conditions ?? [])) { throw new InvalidArgumentException("Invalid statuses provided"); } - $list = $list->whereAny(array_filter($conditions)); + $list = $list->whereAny(array_filter($conditions ?? [])); break; case 'version': // Note: Only valid for ReadOne @@ -222,6 +222,6 @@ protected function isValidDate($date) { $dt = DateTime::createFromFormat('Y-m-d', $date); - return ($dt !== false && !array_sum($dt->getLastErrors())); + return ($dt !== false && !array_sum($dt->getLastErrors() ?? [])); } } diff --git a/src/GraphQL/Resolvers/VersionedResolver.php b/src/GraphQL/Resolvers/VersionedResolver.php index 940386a4..97eba240 100644 --- a/src/GraphQL/Resolvers/VersionedResolver.php +++ b/src/GraphQL/Resolvers/VersionedResolver.php @@ -175,7 +175,7 @@ public static function resolvePublishOperation(array $context) AbstractPublishOperationCreator::ACTION_PUBLISH, AbstractPublishOperationCreator::ACTION_UNPUBLISH, ]; - if (!in_array($action, $allowedActions)) { + if (!in_array($action, $allowedActions ?? [])) { throw new InvalidArgumentException(sprintf( 'Invalid publish action: %s', $action diff --git a/src/GridFieldArchiveAction.php b/src/GridFieldArchiveAction.php index 00c5b592..7ac62cb4 100644 --- a/src/GridFieldArchiveAction.php +++ b/src/GridFieldArchiveAction.php @@ -84,7 +84,7 @@ public function augmentColumns($gridField, &$columns) $config->removeComponent($deleteComponent); } } - if (!in_array('Actions', $columns)) { + if (!in_array('Actions', $columns ?? [])) { $columns[] = 'Actions'; } } diff --git a/src/GridFieldRestoreAction.php b/src/GridFieldRestoreAction.php index 5eca867a..2acffd38 100644 --- a/src/GridFieldRestoreAction.php +++ b/src/GridFieldRestoreAction.php @@ -55,7 +55,7 @@ public function getExtraData($gridField, $record, $columnName) */ public function augmentColumns($gridField, &$columns) { - if (!in_array('Actions', $columns)) { + if (!in_array('Actions', $columns ?? [])) { $columns[] = 'Actions'; } } diff --git a/src/ReadingMode.php b/src/ReadingMode.php index 0e9b4587..5a0f5c5b 100644 --- a/src/ReadingMode.php +++ b/src/ReadingMode.php @@ -24,7 +24,7 @@ public static function toDataQueryParams($mode) if (!is_string($mode)) { throw new InvalidArgumentException("mode must be a string"); } - $parts = explode('.', $mode); + $parts = explode('.', $mode ?? ''); switch ($parts[0]) { case 'Archive': $archiveStage = isset($parts[2]) ? $parts[2] : Versioned::DRAFT; @@ -80,21 +80,21 @@ public static function fromDataQueryParams($params) public static function fromQueryString($query) { if (is_string($query)) { - parse_str($query, $query); + parse_str($query ?? '', $query); } if (empty($query)) { return null; } // Check date - $archiveDate = isset($query['archiveDate']) && strtotime($query['archiveDate']) + $archiveDate = isset($query['archiveDate']) && strtotime($query['archiveDate'] ?? '') ? $query['archiveDate'] : null; // Check stage (ignore invalid stages) $stage = null; - if (isset($query['stage']) && strcasecmp($query['stage'], Versioned::DRAFT) === 0) { + if (isset($query['stage']) && strcasecmp($query['stage'] ?? '', Versioned::DRAFT ?? '') === 0) { $stage = Versioned::DRAFT; - } elseif (isset($query['stage']) && strcasecmp($query['stage'], Versioned::LIVE) === 0) { + } elseif (isset($query['stage']) && strcasecmp($query['stage'] ?? '', Versioned::LIVE ?? '') === 0) { $stage = Versioned::LIVE; } @@ -129,7 +129,7 @@ public static function toQueryString($mode) if (!is_string($mode)) { throw new InvalidArgumentException("mode must be a string"); } - $parts = explode('.', $mode); + $parts = explode('.', $mode ?? ''); switch ($parts[0]) { case 'Archive': $archiveStage = isset($parts[2]) ? $parts[2] : Versioned::DRAFT; diff --git a/src/RecursivePublishable.php b/src/RecursivePublishable.php index 96874f4d..e02a19d0 100644 --- a/src/RecursivePublishable.php +++ b/src/RecursivePublishable.php @@ -228,7 +228,7 @@ public function findOwnersRecursive($recursive, $list, $lookup) if ($owner->isInDB()) { foreach ($lookup as $ownedClass => $classLookups) { // Skip owners of other objects - if (!is_a($owner, $ownedClass)) { + if (!is_a($owner, $ownedClass ?? '')) { continue; } foreach ($classLookups as $classLookup) { @@ -323,7 +323,7 @@ public function unlinkDisownedObjects($source, $targetStage) // dis-connected from this object (set ForeignKeyID = 0) $owns = $owner->config()->get('owns'); $hasMany = $owner->config()->get('has_many'); - $ownedHasMany = array_intersect($owns, array_keys($hasMany)); + $ownedHasMany = array_intersect($owns ?? [], array_keys($hasMany ?? [])); if (empty($ownedHasMany)) { return; } @@ -438,14 +438,14 @@ public function onBeforeDuplicate($original, &$doWrite, &$relations) // Only duplicate owned relationships that are either exclusively owned, // or require additional writes. Also exclude any custom non-relation ownerships. $allowed = array_merge( - array_keys($this->owner->manyMany()), // Require mapping table duplications - array_keys($this->owner->belongsTo()), // Exclusive record must be duplicated - array_keys($this->owner->hasMany()) // Exclusive records should be duplicated + array_keys($this->owner->manyMany() ?? []), // Require mapping table duplications + array_keys($this->owner->belongsTo() ?? []), // Exclusive record must be duplicated + array_keys($this->owner->hasMany() ?? []) // Exclusive records should be duplicated ); // Note: don't assume that owned has_one needs duplication, as these can be // shared non-exclusively by both clone and original. // Get candidates from ownership and intersect $owns = $this->owner->config()->get('owns'); - $relations = array_intersect($allowed, $owns); + $relations = array_intersect($allowed ?? [], $owns); } } diff --git a/src/RestoreAction.php b/src/RestoreAction.php index 703d8fc1..86fe3fcd 100644 --- a/src/RestoreAction.php +++ b/src/RestoreAction.php @@ -86,7 +86,7 @@ public static function restore($item) public static function getRestoreMessage($originalItem, $restoredItem, $changedLocation = false) { $restoredID = $restoredItem->Title ?: $restoredItem->ID; - $restoredType = strtolower($restoredItem->i18n_singular_name()); + $restoredType = strtolower($restoredItem->i18n_singular_name() ?? ''); if (method_exists($restoredItem, 'CMSEditLink') && $restoredItem->CMSEditLink()) { diff --git a/src/Versioned.php b/src/Versioned.php index 9c3fbe49..0c8bc795 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -335,7 +335,7 @@ public function __construct($mode = self::STAGEDVERSIONED) $mode = static::VERSIONED; } elseif (is_array($mode) || func_num_args() > 1) { Deprecation::notice("5.0", "Versioned now takes a mode as a single parameter"); - $mode = func_num_args() > 1 || count($mode) > 1 + $mode = func_num_args() > 1 || count($mode ?? []) > 1 ? static::STAGEDVERSIONED : static::VERSIONED; } @@ -645,11 +645,11 @@ protected function prepareMaxVersionSubSelect(SQLSelect $baseQuery, DataQuery $d // Determine the base table of the existing query $baseFrom = $baseQuery->getFrom(); - $baseTable = trim(reset($baseFrom), '"'); + $baseTable = trim(reset($baseFrom) ?? '', '"'); // And then the name of the base table in the new query $newFrom = $subSelect->getFrom(); - $newTable = trim(key($newFrom), '"'); + $newTable = trim(key($newFrom ?? []) ?? '', '"'); // Parse "where" conditions to find those appropriate to be "promoted" into an inner join // We can ONLY promote a filter on the primary key of the base table. Any other conditions will make the @@ -658,9 +658,9 @@ protected function prepareMaxVersionSubSelect(SQLSelect $baseQuery, DataQuery $d if (is_object($condition)) { continue; } - $conditionClause = key($condition); + $conditionClause = key($condition ?? []); // Pull out the table and field for this condition. We'll skip anything we can't parse - if (preg_match('/^"([^"]+)"\."([^"]+)"/', $conditionClause, $matches) !== 1) { + if (preg_match('/^"([^"]+)"\."([^"]+)"/', $conditionClause ?? '', $matches) !== 1) { continue; } @@ -675,7 +675,7 @@ protected function prepareMaxVersionSubSelect(SQLSelect $baseQuery, DataQuery $d $conditionClause = preg_replace( '/^"([^"]+)"\./', "\"{$newTable}\".", - $conditionClause + $conditionClause ?? '' ); $subSelect->addWhere([$conditionClause => reset($condition)]); @@ -901,7 +901,7 @@ protected function isTableVersioned($table) // Check that this class belongs to the same tree $baseClass = $schema->baseDataClass($this->owner); - if (!is_a($tableClass, $baseClass, true)) { + if (!is_a($tableClass, $baseClass ?? '', true)) { return false; } @@ -931,7 +931,7 @@ public function augmentLoadLazyFields(SQLSelect &$query, DataQuery &$dataQuery = $versionedMode = $dataObject->getSourceQueryParam('Versioned.mode'); $modesToAllowVersioning = ['all_versions', 'latest_versions', 'archive', 'version']; if (!empty($dataObject->Version) && - (!empty($versionedMode) && in_array($versionedMode, $modesToAllowVersioning)) + (!empty($versionedMode) && in_array($versionedMode, $modesToAllowVersioning ?? [])) ) { // This will ensure that augmentSQL will select only the same version as the owner, // regardless of how this object was initially selected @@ -956,7 +956,7 @@ public function augmentDatabase() // Build a list of suffixes whose tables need versioning $allSuffixes = []; $versionableExtensions = (array)$owner->config()->get('versionableExtensions'); - if (count($versionableExtensions)) { + if (count($versionableExtensions ?? [])) { foreach ($versionableExtensions as $versionableExtension => $suffixes) { if ($owner->hasExtension($versionableExtension)) { foreach ((array)$suffixes as $suffix) { @@ -1078,14 +1078,14 @@ protected function cleanupVersionedOrphans($baseTable, $childTable) } // Skip if tables are the same (ignore case) - if (strcasecmp($childTable, $baseTable) === 0) { + if (strcasecmp($childTable ?? '', $baseTable ?? '') === 0) { return; } // Skip if child table doesn't exist // If it does, ensure query case matches found case $tables = DB::get_schema()->tableList(); - if (!array_key_exists(strtolower($childTable), $tables)) { + if (!array_key_exists(strtolower($childTable ?? ''), $tables ?? [])) { return; } $childTable = $tables[strtolower($childTable)]; @@ -1097,7 +1097,7 @@ protected function cleanupVersionedOrphans($baseTable, $childTable) // If we have a parent table limit orphaned records // to only those that exist in this - if (array_key_exists(strtolower($baseTable), $tables)) { + if (array_key_exists(strtolower($baseTable ?? ''), $tables ?? [])) { // Ensure we match db table case $baseTable = $tables[strtolower($baseTable)]; $orphanedQuery @@ -1163,11 +1163,11 @@ protected function augmentWriteVersioned(&$manipulation, $class, $table, $record if ($data) { $fields = $schema->databaseFields($class, false); if (is_array($fields)) { - $data = array_intersect_key($data, $fields); + $data = array_intersect_key($data ?? [], $fields); foreach ($data as $k => $v) { // If the value is not set at all in the manipulation currently, use the existing value from the database - if (!array_key_exists($k, $newManipulation['fields'])) { + if (!array_key_exists($k, $newManipulation['fields'] ?? [])) { $newManipulation['fields'][$k] = $v; } } @@ -1301,7 +1301,7 @@ public function augmentWrite(&$manipulation) // Update all tables $thisVersion = null; - $tables = array_keys($manipulation); + $tables = array_keys($manipulation ?? []); foreach ($tables as $table) { // Make sure that the augmented write is being applied to a table that can be versioned $class = isset($manipulation[$table]['class']) ? $manipulation[$table]['class'] : null; @@ -1355,7 +1355,7 @@ public function augmentWrite(&$manipulation) // Add the new version # back into the data object, for accessing // after this write if ($thisVersion !== null) { - $owner->Version = str_replace("'", "", $thisVersion); + $owner->Version = str_replace("'", "", $thisVersion ?? ''); } } @@ -1777,7 +1777,7 @@ public function extendWithSuffix($table) $owner = $this->owner; $versionableExtensions = (array)$owner->config()->get('versionableExtensions'); - if (count($versionableExtensions)) { + if (count($versionableExtensions ?? [])) { foreach ($versionableExtensions as $versionableExtension => $suffixes) { if ($owner->hasExtension($versionableExtension)) { /** @var VersionableExtension|Extension $ext */ @@ -2126,8 +2126,8 @@ public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $ $baseTable = null; foreach ($query->getFrom() as $table => $tableJoin) { if (is_string($tableJoin) && $tableJoin[0] == '"') { - $baseTable = str_replace('"', '', $tableJoin); - } elseif (is_string($tableJoin) && substr($tableJoin, 0, 5) != 'INNER') { + $baseTable = str_replace('"', '', $tableJoin ?? ''); + } elseif (is_string($tableJoin) && substr($tableJoin ?? '', 0, 5) != 'INNER') { $query->setFrom([ $table => "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\"=\"{$baseTable}_Versions\".\"RecordID\"" . " AND \"$table\".\"Version\" = \"{$baseTable}_Versions\".\"Version\"" @@ -2329,7 +2329,7 @@ public static function get_reading_mode() */ public static function get_stage() { - $parts = explode('.', Versioned::get_reading_mode()); + $parts = explode('.', Versioned::get_reading_mode() ?? ''); if ($parts[0] == 'Stage') { return $parts[1]; @@ -2344,7 +2344,7 @@ public static function get_stage() */ public static function current_archived_date() { - $parts = explode('.', Versioned::get_reading_mode()); + $parts = explode('.', Versioned::get_reading_mode() ?? ''); if ($parts[0] == 'Archive') { return $parts[1]; } @@ -2358,8 +2358,8 @@ public static function current_archived_date() */ public static function current_archived_stage() { - $parts = explode('.', Versioned::get_reading_mode()); - if (sizeof($parts) === 3 && $parts[0] == 'Archive') { + $parts = explode('.', Versioned::get_reading_mode() ?? ''); + if (sizeof($parts ?? []) === 3 && $parts[0] == 'Archive') { return $parts[2]; } return static::DRAFT; diff --git a/src/VersionedGridFieldState/VersionedGridFieldState.php b/src/VersionedGridFieldState/VersionedGridFieldState.php index 664cc1b9..65b5dda6 100644 --- a/src/VersionedGridFieldState/VersionedGridFieldState.php +++ b/src/VersionedGridFieldState/VersionedGridFieldState.php @@ -89,11 +89,11 @@ public function augmentColumns($gridField, &$columns) } $matchedVersionedFields = array_intersect( - $columns, + $columns ?? [], $this->versionedLabelFields ); - if (count($matchedVersionedFields) > 0) { + if (count($matchedVersionedFields ?? []) > 0) { // Get first matched column $this->setColumn(reset($matchedVersionedFields)); } elseif ($columns) { diff --git a/src/VersionedStateExtension.php b/src/VersionedStateExtension.php index 1de660c3..9b99473a 100644 --- a/src/VersionedStateExtension.php +++ b/src/VersionedStateExtension.php @@ -57,7 +57,7 @@ public function updateLink(&$link) // Decorate $link = Controller::join_links( $link, - '?' . http_build_query($queryargs) + '?' . http_build_query($queryargs ?? []) ); } @@ -70,8 +70,8 @@ public function updateLink(&$link) protected function hasVersionedQuery($link) { // Find querystrings - $parts = explode('?', $link, 2); - if (count($parts) < 2) { + $parts = explode('?', $link ?? '', 2); + if (count($parts ?? []) < 2) { return false; } diff --git a/src/Versioned_Version.php b/src/Versioned_Version.php index e0ef94c4..5c2789d6 100644 --- a/src/Versioned_Version.php +++ b/src/Versioned_Version.php @@ -118,8 +118,8 @@ public function relField($fieldName) $component = $this; // We're dealing with relations here so we traverse the dot syntax - if (strpos($fieldName, '.') !== false) { - $relations = explode('.', $fieldName); + if (strpos($fieldName ?? '', '.') !== false) { + $relations = explode('.', $fieldName ?? ''); $fieldName = array_pop($relations); foreach ($relations as $relation) { // Inspect $component for element $relation diff --git a/tests/php/ChangeSetTest.php b/tests/php/ChangeSetTest.php index 10136727..9d85560c 100644 --- a/tests/php/ChangeSetTest.php +++ b/tests/php/ChangeSetTest.php @@ -71,7 +71,7 @@ protected function assertChangeSetLooksLike($cs, $match) $items = $cs->Changes()->toArray(); foreach ($match as $key => $mode) { - list($class, $identifier) = explode('.', $key); + list($class, $identifier) = explode('.', $key ?? ''); $objectID = $this->idFromFixture($class, $identifier); $objectClass = DataObject::getSchema()->baseDataClass($class); @@ -96,7 +96,7 @@ protected function assertChangeSetLooksLike($cs, $match) ); } - if (count($items)) { + if (count($items ?? [])) { $extra = []; foreach ($items as $item) { $extra[] = [ diff --git a/tests/php/DataDifferencerTest.php b/tests/php/DataDifferencerTest.php index abd77077..11d84d6d 100644 --- a/tests/php/DataDifferencerTest.php +++ b/tests/php/DataDifferencerTest.php @@ -55,8 +55,8 @@ protected function tearDown(): void */ public static function assertContainsIgnoreWhitespace($needle, $haystack, $message = '') { - $needle = preg_replace('#\s+#', '', $needle); - $haystack = preg_replace('#\s+#', '', $haystack); + $needle = preg_replace('#\s+#', '', $needle ?? ''); + $haystack = preg_replace('#\s+#', '', $haystack ?? ''); return parent::assertStringContainsString($needle, $haystack, $message); } diff --git a/tests/php/GraphQL/Legacy/Resolvers/ApplyVersionFiltersTest.php b/tests/php/GraphQL/Legacy/Resolvers/ApplyVersionFiltersTest.php index 34726e8f..7c879e4f 100644 --- a/tests/php/GraphQL/Legacy/Resolvers/ApplyVersionFiltersTest.php +++ b/tests/php/GraphQL/Legacy/Resolvers/ApplyVersionFiltersTest.php @@ -285,7 +285,7 @@ public function testStatusOnApplyToList() $this->assertCount(2, $list); $ids = $list->column('ID'); - $this->assertTrue(in_array($record3->ID, $ids)); - $this->assertTrue(in_array($oldID, $ids)); + $this->assertTrue(in_array($record3->ID, $ids ?? [])); + $this->assertTrue(in_array($oldID, $ids ?? [])); } } diff --git a/tests/php/GraphQL/Resolvers/VersionedFiltersTest.php b/tests/php/GraphQL/Resolvers/VersionedFiltersTest.php index 58f04641..113a7827 100644 --- a/tests/php/GraphQL/Resolvers/VersionedFiltersTest.php +++ b/tests/php/GraphQL/Resolvers/VersionedFiltersTest.php @@ -285,7 +285,7 @@ public function testStatusOnApplyToList() $this->assertCount(2, $list); $ids = $list->column('ID'); - $this->assertTrue(in_array($record3->ID, $ids)); - $this->assertTrue(in_array($oldID, $ids)); + $this->assertTrue(in_array($record3->ID, $ids ?? [])); + $this->assertTrue(in_array($oldID, $ids ?? [])); } } diff --git a/tests/php/GridFieldRestoreActionTest.php b/tests/php/GridFieldRestoreActionTest.php index 9003f15d..20a0a44c 100644 --- a/tests/php/GridFieldRestoreActionTest.php +++ b/tests/php/GridFieldRestoreActionTest.php @@ -69,11 +69,11 @@ public function testDontShowRestoreButtons() } $content = new CSSContentParser($this->gridField->FieldHolder()); // Check that there are content - $this->assertEquals(4, count($content->getBySelector('.ss-gridfield-item'))); + $this->assertEquals(4, count($content->getBySelector('.ss-gridfield-item') ?? [])); // Make sure that there are no restore buttons $this->assertEquals( 0, - count($content->getBySelector('.action-restore')), + count($content->getBySelector('.action-restore') ?? []), 'Restore buttons should not show when not logged in.' ); } @@ -83,7 +83,7 @@ public function testShowRestoreButtonsWithAdminPermission() $this->logInWithPermission('ADMIN'); $content = new CSSContentParser($this->gridField->FieldHolder()); $restoreButtons = $content->getBySelector('.action-restore'); - $this->assertEquals(3, count($restoreButtons), 'Restore buttons should show when logged in.'); + $this->assertEquals(3, count($restoreButtons ?? []), 'Restore buttons should show when logged in.'); } public function testActionsRequireCSRF() diff --git a/tests/php/VersionableExtensionsTest.php b/tests/php/VersionableExtensionsTest.php index 6b45e0c5..fec7c170 100644 --- a/tests/php/VersionableExtensionsTest.php +++ b/tests/php/VersionableExtensionsTest.php @@ -24,7 +24,7 @@ public function testTablesAreCreated() // Check that the right tables exist foreach ($check as $tableName) { - $this->assertContains($tableName, array_keys($tables), 'Contains table: '.$tableName); + $this->assertContains($tableName, array_keys($tables ?? []), 'Contains table: '.$tableName); } } } diff --git a/tests/php/VersionedOwnershipTest.php b/tests/php/VersionedOwnershipTest.php index a1b8a0d9..c8581d95 100644 --- a/tests/php/VersionedOwnershipTest.php +++ b/tests/php/VersionedOwnershipTest.php @@ -48,7 +48,7 @@ protected function setUp(): void // Automatically publish any object named *_published foreach ($this->getFixtureFactory()->getFixtures() as $class => $fixtures) { foreach ($fixtures as $name => $id) { - if (stripos($name, '_published') !== false) { + if (stripos($name ?? '', '_published') !== false) { /** @var Versioned|DataObject $object */ $object = DataObject::get($class)->byID($id); $object->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); diff --git a/tests/php/VersionedOwnershipTest/CustomRelation.php b/tests/php/VersionedOwnershipTest/CustomRelation.php index 4a6e272f..4f2bd34b 100644 --- a/tests/php/VersionedOwnershipTest/CustomRelation.php +++ b/tests/php/VersionedOwnershipTest/CustomRelation.php @@ -37,7 +37,7 @@ class CustomRelation extends DataObject implements TestOnly */ public function Pages() { - $title = str_replace('Custom', 'Page', $this->Title); + $title = str_replace('Custom', 'Page', $this->Title ?? ''); return TestPage::get()->filter('Title', $title); } } diff --git a/tests/php/VersionedOwnershipTest/TestPage.php b/tests/php/VersionedOwnershipTest/TestPage.php index 025328a8..253e5379 100644 --- a/tests/php/VersionedOwnershipTest/TestPage.php +++ b/tests/php/VersionedOwnershipTest/TestPage.php @@ -42,7 +42,7 @@ class TestPage extends DataObject implements TestOnly */ public function Custom() { - $title = str_replace('Page', 'Custom', $this->Title); + $title = str_replace('Page', 'Custom', $this->Title ?? ''); return CustomRelation::get()->filter('Title', $title); } } diff --git a/tests/php/VersionedTableTest/VersionedTableTest.php b/tests/php/VersionedTableTest/VersionedTableTest.php index d5024ddc..5d991db5 100644 --- a/tests/php/VersionedTableTest/VersionedTableTest.php +++ b/tests/php/VersionedTableTest/VersionedTableTest.php @@ -64,7 +64,7 @@ public function testApplyRelationHasOneVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(0, count($roofs)); + $this->assertEquals(0, count($roofs ?? [])); }); $roof1->publishRecursive(); @@ -79,7 +79,7 @@ public function testApplyRelationHasOneVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(1, count($roofs)); + $this->assertEquals(1, count($roofs ?? [])); }); }); } @@ -110,7 +110,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(0, count($visitors)); + $this->assertEquals(0, count($visitors ?? [])); // check many many $columnName = null; @@ -119,7 +119,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(0, count($visitors)); + $this->assertEquals(0, count($visitors ?? [])); }); $houseVisit1->publishRecursive(); @@ -134,7 +134,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(1, count($visitors)); + $this->assertEquals(1, count($visitors ?? [])); // check many many $columnName = null; @@ -143,7 +143,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(0, count($visitors)); + $this->assertEquals(0, count($visitors ?? [])); }); $visitor1->publishRecursive(); @@ -158,7 +158,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(1, count($visitors)); + $this->assertEquals(1, count($visitors ?? [])); // check many many $columnName = null; @@ -167,7 +167,7 @@ public function testApplyRelationHasManyAndManyManyVersioned() ->where(sprintf('%s IS NOT NULL', $columnName)) ->columnUnique($columnName); - $this->assertEquals(1, count($visitors)); + $this->assertEquals(1, count($visitors ?? [])); }); }); } diff --git a/tests/php/VersionedTest.php b/tests/php/VersionedTest.php index ef8d2aa4..cdcb38cd 100644 --- a/tests/php/VersionedTest.php +++ b/tests/php/VersionedTest.php @@ -69,7 +69,7 @@ public function testUniqueIndexes() // Check unique -> non-unique conversion foreach ($indexes as $indexKey => $indexSpec) { - if (array_intersect($indexSpec['columns'], $expectedColumns)) { + if (array_intersect($indexSpec['columns'] ?? [], $expectedColumns)) { $isUnique = $indexSpec['type'] === 'unique'; $this->assertEquals($isUnique, $expectation['value'], $expectation['message']); } @@ -664,7 +664,7 @@ public function testGetVersion() $this->assertEquals($archiveParms, $page2v1->getInheritableQueryParams()); $queryParms = $page2v1->Children()->getQueryParams(); foreach ($queryParms as $key => $val) { - if (!array_key_exists($key, $archiveParms)) { + if (!array_key_exists($key, $archiveParms ?? [])) { continue; } $this->assertSame($val, $queryParms[$key], "queryParms[$key] should be $val"); @@ -692,7 +692,7 @@ public function testGetVersion() $this->assertEquals($archiveParms, $page2v2->getInheritableQueryParams()); $queryParms = $page2v1->Children()->getQueryParams(); foreach ($queryParms as $key => $val) { - if (!array_key_exists($key, $archiveParms)) { + if (!array_key_exists($key, $archiveParms ?? [])) { continue; } $this->assertSame($val, $queryParms[$key], "queryParms[$key] should be $val"); @@ -940,23 +940,23 @@ public function testVersionedWithSingleStage() $tables = DB::table_list(); $this->assertContains( 'versionedtest_singlestage', - array_keys($tables), + array_keys($tables ?? []), 'Contains base table' ); $this->assertContains( 'versionedtest_singlestage_versions', - array_keys($tables), + array_keys($tables ?? []), 'Contains versions table' ); $this->assertNotContains( 'versionedtest_singlestage_live', - array_keys($tables), + array_keys($tables ?? []), 'Does not contain separate table with _Live suffix' ); $this->assertNotContains( 'versionedtest_singlestage_stage', - array_keys($tables), + array_keys($tables ?? []), 'Does not contain separate table with _Stage suffix' );