Passed
Push — master ( 0f0f99...fb91d6 )
by Michael
17s
created

TemplatesUserRss::renderFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
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
{
30
    /*
31
    * @var string
32
    */
33
    private $tdmcfile = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
        $this->tdmcfile = TDMCreateFile::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreateFile::getInstance() of type object<TDMCreateFile> is incompatible with the declared type string of property $tdmcfile.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
    }
47
48
    /*
49
    *  @static function &getInstance
50
    *  @param null
51
    */
52
    /**
53
     * @return TemplatesUserRss
54
     */
55
    public static function &getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
62
        return $instance;
63
    }
64
65
    /*
66
    *  @public function write
67
    *  @param string $module
68
    *  @param string $table
69
    *  @param string $filename
70
    */
71
    /**
72
     * @param $module
73
     * @param $table
74
     */
75
    public function write($module)
76
    {
77
        $this->setModule($module);
78
    }
79
80
    /*
81
    *  @private function getTemplatesUserRssXml
82
    *  @param string $moduleDirname
83
    *  @param string $table
84
    *  @param string $language
85
    */
86
    /**
87
     * @param $moduleDirname
88
     * @param $table
89
     * @param $language
90
     *
91
     * @return string
92
     */
93
    private function getTemplatesUserRssXml()
94
    {
95
        $ret = <<<EOT
96
<?xml version="1.0" encoding="UTF-8"?>
97
<rss version="2.0">
98
  <channel>
99
    <title><{\$channel_title}></title>
100
    <link><{\$channel_link}></link>
101
    <description><{\$channel_desc}></description>
102
    <lastBuildDate><{\$channel_lastbuild}></lastBuildDate>
103
    <docs>http://backend.userland.com/rss/</docs>
104
    <generator><{\$channel_generator}></generator>
105
    <category><{\$channel_category}></category>
106
    <managingEditor><{\$channel_editor}></managingEditor>
107
    <webMaster><{\$channel_webmaster}></webMaster>
108
    <language><{\$channel_language}></language>
109
    <{if \$image_url != ""}>
110
    <image>
111
      <title><{\$channel_title}></title>
112
      <url><{\$image_url}></url>
113
      <link><{\$channel_link}></link>
114
      <width><{\$image_width}></width>
115
      <height><{\$image_height}></height>
116
    </image>
117
    <{/if}>
118
    <{foreach item=item from=\$items}>
119
    <item>
120
      <title><{\$item.title}></title>
121
      <link><{\$item.link}></link>
122
      <description><{\$item.description}></description>
123
      <pubDate><{\$item.pubdate}></pubDate>
124
      <guid><{\$item.guid}></guid>
125
    </item>
126
    <{/foreach}>
127
  </channel>
128
</rss>\n
129
EOT;
130
131
        return $ret;
132
    }
133
134
    /*
135
    *  @public function renderFile
136
    *  @param string $filename
137
    */
138
    /**
139
     * @param $filename
140
     *
141
     * @return bool|string
142
     */
143
    public function renderFile($filename)
144
    {
145
        $module = $this->getModule();
146
        $moduleDirname = $module->getVar('mod_dirname');
147
        $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...
148
        $content = $this->getTemplatesUserRssXml();
149
        //
150
        $this->tdmcfile->create($moduleDirname, 'templates', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
0 ignored issues
show
Bug introduced by
The method create cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151
152
        return $this->tdmcfile->renderFile();
0 ignored issues
show
Bug introduced by
The method renderFile cannot be called on $this->tdmcfile (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
153
    }
154
}
155