Completed
Pull Request — master (#51)
by Gino
06:03
created

UserFooter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 94
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getInstance() 0 9 2
A write() 0 5 1
A getUserFooter() 0 19 1
A render() 0 12 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 29 and the first side effect is on line 24.

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
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: user_footer.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * Class UserFooter.
28
 */
29
class UserFooter extends TDMCreateFile
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...
30
{
31
    /*
32
    *  @public function constructor
33
    *  @param null
34
    */
35
    /**
36
     *
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
0 ignored issues
show
Bug introduced by
The property xoopscode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Bug introduced by
The property phpcode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
    }
44
45
    /*
46
    *  @static function &getInstance
47
    *  @param null
48
    */
49
    /**
50
     * @return UserFooter
51
     */
52
    public static function &getInstance()
53
    {
54
        static $instance = false;
55
        if (!$instance) {
56
            $instance = new self();
57
        }
58
59
        return $instance;
60
    }
61
62
    /*
63
    *  @public function write
64
    *  @param string $module
65
    *  @param string $filename
66
    */
67
    /**
68
     * @param $module
69
     * @param $filename
70
     */
71
    public function write($module, $filename)
72
    {
73
        $this->setModule($module);
74
        $this->setFileName($filename);
75
    }
76
77
    /*
78
    *  @private function getUserFooter
79
    *  @param $moduleDirname
80
    *
81
    *  @return string
82
    */
83
    private function getUserFooter($moduleDirname)
84
    {
85
        $xoBreadcrumbs = $this->xoopscode->getXoopsCodeTplAssign('xoBreadcrumbs', '$xoBreadcrumbs');
86
        $ret = $this->phpcode->getPhpCodeConditions('count($xoBreadcrumbs)', ' > ', '1', $xoBreadcrumbs);
87
        $language = $this->getLanguage($moduleDirname, 'MA');
88
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('sysPathIcon32', '$sysPathIcon32');
89
        $ret .= $this->xoopscode->getXoopsCodeTplAssign("{$moduleDirname}_url", "{$language}URL");
90
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('adv', "\${$moduleDirname}->getConfig('advertise')");
91
        $ret .= $this->getCommentLine();
92
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('bookmarks', "\${$moduleDirname}->getConfig('bookmarks')");
93
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('fbcomments', "\${$moduleDirname}->getConfig('fbcomments')");
94
        $ret .= $this->getCommentLine();
95
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('admin', "{$language}ADMIN");
96
        $ret .= $this->xoopscode->getXoopsCodeTplAssign('copyright', '$copyright');
97
        $ret .= $this->getCommentLine();
98
        $ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'footer', true);
99
100
        return $ret;
101
    }
102
103
    /*
104
    *  @public function render
105
    *  @param null
106
    */
107
    /**
108
     * @return bool|string
109
     */
110
    public function render()
111
    {
112
        $module = $this->getModule();
113
        $moduleDirname = $module->getVar('mod_dirname');
114
        $filename = $this->getFileName();
115
        $content = $this->getHeaderFilesComments($module, $filename);
116
        $content .= $this->getUserFooter($moduleDirname);
117
118
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Documentation introduced by
_AM_TDMCREATE_FILE_CREATED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
_AM_TDMCREATE_FILE_NOTCREATED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
119
120
        return $this->renderFile();
121
    }
122
}
123