diff --git a/system/src/Grav/Common/Assets/Pipeline.php b/system/src/Grav/Common/Assets/Pipeline.php index 948104ab9..0135e89bd 100644 --- a/system/src/Grav/Common/Assets/Pipeline.php +++ b/system/src/Grav/Common/Assets/Pipeline.php @@ -122,7 +122,7 @@ class Pipeline extends PropertyObject // Compute uid based on assets and timestamp $json_assets = json_encode($assets); - $uid = md5($json_assets . $this->css_minify . $this->css_rewrite . $group); + $uid = md5($json_assets . (int)$this->css_minify . (int)$this->css_rewrite . $group); $file = $uid . '.css'; $relative_path = "{$this->base_url}{$this->assets_url}/{$file}"; diff --git a/system/src/Grav/Common/Backup/Backups.php b/system/src/Grav/Common/Backup/Backups.php index 4680f8546..158e12e2f 100644 --- a/system/src/Grav/Common/Backup/Backups.php +++ b/system/src/Grav/Common/Backup/Backups.php @@ -145,7 +145,7 @@ class Backups { $backups = static::getAvailableBackups(); - return array_sum(array_column($backups, 'size')); + return $backups ? array_sum(array_column($backups, 'size')) : 0; } /** diff --git a/system/src/Grav/Common/Data/Blueprint.php b/system/src/Grav/Common/Data/Blueprint.php index df434267f..e4f841921 100644 --- a/system/src/Grav/Common/Data/Blueprint.php +++ b/system/src/Grav/Common/Data/Blueprint.php @@ -99,7 +99,7 @@ class Blueprint extends BlueprintForm */ public function getDefaultValue(string $name) { - $path = explode('.', $name) ?: []; + $path = explode('.', $name); $current = $this->getDefaults(); foreach ($path as $field) { diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index bfb40578d..9c23f81c2 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -816,7 +816,7 @@ class Validation { $value = static::filterArray($value, $params, $field); - return Utils::arrayUnflattenDotNotation($value); + return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null; } /** diff --git a/system/src/Grav/Common/Filesystem/Folder.php b/system/src/Grav/Common/Filesystem/Folder.php index ecbc6ceac..6edd8e2e3 100644 --- a/system/src/Grav/Common/Filesystem/Folder.php +++ b/system/src/Grav/Common/Filesystem/Folder.php @@ -513,7 +513,7 @@ abstract class Folder } $directories = glob($directory . '/*', GLOB_ONLYDIR); - return count($directories); + return $directories ? count($directories) : false; } /** @@ -530,7 +530,8 @@ abstract class Folder } // Go through all items in filesystem and recursively remove everything. - $files = array_diff(scandir($folder, SCANDIR_SORT_NONE), array('.', '..')); + $files = scandir($folder, SCANDIR_SORT_NONE); + $files = $files ? array_diff($files, ['.', '..']) : []; foreach ($files as $file) { $path = "{$folder}/{$file}"; is_dir($path) ? self::doDelete($path) : @unlink($path); diff --git a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php index 25d8672c0..4974a3acf 100644 --- a/system/src/Grav/Framework/Collection/AbstractIndexCollection.php +++ b/system/src/Grav/Framework/Collection/AbstractIndexCollection.php @@ -131,7 +131,7 @@ abstract class AbstractIndexCollection implements CollectionInterface { $key = $this->isAllowedElement($element) ? $this->getCurrentKey($element) : null; - if (!$key || !isset($this->entries[$key])) { + if (null !== $key || !isset($this->entries[$key])) { return false; } @@ -148,7 +148,7 @@ abstract class AbstractIndexCollection implements CollectionInterface #[\ReturnTypeWillChange] public function offsetExists($offset) { - return $this->containsKey($offset); + return $offset !== null ? $this->containsKey($offset) : false; } /** @@ -159,7 +159,7 @@ abstract class AbstractIndexCollection implements CollectionInterface #[\ReturnTypeWillChange] public function offsetGet($offset) { - return $this->get($offset); + return $offset !== null ? $this->get($offset) : null; } /** @@ -172,9 +172,9 @@ abstract class AbstractIndexCollection implements CollectionInterface { if (null === $offset) { $this->add($value); + } else { + $this->set($offset, $value); } - - $this->set($offset, $value); } /** @@ -185,7 +185,9 @@ abstract class AbstractIndexCollection implements CollectionInterface #[\ReturnTypeWillChange] public function offsetUnset($offset) { - $this->remove($offset); + if ($offset !== null) { + $this->remove($offset); + } } /** diff --git a/system/src/Grav/Framework/File/AbstractFile.php b/system/src/Grav/Framework/File/AbstractFile.php index 0c78dd303..af9209c68 100644 --- a/system/src/Grav/Framework/File/AbstractFile.php +++ b/system/src/Grav/Framework/File/AbstractFile.php @@ -191,8 +191,9 @@ class AbstractFile implements FileInterface $this->handle = @fopen($this->filepath, 'cb+') ?: null; if (!$this->handle) { $error = error_get_last(); + $message = $error['message'] ?? 'Unknown error'; - throw new RuntimeException("Opening file for writing failed on error {$error['message']}"); + throw new RuntimeException("Opening file for writing failed on error {$message}"); } } diff --git a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php index 32d4d296a..3909f6e85 100644 --- a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php @@ -107,7 +107,9 @@ class YamlFormatter extends AbstractFormatter $saved = @ini_get('yaml.decode_php'); @ini_set('yaml.decode_php', '0'); $decoded = @yaml_parse($data); - @ini_set('yaml.decode_php', $saved); + if ($saved !== false) { + @ini_set('yaml.decode_php', $saved); + } if ($decoded !== false) { return (array) $decoded;