Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
MimeTypeConfigurator | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMimeTypes | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace AdvancedSearch; |
4 | |
5 | use MimeAnalyzer; |
6 | |
7 | /** |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | class MimeTypeConfigurator { |
11 | |
12 | private MimeAnalyzer $mimeAnalyzer; |
13 | |
14 | public function __construct( MimeAnalyzer $mimeAnalyzer ) { |
15 | $this->mimeAnalyzer = $mimeAnalyzer; |
16 | } |
17 | |
18 | /** |
19 | * @param string[] $fileExtensions |
20 | * |
21 | * @return string[] List of file extension => MIME type. |
22 | */ |
23 | public function getMimeTypes( array $fileExtensions ): array { |
24 | $mimeTypes = []; |
25 | |
26 | foreach ( $fileExtensions as $ext ) { |
27 | $mimeType = $this->mimeAnalyzer->getMimeTypeFromExtensionOrNull( $ext ); |
28 | if ( $mimeType ) { |
29 | $mimeTypes += [ $mimeType => $ext ]; |
30 | } |
31 | } |
32 | |
33 | return array_flip( $mimeTypes ); |
34 | } |
35 | |
36 | } |