From 5b84213fce5ebdc54e45b860f0f38c0d854cbab7 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 7 Dec 2021 13:08:05 +0200 Subject: [PATCH] Improved Framework File classes --- system/src/Grav/Framework/File/CsvFile.php | 9 +++++++++ system/src/Grav/Framework/File/File.php | 9 --------- .../Framework/File/Formatter/JsonFormatter.php | 16 ++++++++++------ system/src/Grav/Framework/File/IniFile.php | 9 +++++++++ system/src/Grav/Framework/File/MarkdownFile.php | 9 +++++++++ system/src/Grav/Framework/File/YamlFile.php | 9 +++++++++ .../src/Grav/Framework/Filesystem/Filesystem.php | 2 +- 7 files changed, 47 insertions(+), 16 deletions(-) diff --git a/system/src/Grav/Framework/File/CsvFile.php b/system/src/Grav/Framework/File/CsvFile.php index 999f88a52..7be6879b7 100644 --- a/system/src/Grav/Framework/File/CsvFile.php +++ b/system/src/Grav/Framework/File/CsvFile.php @@ -28,4 +28,13 @@ class CsvFile extends DataFile { parent::__construct($filepath, $formatter); } + + /** + * @return array + */ + public function load(): array + { + /** @var array */ + return parent::load(); + } } diff --git a/system/src/Grav/Framework/File/File.php b/system/src/Grav/Framework/File/File.php index 1d4055aec..a6a8f3c9c 100644 --- a/system/src/Grav/Framework/File/File.php +++ b/system/src/Grav/Framework/File/File.php @@ -20,15 +20,6 @@ use function is_string; */ class File extends AbstractFile { - /** - * {@inheritdoc} - * @see FileInterface::load() - */ - public function load() - { - return parent::load(); - } - /** * {@inheritdoc} * @see FileInterface::save() diff --git a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php index c76864533..395766718 100644 --- a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php @@ -75,9 +75,11 @@ class JsonFormatter extends AbstractFormatter if (is_string($options)) { $list = preg_split('/[\s,|]+/', $options); $options = 0; - foreach ($list as $option) { - if (isset($this->encodeOptions[$option])) { - $options += $this->encodeOptions[$option]; + if ($list) { + foreach ($list as $option) { + if (isset($this->encodeOptions[$option])) { + $options += $this->encodeOptions[$option]; + } } } } else { @@ -100,9 +102,11 @@ class JsonFormatter extends AbstractFormatter if (is_string($options)) { $list = preg_split('/[\s,|]+/', $options); $options = 0; - foreach ($list as $option) { - if (isset($this->decodeOptions[$option])) { - $options += $this->decodeOptions[$option]; + if ($list) { + foreach ($list as $option) { + if (isset($this->decodeOptions[$option])) { + $options += $this->decodeOptions[$option]; + } } } } else { diff --git a/system/src/Grav/Framework/File/IniFile.php b/system/src/Grav/Framework/File/IniFile.php index 6cda6096c..64214998d 100644 --- a/system/src/Grav/Framework/File/IniFile.php +++ b/system/src/Grav/Framework/File/IniFile.php @@ -28,4 +28,13 @@ class IniFile extends DataFile { parent::__construct($filepath, $formatter); } + + /** + * @return array + */ + public function load(): array + { + /** @var array */ + return parent::load(); + } } diff --git a/system/src/Grav/Framework/File/MarkdownFile.php b/system/src/Grav/Framework/File/MarkdownFile.php index 4ae3aa0de..881862b78 100644 --- a/system/src/Grav/Framework/File/MarkdownFile.php +++ b/system/src/Grav/Framework/File/MarkdownFile.php @@ -28,4 +28,13 @@ class MarkdownFile extends DataFile { parent::__construct($filepath, $formatter); } + + /** + * @return array + */ + public function load(): array + { + /** @var array */ + return parent::load(); + } } diff --git a/system/src/Grav/Framework/File/YamlFile.php b/system/src/Grav/Framework/File/YamlFile.php index 29224ce78..d191e3cf9 100644 --- a/system/src/Grav/Framework/File/YamlFile.php +++ b/system/src/Grav/Framework/File/YamlFile.php @@ -28,4 +28,13 @@ class YamlFile extends DataFile { parent::__construct($filepath, $formatter); } + + /** + * @return array + */ + public function load(): array + { + /** @var array */ + return parent::load(); + } } diff --git a/system/src/Grav/Framework/Filesystem/Filesystem.php b/system/src/Grav/Framework/Filesystem/Filesystem.php index d93f4c22a..d323618f7 100644 --- a/system/src/Grav/Framework/Filesystem/Filesystem.php +++ b/system/src/Grav/Framework/Filesystem/Filesystem.php @@ -239,7 +239,7 @@ class Filesystem implements FilesystemInterface if (null !== $scheme) { $info['scheme'] = $scheme; - $dirname = isset($info['dirname']) && $info['dirname'] !== '.' ? $info['dirname'] : null; + $dirname = $info['dirname'] !== '.' ? $info['dirname'] : null; if (null !== $dirname) { // In Windows dirname may be using backslashes, fix that.