Uploader   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setCheckMediaTypeByExt() 0 2 1
A __construct() 0 21 6
A setImageSizeCheck() 0 2 1
A getExt() 0 5 1
A setFileSizeCheck() 0 2 1
1
<?php
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 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
 * @package        module::newbb
13
 */
14
15
16
17
require_once $GLOBALS['xoops']->path('class/uploader.php');
18
19
/**
20
 * Class Uploader
21
 */
22
class Uploader extends \XoopsMediaUploader
23
{
24
    /**
25
     * No admin check for uploads
26
     * @param mixed $uploadDir
27
     * @param mixed $allowedMimeTypes
28
     * @param mixed $maxFileSize
29
     * @param mixed $maxWidth
30
     * @param mixed $maxHeight
31
     */
32
33
    /**
34
     * Constructor
35
     *
36
     * @param string           $uploadDir
37
     * @param array|int|string $allowedMimeTypes
38
     * @param int              $maxFileSize
39
     * @param int              $maxWidth
40
     * @param int              $maxHeight
41
     */
42
    public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0)
43
    {
44
        //        $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
45
46
        if (!\is_array($allowedMimeTypes)) {
47
            if (empty($allowedMimeTypes) || '*' === $allowedMimeTypes) {
48
                $allowedMimeTypes = [];
49
            } else {
50
                $allowedMimeTypes = \array_filter(\array_map('\trim', \explode('|', mb_strtolower($allowedMimeTypes))));
51
            }
52
        }
53
        $_allowedMimeTypes = [];
54
        $extensionToMime   = require $GLOBALS['xoops']->path('include/mimetypes.inc.php');
55
        foreach ($allowedMimeTypes as $type) {
56
            if (isset($extensionToMime[$type])) {
57
                $_allowedMimeTypes[] = $extensionToMime[$type];
58
            } else {
59
                $_allowedMimeTypes[] = $type;
60
            }
61
        }
62
        parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
63
    }
64
65
    /**
66
     * Set the CheckMediaTypeByExt
67
     * Deprecated
68
     *
69
     * @param bool|string $value
70
     */
71
    public function setCheckMediaTypeByExt($value = true)
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

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

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...
72
    {
73
    }
74
75
    /**
76
     * Set the imageSizeCheck
77
     * Deprecated
78
     *
79
     * @param string $value
80
     */
81
    public function setImageSizeCheck($value)
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

81
    public function setImageSizeCheck(/** @scrutinizer ignore-unused */ $value)

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...
82
    {
83
    }
84
85
    /**
86
     * Set the fileSizeCheck
87
     * Deprecated
88
     *
89
     * @param string $value
90
     */
91
    public function setFileSizeCheck($value)
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

91
    public function setFileSizeCheck(/** @scrutinizer ignore-unused */ $value)

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...
92
    {
93
    }
94
95
    /**
96
     * Get the file extension
97
     *
98
     * @return string
99
     */
100
    public function getExt()
101
    {
102
        $this->ext = mb_strtolower(\ltrim(mb_strrchr($this->getMediaName(), '.'), '.'));
0 ignored issues
show
Bug Best Practice introduced by
The property ext does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
103
104
        return $this->ext;
105
    }
106
}
107