From 8660694ea1c7d6eea85ea3c429e0893eff6b6134 Mon Sep 17 00:00:00 2001 From: Bozhidar Hristov Date: Sun, 4 Jul 2021 10:07:31 +0300 Subject: [PATCH] fix psalm --- src/Manager.php | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/Manager.php b/src/Manager.php index 4bb868a..a19f473 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -97,12 +97,12 @@ public function __construct( $this->filesystem = $filesystem; $this->namingStrategy = $namingStrategy; $this->repository = $repository; - $this->fileMap = new FileMap(); $this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector(); $this->modelFactory = $modelFactory ?? new AbstractModelFactory($class); $this->eventDispatcher = $eventDispatcher; $this->temporaryDirectory = $temporaryDirectory ?? ini_get('upload_tmp_dir') ?: sys_get_temp_dir(); $this->hashingAlgorithm = $hashingAlgorithm; + $this->clear(); } public function upload(SplFileInfo $file): File @@ -166,24 +166,6 @@ public function upload(SplFileInfo $file): File } } - private function hashFile(SplFileInfo $file): string - { - return hash_file($this->hashingAlgorithm, $file->getPathname()); - } - - /** - * @throws InvalidArgumentException - */ - private function getMimeTypeByFile(SplFileInfo $file): string - { - $mimeType = $this->mimeTypeDetector->detectMimeTypeFromFile($file->getPathname()); - if ($mimeType === null) { - throw new InvalidArgumentException('Failed to detect mimeType for '.$file->getPathname()); - } - - return $mimeType; - } - public function moveFile(File $file): void { try { @@ -230,11 +212,6 @@ public function getPathname(File $file): string } } - private function getPathnameFromNamingStrategy(File $file): string - { - return NamingStrategyUtility::getPathnameFromStrategy($this->namingStrategy, $file); - } - public function remove(File $file): void { try { @@ -347,6 +324,31 @@ public function getClass(): string public function clear(): void { - $this->fileMap = new FileMap(); + /** @var FileMap $map */ + $map = new FileMap(); + $this->fileMap = $map; + } + + private function hashFile(SplFileInfo $file): string + { + return hash_file($this->hashingAlgorithm, $file->getPathname()); + } + + /** + * @throws InvalidArgumentException + */ + private function getMimeTypeByFile(SplFileInfo $file): string + { + $mimeType = $this->mimeTypeDetector->detectMimeTypeFromFile($file->getPathname()); + if ($mimeType === null) { + throw new InvalidArgumentException('Failed to detect mimeType for '.$file->getPathname()); + } + + return $mimeType; + } + + private function getPathnameFromNamingStrategy(File $file): string + { + return NamingStrategyUtility::getPathnameFromStrategy($this->namingStrategy, $file); } }