Uploader::setCheckMediaTypeByExt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Newbb;
4
5
/**
6
 * NewBB, XOOPS forum module
7
 *
8
 * @copyright      XOOPS Project (https://xoops.org)
9
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
10
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
11
 * @since          4.00
12
 */
13
require_once $GLOBALS['xoops']->path('class/uploader.php');
14
15
/**
16
 * Class Uploader
17
 */
18
class Uploader extends \XoopsMediaUploader
19
{
20
    /**
21
     * No admin check for uploads
22
     * @param mixed $uploadDir
23
     * @param mixed $allowedMimeTypes
24
     * @param mixed $maxFileSize
25
     * @param mixed $maxWidth
26
     * @param mixed $maxHeight
27
     */
28
    private string $ext;
29
30
    /**
31
     * Constructor
32
     *
33
     * @param string           $uploadDir
34
     * @param array|int|string $allowedMimeTypes
35
     * @param int              $maxFileSize
36
     * @param int              $maxWidth
37
     * @param int              $maxHeight
38
     */
39
    public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0)
40
    {
41
        //        $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
42
43
        if (!\is_array($allowedMimeTypes)) {
44
            if (empty($allowedMimeTypes) || '*' === $allowedMimeTypes) {
45
                $allowedMimeTypes = [];
46
            } else {
47
                $allowedMimeTypes = \array_filter(\array_map('\trim', \explode('|', \mb_strtolower($allowedMimeTypes))));
48
            }
49
        }
50
        $_allowedMimeTypes = [];
51
        $extensionToMime   = require $GLOBALS['xoops']->path('include/mimetypes.inc.php');
52
        foreach ($allowedMimeTypes as $type) {
53
            if (isset($extensionToMime[$type])) {
54
                $_allowedMimeTypes[] = $extensionToMime[$type];
55
            } else {
56
                $_allowedMimeTypes[] = $type;
57
            }
58
        }
59
        parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
60
    }
61
62
    /**
63
     * Set the CheckMediaTypeByExt
64
     * Deprecated
65
     *
66
     * @param bool|string $value
67
     */
68
    public function setCheckMediaTypeByExt($value = true): void
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    public function setCheckMediaTypeByExt(/** @scrutinizer ignore-unused */ $value = true): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
    }
71
72
    /**
73
     * Set the imageSizeCheck
74
     * Deprecated
75
     *
76
     * @param string $value
77
     */
78
    public function setImageSizeCheck(string $value): void
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function setImageSizeCheck(/** @scrutinizer ignore-unused */ string $value): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
    }
81
82
    /**
83
     * Set the fileSizeCheck
84
     * Deprecated
85
     *
86
     * @param string $value
87
     */
88
    public function setFileSizeCheck(string $value): void
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

88
    public function setFileSizeCheck(/** @scrutinizer ignore-unused */ string $value): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    {
90
    }
91
92
    /**
93
     * Get the file extension
94
     *
95
     * @return string
96
     */
97
    public function getExt(): string
98
    {
99
        $this->ext = \mb_strtolower(\ltrim(mb_strrchr((string) $this->getMediaName(), '.'), '.'));
100
101
        return $this->ext;
102
    }
103
}
104