Skip to content

Commit

Permalink
fix psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Jul 4, 2021
1 parent a19829a commit 8660694
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -347,6 +324,31 @@ public function getClass(): string

public function clear(): void
{
$this->fileMap = new FileMap();
/** @var FileMap<T, \SplFileInfo> $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);
}
}

0 comments on commit 8660694

Please sign in to comment.