Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
File
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 generateExtension
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Utils\RnG
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Utils\RnG;
16
17/**
18 * File generator.
19 *
20 * @package phpOMS\Utils\RnG
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25class File
26{
27    /**
28     * Extensions.
29     *
30     * @var array<string[]>
31     * @since 1.0.0
32     */
33    private static $extensions = [
34        ['exe'], ['dat'], ['txt'], ['csv', 'txt'], ['doc'], ['docx', 'doc'],
35        ['mp3'], ['mp4'], ['avi'], ['mpeg'], ['wmv'], ['ppt'],
36        ['xls'], ['xlsx', 'xls'], ['xlsxm', 'xls'], ['php'], ['html'], ['tex'],
37        ['js'], ['c'], ['cpp'], ['h'], ['res'], ['ico'],
38        ['jpg'], ['png'], ['gif'], ['bmp'], ['ttf'], ['zip'],
39        ['rar'], ['7z'], ['tar', 'gz'], ['gz'], ['gz'], ['sh'],
40        ['bat'], ['iso'], ['css'], ['json'], ['ini'], ['psd'],
41        ['pptx', 'ppt'], ['xml'], ['dll'], ['wav'], ['wma'], ['vb'],
42        ['tmp'], ['tif'], ['sql'], ['swf'], ['svg'], ['rpm'],
43        ['rss'], ['pkg'], ['pdf'], ['mpg'], ['mov'], ['jar'],
44        ['flv'], ['fla'], ['deb'], ['py'], ['pl'],
45    ];
46
47    /**
48     * Get a random file extension.
49     *
50     * @param array<string[]> $source Source array for possible extensions
51     *
52     * @return string
53     *
54     * @since 1.0.0
55     */
56    public static function generateExtension(array $source = null) : string
57    {
58        if ($source === null) {
59            $source = self::$extensions;
60        }
61
62        $key = \mt_rand(0, \count($source) - 1);
63
64        return $source[$key][\mt_rand(0, \count($source[$key]) - 1)];
65    }
66}