From 2e5ec71f2969eac50dd6cb8fb5cab35059ace9a4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 15 Feb 2020 21:40:03 +0100 Subject: [PATCH] fix phpstan --- Models/Media.php | 8 +++++--- Views/MediaView.php | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Models/Media.php b/Models/Media.php index a7f498f..a00750b 100644 --- a/Models/Media.php +++ b/Models/Media.php @@ -170,11 +170,11 @@ class Media implements \JsonSerializable * @param string $password Password to encrypt the file with * @param null|string $outputPath Output path of the encryption (null = replace file) * - * @return void + * @return string * * @since 1.0.0 */ - public function encrypt(string $password, string $outputPath = null) : void + public function encrypt(string $password, string $outputPath = null) : string { /** * @todo Orange-Management/Modules#185 @@ -182,6 +182,8 @@ class Media implements \JsonSerializable * The media module should allow to define a password (not encrypted on the hard drive) * and an encryption checkbox which forces a password AND encrypts the file on the harddrive. */ + + return ''; } /** @@ -190,7 +192,7 @@ class Media implements \JsonSerializable * @param string $password Password to encrypt the file with * @param null|string $outputPath Output path of the encryption (null = replace file) * - * @return void + * @return string * * @since 1.0.0 */ diff --git a/Views/MediaView.php b/Views/MediaView.php index 89f7d67..ba683a1 100644 --- a/Views/MediaView.php +++ b/Views/MediaView.php @@ -45,10 +45,9 @@ class MediaView extends View protected function filePathFunction(Media $media, string $sub) : string { if (\is_file($media->getPath() . $sub) - && StringUtils::startsWith( - \str_replace('\\', '/', \realpath($media->getPath() . $sub)), - $media->getPath() - ) + && ($path = \realpath($media->getPath() . $sub)) !== false + && ($path = \str_replace('\\', '/', $path)) !== false + && StringUtils::startsWith($path, $media->getPath()) ) { return $media->getPath() . $sub; } @@ -69,10 +68,9 @@ class MediaView extends View protected function dirPathFunction(Media $media, string $sub) : string { if (\is_dir($media->getPath() . $sub) - && StringUtils::startsWith( - \str_replace('\\', '/', \realpath($media->getPath() . $sub)), - $media->getPath() - ) + && ($path = \realpath($media->getPath() . $sub)) !== false + && ($path = \str_replace('\\', '/', $path)) !== false + && StringUtils::startsWith($path, $media->getPath()) ) { return $media->getPath() . $sub; } @@ -111,6 +109,11 @@ class MediaView extends View protected function getFileContent(string $path) : string { $output = \file_get_contents($path); + + if ($output === false) { + return ''; + } + $output = \str_replace(["\r\n", "\r"], "\n", $output); return $output; @@ -128,6 +131,11 @@ class MediaView extends View protected function lineContentFunction(string $path) : array { $output = \file_get_contents($path); + + if ($output === false) { + return []; + } + $output = \str_replace(["\r\n", "\r"], "\n", $output); return \explode("\n", $output);