Completed
Push — xmfasserts ( b960a9 )
by Richard
06:03
created

XoopsFile   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 24.14 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 7
loc 29
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHandler() 7 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * XoopsFile
14
 *
15
 * File factory For XOOPS
16
 *
17
 * PHP 5.3
18
 *
19
 * @category  Xoops\Class\Cache\CacheApc
20
 * @package   CacheApc
21
 * @author    Taiwen Jiang <[email protected]>
22
 * @copyright 2013 XOOPS Project (http://xoops.org)
23
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24
 * @version   $Id$
25
 * @link      http://xoops.org
26
 * @since     2.6.0
27
 */
28
class XoopsFile
29
{
30
    /**
31
     * XoopsFile::getHandler()
32
     *
33
     * @param string $name   name of file
34
     * @param string  $path   path file is in
35
     * @param boolean  $create create file if needed
36
     * @param integer  $mode   mode on file created
37
     *
38
     * @return XoopsFileHandler|XoopsFolderHandler|bool
39
     */
40 45
    public static function getHandler($name = 'file', $path = false, $create = false, $mode = null)
41
    {
42 45
        $handler = null;
0 ignored issues
show
Unused Code introduced by
$handler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43 45
        $name = strtolower(trim($name));
44 45
        $class = 'Xoops' . ucfirst($name) . 'Handler';
45 45
        if (in_array($name, array('file', 'folder'))) {
46 45
            $handler = new $class($path, $create, $mode);
47 View Code Duplication
        } else {
48 1
            trigger_error(
49 1
                'Class ' . $class . ' not exist in File ' . __FILE__ . ' at Line ' . __LINE__,
50 1
                E_USER_WARNING
51
            );
52
            return false;
53
        }
54 45
        return $handler;
55
    }
56
}
57