Completed
Branch master (a25b3b)
by Michael
03:43 queued 01:22
created

report-abuse.php ➔ MailAd()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 75
Code Lines 59

Duplication

Lines 7
Ratio 9.33 %

Importance

Changes 0
Metric Value
cc 3
eloc 59
nc 3
nop 5
dl 7
loc 75
rs 9
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 32 and the first side effect is on line 23.

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
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
include_once __DIR__ . '/header.php';
24
require_once XOOPS_ROOT_PATH . '/modules/adslight/include/gtickets.php';
25
//include XOOPS_ROOT_PATH . '/modules/adslight/class/utilities.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
26
27
/**
28
 * @param $lid
29
 *
30
 * @return void
31
 */
32
function ReportAbuse($lid)
1 ignored issue
show
Coding Style introduced by
ReportAbuse 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...
33
{
34
    global $xoopsConfig, $xoopsDB, $xoopsTheme, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
35
36
    include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
37
    include XOOPS_ROOT_PATH . '/header.php';
38
39
    $lid    = (int)$lid;
40
    $result = $xoopsDB->query('SELECT lid, title, type FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid) );
41
    list($lid, $title, $type) = $xoopsDB->fetchRow($result);
42
43
    $xoTheme->addMeta('meta', 'robots', 'noindex, nofollow');
0 ignored issues
show
Bug introduced by
The variable $xoTheme does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
44
45
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8'><tr class='bg4'><td valign='top'>\n";
46
    echo '<strong>' . _ADSLIGHT_REPORTSENDTO . " $lid </strong>: \" $type : $title \"<br><br>
47
        <form action=\"report-abuse.php\" method=post>
48
        <input type=\"hidden\" name=\"lid\" value=\"$lid\" />";
49
    if ($GLOBALS['xoopsUser']) {
50
        $idd   = $GLOBALS['xoopsUser']->getVar('uname', 'E');
51
        $idde  = $GLOBALS['xoopsUser']->getVar('email', 'E');
52
        $iddee = $xoopsConfig['adminmail'];
53
    } else {
54
        $iddee = $xoopsConfig['adminmail'];
55
    }
56
57
    echo "
58
    <table width='99%' class='outer' cellspacing='1'>
59
    <tr>
60
      <td class='head' width='30%'>" . _ADSLIGHT_NAME . " </td>
61
      <td class='even'><input class=\"textbox\" type=\"text\" name=\"yname\" value=\"$idd\" /></td>
0 ignored issues
show
Bug introduced by
The variable $idd does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
62
    </tr>
63
    <tr>
64
      <td class='head'>" . _ADSLIGHT_MAIL . " </td>
65
      <td class='even'><input class=\"textbox\" type=\"text\" name=\"ymail\" value=\"$idde\" /></td>
0 ignored issues
show
Bug introduced by
The variable $idde does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
66
    </tr>
67
    <tr>
68
      <td class='head'></td>
69
      <td class='even'><input class=\"textbox\" type=\"hidden\" name=\"fmail\" value=\"$iddee\"/></td>
70
    </tr>";
71
72 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
        echo "<tr><td class='head'>" . _ADSLIGHT_CAPTCHA . " </td><td class='even'>";
74
        $jlm_captcha = '';
0 ignored issues
show
Unused Code introduced by
$jlm_captcha 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...
75
        $jlm_captcha = new XoopsFormCaptcha(_ADSLIGHT_CAPTCHA, 'xoopscaptcha', false);
76
        echo $jlm_captcha->render();
77
        echo '</td></tr>';
78
    }
79
80
    echo '</table><br>
81
    <input type=hidden name=op value=MailAd>
82
    <input type=submit value=' . _ADSLIGHT_SENDFR . '>
83
    </form>     ';
84
    echo '</td></tr></table>';
85
}
86
87
/**
88
 * @param $lid
89
 * @param $yname
90
 * @param $ymail
91
 * @param $fname
92
 * @param $fmail
93
 */
94
function MailAd($lid, $yname, $ymail, $fname, $fmail)
1 ignored issue
show
Coding Style introduced by
MailAd 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...
95
{
96
    global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts, $xoopsLogger, $moduleDirName, $main_lang;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
97
98 View Code Duplication
    if ('1' == $GLOBALS['xoopsModuleConfig']['adslight_use_captcha']) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
        xoops_load('xoopscaptcha');
100
        $xoopsCaptcha = XoopsCaptcha::getInstance();
101
        if (!$xoopsCaptcha->verify()) {
102
            redirect_header(XOOPS_URL . '/modules/adslight/index.php', 2, $xoopsCaptcha->getMessage());
103
        }
104
    }
105
106
    $lid    = (int)$lid;
107
    $result = $xoopsDB->query('SELECT lid, title, expire, type, desctext, tel, price, typeprice, date, email, submitter, town, country, photo FROM '
108
                              . $xoopsDB->prefix('adslight_listing')
109
                              . ' WHERE lid='
110
                              . $xoopsDB->escape($lid));
