diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php
index f58431efee555d378eb6658924344471847262e8..8505f59bacc8f656d5efc6e6e629080812a585bf 100644
--- a/lib/private/Files/Type/Detection.php
+++ b/lib/private/Files/Type/Detection.php
@@ -47,8 +47,8 @@ use OCP\IURLGenerator;
  */
 class Detection implements IMimeTypeDetector {
 
-	public const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
-	public const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
+	private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
+	private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
 
 	protected $mimetypes = [];
 	protected $secureMimeTypes = [];
@@ -121,6 +121,18 @@ class Detection implements IMimeTypeDetector {
 		}
 	}
 
+	private function loadCustomDefinitions(string $fileName, array $definitions): array {
+		if (file_exists($this->customConfigDir . '/' . $fileName)) {
+			$custom = json_decode(file_get_contents($this->customConfigDir . '/' . $fileName), true);
+			if (json_last_error() === JSON_ERROR_NONE) {
+				$definitions = array_merge($definitions, $custom);
+			} else {
+				$this->logger->warning('Failed to parse ' . $fileName . ': ' . json_last_error_msg());
+			}
+		}
+		return $definitions;
+	}
+
 	/**
 	 * Add the mimetype aliases if they are not yet present
 	 */
@@ -130,15 +142,7 @@ class Detection implements IMimeTypeDetector {
 		}
 
 		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
-
-		if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES)) {
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES), true);
-			if (json_last_error() === JSON_ERROR_NONE) {
-				$this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
-			} else {
-				$this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEALIASES . ': ' . json_last_error_msg());
-			}
-		}
+		$this->mimeTypeAlias = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEALIASES, $this->mimeTypeAlias);
 	}
 
 	/**
@@ -164,16 +168,7 @@ class Detection implements IMimeTypeDetector {
 		}
 
 		$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
-
-		//Check if need to load custom mappings
-		if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING)) {
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING), true);
-			if (json_last_error() === JSON_ERROR_NONE) {
-				$mimetypeMapping = array_merge($mimetypeMapping, $custom);
-			} else {
-				$this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEMAPPING . ': ' . json_last_error_msg());
-			}
-		}
+		$mimetypeMapping = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEMAPPING, $mimetypeMapping);
 
 		$this->registerTypeArray($mimetypeMapping);
 	}
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index ea8123421132436f56d26e6438ec01ef8c19b738..ade4820057a71ff644f1b951fd7defd5f255f0f4 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -116,9 +116,8 @@ class DetectionTest extends \Test\TestCase {
 			->disableOriginalConstructor()
 			->getMock();
 
-		$logger = $this->getMockBuilder(ILogger::class)
-			->disableOriginalConstructor()
-			->getMock();
+		/** @var ILogger $logger */
+		$logger = $this->createMock(ILogger::class);
 
 		//Only call the url generator once
 		$urlGenerator->expects($this->once())