Completed
Branch master (1b2f30)
by Michael
06:29 queued 03:22
created

sfUploader::setImageSizeCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * CBB, XOOPS forum module
4
 *
5
 * @copyright   The XOOPS Project http://xoops.sf.net
6
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
7
 * @author      Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since       4.00
9
 * @package     module::newbb
10
 */
11
12
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
14
include_once XOOPS_ROOT_PATH . '/class/uploader.php';
15
16
/**
17
 * Class sfUploader
18
 */
19
class sfUploader extends XoopsMediaUploader
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
    /**
22
     * No admin check for uploads
23
     */
24
    /**
25
     * Constructor
26
     *
27
     * @param string    $uploadDir
28
     * @param array|int $allowedMimeTypes
29
     * @param int       $maxFileSize
30
     * @param int       $maxWidth
31
     * @param int       $maxHeight
32
     */
33
    public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0)
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
34
    {
35
        if (!is_array($allowedMimeTypes)) {
36
            if (empty($allowedMimeTypes) || $allowedMimeTypes === '*') {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $allowedMimeTypes (integer) and '*' (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
37
                $allowedMimeTypes = array();
38
            } else {
39
                $allowedMimeTypes = array_filter(array_map('trim', explode('|', strtolower($allowedMimeTypes))));
40
            }
41
        }
42
        $_allowedMimeTypes = array();
43
        $extensionToMime   = include $GLOBALS['xoops']->path('/include/mimetypes.inc.php');
44
        foreach ($allowedMimeTypes as $type) {
45
            if (isset($extensionToMime[$type])) {
46
                $_allowedMimeTypes[] = $extensionToMime[$type];
47
            } else {
48
                $_allowedMimeTypes[] = $type;
49
            }
50
        }
51
        parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight);
52
    }
53
54
    /**
55
     * Set the CheckMediaTypeByExt
56
     * Deprecated
57
     *
58
     * @param bool|string $value
59
     */
60
    public function setCheckMediaTypeByExt($value = true)
61
    {
62
    }
63
64
    /**
65
     * Set the imageSizeCheck
66
     * Deprecated
67
     *
68
     * @param string $value
69
     */
70
    public function setImageSizeCheck($value)
71
    {
72
    }
73
74
    /**
75
     * Set the fileSizeCheck
76
     * Deprecated
77
     *
78
     * @param string $value
79
     */
80
    public function setFileSizeCheck($value)
81
    {
82
    }
83
84
    /**
85
     * Get the file extension
86
     *
87
     * @return string
88
     */
89
    public function getExt()
90
    {
91
        $this->ext = strtolower(ltrim(strrchr($this->getMediaName(), '.'), '.'));
92
93
        return $this->ext;
94
    }
95
}
96