111
    list($lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date, $email, $submitter, $town, $country, $photo) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Unused Code introduced by
The assignment to $date is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $email is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $photo is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
112
113
    $title     = $myts->addSlashes($title);
114
    $expire    = $myts->addSlashes($expire);
0 ignored issues
show
Unused Code introduced by
$expire 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...
115
    $type      = $myts->addSlashes($type);
116
    $desctext  = $myts->displayTarea($desctext, 1, 1, 1, 1, 1);
117
    $tel       = $myts->addSlashes($tel);
118
    $price     = $myts->addSlashes($price);
119
    $typeprice = $myts->addSlashes($typeprice);
120
    $submitter = $myts->addSlashes($submitter);
0 ignored issues
show
Unused Code introduced by
$submitter 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...
121
    $town      = $myts->addSlashes($town);
122
    $country   = $myts->addSlashes($country);
123
124
    $tags                       = array();
125
    $tags['YNAME']              = stripslashes($yname);
126
    $tags['YMAIL']              = $ymail;
127
    $tags['FNAME']              = stripslashes($fname);
128
    $tags['FMAIL']              = $fmail;
129
    $tags['HELLO']              = _ADSLIGHT_HELLO;
130
    $tags['LID']                = $lid;
131
    $tags['LISTING_NUMBER']     = _ADSLIGHT_LISTING_NUMBER;
132
    $tags['TITLE']              = $title;
133
    $tags['TYPE']               = AdslightUtilities::getNameType($type);
134
    $tags['DESCTEXT']           = $desctext;
135
    $tags['PRICE']              = $price;
136
    $tags['TYPEPRICE']          = $typeprice;
137
    $tags['TEL']                = $tel;
138
    $tags['TOWN']               = $town;
139
    $tags['COUNTRY']            = $country;
140
    $tags['OTHER']              = '' . _ADSLIGHT_INTERESS . '' . $xoopsConfig['sitename'] . '';
141
    $tags['LISTINGS']           = '' . XOOPS_URL . '/modules/adslight/';
142
    $tags['LINK_URL']           = '' . XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid . '';
143
    $tags['THINKS_REPORT']      = '' . _ADSLIGHT_REPORTMESSAGE . '';
144
    $tags['NO_MAIL']            = '' . _ADSLIGHT_NOMAIL . '';
145
    $tags['YOU_CAN_VIEW_BELOW'] = '' . _ADSLIGHT_YOU_CAN_VIEW_BELOW . '';
146
    $tags['WEBMASTER']          = _ADSLIGHT_WEBMASTER;
147
    $tags['NO_REPLY']           = _ADSLIGHT_NOREPLY;
148
    $subject                    = '' . _ADSLIGHT_REPORTSUBJET . ' ' . $xoopsConfig['sitename'] . '';
149
150
    $xoopsMailer =& xoops_getMailer();
151
    $xoopsMailer->multimailer->isHTML(true);
152
    $xoopsMailer->useMail();
153
    $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/');
154
    $xoopsMailer->setTemplate('listing_report_abuse.tpl');
155
    $xoopsMailer->setFromEmail($ymail);
156
    $xoopsMailer->setToEmails($fmail);
157
    $xoopsMailer->setSubject($subject);
158
    $xoopsMailer->assign($tags);
159
160
    // $fmail = $xoopsConfig['adminmail'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
161
    // $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
162
    // $idde = $xoopsUserIsAdmin->getVar("adminmail", "E");
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
163
164
    $xoopsMailer->send();
165
    echo $xoopsMailer->getErrors();
166
167
    redirect_header('index.php', 3, _ADSLIGHT_REPORTANNSEND);
168
}
169
170
##############################################################
171
$yname = !empty($_POST['yname']) ? $myts->addSlashes($_POST['yname']) : '';
172
$ymail = !empty($_POST['ymail']) ? $myts->addSlashes($_POST['ymail']) : '';
173
$fname = !empty($_POST['fname']) ? $myts->addSlashes($_POST['fname']) : '';
174
$fmail = !empty($_POST['fmail']) ? $myts->addSlashes($_POST['fmail']) : '';
175
176
$lid = XoopsRequest::getInt('lid', 0);
177
$op  = XoopsRequest::getString('op', '');
178
179 View Code Duplication
switch ($op) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
    case 'ReportAbuse':
181
        include XOOPS_ROOT_PATH . '/header.php';
182
        ReportAbuse($lid);
183
        include XOOPS_ROOT_PATH . '/footer.php';
184
        break;
185
186
    case 'MailAd':
187
        MailAd($lid, $yname, $ymail, $fname, $fmail);
188
        break;
189
190
    default:
191
        redirect_header('index.php', 1, _RETURNANN);
192
        break;
193
}
194