Skip to content

Commit

Permalink
Removed useless method FilesService.php::parseMimeTypeTextByExtension
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Onderka <jakub.onderka@gmail.com>
  • Loading branch information
JakubOnderka committed Aug 8, 2019
1 parent de2f070 commit 8cdf712
Showing 1 changed file with 7 additions and 37 deletions.
44 changes: 7 additions & 37 deletions lib/Service/FilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,11 @@ private function updateShareNames(FilesDocument $document, Node $file): array {
*
* @return string
*/
private function parseMimeType(string $mimeType, string $extension): string {
private function parseMimeType(string $mimeType): string {

$parsed = '';
try {
$this->parseMimeTypeText($mimeType, $extension, $parsed);
$this->parseMimeTypeText($mimeType, $parsed);
$this->parseMimeTypePDF($mimeType, $parsed);
$this->parseMimeTypeOffice($mimeType, $parsed);
$this->parseMimeTypeZip($mimeType, $parsed);
Expand All @@ -802,7 +802,7 @@ private function parseMimeType(string $mimeType, string $extension): string {
*
* @throws KnownFileMimeTypeException
*/
private function parseMimeTypeText(string $mimeType, string $extension, string &$parsed) {
private function parseMimeTypeText(string $mimeType, string &$parsed) {

if (substr($mimeType, 0, 5) === 'text/') {
$parsed = self::MIMETYPE_TEXT;
Expand All @@ -819,36 +819,6 @@ private function parseMimeTypeText(string $mimeType, string $extension, string &
throw new KnownFileMimeTypeException();
}
}

$this->parseMimeTypeTextByExtension($mimeType, $extension, $parsed);
}


/**
* @param string $mimeType
* @param string $extension
* @param string $parsed
*
* @throws KnownFileMimeTypeException
*/
private function parseMimeTypeTextByExtension(
string $mimeType, string $extension, string &$parsed
) {
$textMimes = [
'application/octet-stream'
];
$textExtension = [
];

foreach ($textMimes as $mime) {
if (strpos($mimeType, $mime) === 0
&& in_array(
strtolower($extension), $textExtension
)) {
$parsed = self::MIMETYPE_TEXT;
throw new KnownFileMimeTypeException();
}
}
}


Expand Down Expand Up @@ -915,7 +885,7 @@ private function parseMimeTypeOffice(string $mimeType, string &$parsed) {
* @throws NotPermittedException
*/
private function extractContentFromFileText(FilesDocument $document, File $file) {
if ($this->parseMimeType($document->getMimeType(), $file->getExtension())
if ($this->parseMimeType($document->getMimeType())
!== self::MIMETYPE_TEXT) {
return;
}
Expand All @@ -937,7 +907,7 @@ private function extractContentFromFileText(FilesDocument $document, File $file)
* @throws NotPermittedException
*/
private function extractContentFromFilePDF(FilesDocument $document, File $file) {
if ($this->parseMimeType($document->getMimeType(), $file->getExtension())
if ($this->parseMimeType($document->getMimeType())
!== self::MIMETYPE_PDF) {
return;
}
Expand Down Expand Up @@ -966,7 +936,7 @@ private function extractContentFromFilePDF(FilesDocument $document, File $file)
* @throws NotPermittedException
*/
private function extractContentFromFileZip(FilesDocument $document, File $file) {
if ($this->parseMimeType($document->getMimeType(), $file->getExtension())
if ($this->parseMimeType($document->getMimeType())
!== self::MIMETYPE_ZIP) {
return;
}
Expand Down Expand Up @@ -995,7 +965,7 @@ private function extractContentFromFileZip(FilesDocument $document, File $file)
* @throws NotPermittedException
*/
private function extractContentFromFileOffice(FilesDocument $document, File $file) {
if ($this->parseMimeType($document->getMimeType(), $file->getExtension())
if ($this->parseMimeType($document->getMimeType())
!== self::MIMETYPE_OFFICE) {
return;
}
Expand Down

0 comments on commit 8cdf712

Please sign in to comment.