Passed
Push — master ( 09f9f5...606015 )
by Michael
16s
created

TemplatesUserRss::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
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: TemplatesUserRss.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class TemplatesUserRss.
27
 */
28
class TemplatesUserRss 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...
29
{    
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
30
    /*
31
    *  @public function constructor
32
    *  @param null
33
    */
34
    /**
35
     *
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
	}
41
42
    /*
43
    *  @static function &getInstance
44
    *  @param null
45
    */
46
    /**
47
     * @return TemplatesUserRss
48
     */
49
    public static function &getInstance()
50
    {
51
        static $instance = false;
52
        if (!$instance) {
53
            $instance = new self();
54
        }
55
56
        return $instance;
57
    }
58
59
    /*
60
    *  @public function write
61
    *  @param $module
62
    *  @param $filename
63
    */
64
    /**
65
     * @param $module
66
     * @param $table
67
     */
68
    public function write($module, $filename)
69
    {
70
        $this->setModule($module);
71
		$this->setFileName($filename);
72
    }
73
74
    /*
75
    *  @private function getTemplatesUserRssXml
76
    *  @param string $moduleDirname
77
    *  @param string $table
78
    *  @param string $language
79
    */
80
    /**
81
     * @param $moduleDirname
82
     * @param $table
83
     * @param $language
84
     *
85
     * @return string
86
     */
87
    private function getTemplatesUserRssXml()
88
    {
89
        $ret = <<<EOT
90
<?xml version="1.0" encoding="UTF-8"?>
91
<rss version="2.0">
92
  <channel>
93
    <title><{\$channel_title}></title>
94
    <link><{\$channel_link}></link>
95
    <description><{\$channel_desc}></description>
96
    <lastBuildDate><{\$channel_lastbuild}></lastBuildDate>
97
    <docs>http://backend.userland.com/rss/</docs>
98
    <generator><{\$channel_generator}></generator>
99
    <category><{\$channel_category}></category>
100
    <managingEditor><{\$channel_editor}></managingEditor>
101
    <webMaster><{\$channel_webmaster}></webMaster>
102
    <language><{\$channel_language}></language>
103
    <{if \$image_url != ""}>
104
    <image>
105
      <title><{\$channel_title}></title>
106
      <url><{\$image_url}></url>
107
      <link><{\$channel_link}></link>
108
      <width><{\$image_width}></width>
109
      <height><{\$image_height}></height>
110
    </image>
111
    <{/if}>
112
    <{foreach item=item from=\$items}>
113
    <item>
114
      <title><{\$item.title}></title>
115
      <link><{\$item.link}></link>
116
      <description><{\$item.description}></description>
117
      <pubDate><{\$item.pubdate}></pubDate>
118
      <guid><{\$item.guid}></guid>
119
    </item>
120
    <{/foreach}>
121
  </channel>
122
</rss>\n
123
EOT;
124
125
        return $ret;
126
    }
127
128
    /*
129
    *  @public function renderFile
130
    *  @param null
131
    */
132
    /**
133
     * @param null
134
     *
135
     * @return bool|string
136
     */
137
    public function render()
138
    {
139
        $module = $this->getModule();
140
        $moduleDirname = $module->getVar('mod_dirname');
141
		$filename = $this->getFileName();
142
        $language = $this->getLanguage($moduleDirname, 'MA');
0 ignored issues
show
Unused Code introduced by
$language 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...
143
        $content = $this->getTemplatesUserRssXml();
144
        //
145
        $this->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
146
147
        return $this->renderFile();
148
    }
149
}
150