Browse Source

fix(IMimeTypeDetector): use correct return type

In PHP array keys that are integers are always kept as integer,
meaning the type of the key of `$a = ["1" => "one"]` will be integer not
string.
While are hacks to circumvent this (case std object with string keys to
an assoc. array) those hacks are performance wise awefull and also not
needed as in PHP you can always access that element with `$a[1]` or
`$a["1"]`.

So TL;DR;: do not lie about return types.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/51564/head
Ferdinand Thiessen 9 months ago
parent
commit
d5efd17942
No known key found for this signature in database GPG Key ID: 45FAE7268762B400
  1. 4
      lib/private/Files/Type/Detection.php
  2. 10
      lib/public/Files/IMimeTypeDetector.php

4
lib/private/Files/Type/Detection.php

@ -23,7 +23,7 @@ class Detection implements IMimeTypeDetector {
private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
/** @var array<string, list{string, string|null}> */
/** @var array<list{string, string|null}> */
protected array $mimetypes = [];
protected array $secureMimeTypes = [];
@ -140,7 +140,7 @@ class Detection implements IMimeTypeDetector {
}
/**
* @return array<string, list{string, string|null}>
* @return array<list{string, string|null}>
*/
public function getAllMappings(): array {
$this->loadMappings();

10
lib/public/Files/IMimeTypeDetector.php

@ -75,7 +75,15 @@ interface IMimeTypeDetector {
public function getAllAliases(): array;
/**
* @return array<string, list{string, string|null}>
* Get all extension to MIME type mappings.
*
* The return format is an array of the file extension, as the key,
* mapped to a list where the first entry is the MIME type
* and the second entry is the secure MIME type (or null if none).
* Due to PHP idiosyncrasies if a numeric string is set as the extension,
* then also the array key (file extension) is a number instead of a string.
*
* @return array<list{string, string|null}>
* @since 32.0.0
*/
public function getAllMappings(): array;

Loading…
Cancel
Save