Completed
Push — master ( a28409...20baf9 )
by Michael
01:24
created

ContactContactHandler   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 404
Duplicated Lines 8.17 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 33
loc 404
rs 8.3157
c 0
b 0
f 0
wmc 43
lcom 0
cbo 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B contactInfoProcessing() 0 26 1
B contactSendMail() 0 22 5
A contactSendMailConfirm() 0 21 2
A contactReplyMail() 0 17 2
A contactToEmails() 0 16 4
A contactAddReply() 0 10 2
A contactGetReply() 7 22 3
B contactGetAdminList() 7 24 3
A contactGetCount() 0 8 1
A getInsertId() 0 4 1
A contactPruneCount() 10 10 2
A contactDeleteBeforeDate() 9 9 2
A contactPlatform() 0 20 4
A contactType() 0 20 4
B contactLogs() 0 27 6

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ContactContactHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContactContactHandler, and based on these observations, apply Extract Interface, too.

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 30 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
 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
 * Contact module
14
 *
15
 * @copyright   The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      Kazumi Ono (aka Onokazu)
18
 * @author      Trabis <[email protected]>
19
 * @author      Hossein Azizabadi (AKA Voltan)
20
 * @author        Mirza (AKA Bleekk)
21
 */
22
23
if (!defined('XOOPS_ROOT_PATH')) {
24
    die('XOOPS root path not defined');
25
}
26
27
/**
28
 * Class contact
29
 */
30
class Contact extends XoopsObject
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...
31
{
32
    private $db;
33
    private $table;
34
    /**
35
     * contact constructor.
36
     */
37
    public function __construct()
0 ignored issues
show
Coding Style introduced by
__construct 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...
38
    {
39
        // $this->XoopsObject();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
40
        $this->initVar('contact_id', XOBJ_DTYPE_INT, null, false, 11);
41
        $this->initVar('contact_uid', XOBJ_DTYPE_INT, null, false, 11);
42
        $this->initVar('contact_cid', XOBJ_DTYPE_INT, null, false, 11);
43
        $this->initVar('contact_name', XOBJ_DTYPE_TXTBOX, null, false);
44
        $this->initVar('contact_subject', XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('contact_mail', XOBJ_DTYPE_EMAIL, null, false);
46
        $this->initVar('contact_url', XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('contact_create', XOBJ_DTYPE_INT, null, false);
48
        $this->initVar('contact_icq', XOBJ_DTYPE_TXTBOX, null, false);
49
        $this->initVar('contact_company', XOBJ_DTYPE_TXTBOX, null, false);
50
        $this->initVar('contact_location', XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('contact_phone', XOBJ_DTYPE_TXTBOX, null, false);
52
        $this->initVar('contact_department', XOBJ_DTYPE_TXTBOX, null, false);
53
        $this->initVar('contact_ip', XOBJ_DTYPE_TXTBOX, null, false);
54
        $this->initVar('contact_message', XOBJ_DTYPE_TXTAREA, null, false);
55
        $this->initVar('contact_address', XOBJ_DTYPE_TXTAREA, null, false);
56
        $this->initVar('contact_reply', XOBJ_DTYPE_INT, null, false, 1);
57
        $this->initVar('contact_platform', XOBJ_DTYPE_ENUM, null, false, '', '', array('Android', 'Ios', 'Web'));
58
        $this->initVar('contact_type', XOBJ_DTYPE_ENUM, null, false, '', '', array('Contact', 'Phone', 'Mail'));
59
60
        $this->db    = $GLOBALS ['xoopsDB'];
61
        $this->table = $this->db->prefix('contact');
62
    }
63
64
    /**
65
     * @return XoopsThemeForm
66
     */
67
    public function contactReplyForm()
0 ignored issues
show
Coding Style introduced by
contactReplyForm 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...
68
    {
69
//        global $xoopsConfig;
70
        $form = new XoopsThemeForm(_AM_CONTACT_REPLY, 'doreply', 'main.php', 'post', true);
71
        $form->setExtra('enctype="multipart/form-data"');
72
        $form->addElement(new XoopsFormHidden('op', 'doreply'));
73
        $form->addElement(new XoopsFormHidden('contact_id', $this->getVar('contact_id', 'e')));
74
        $form->addElement(new XoopsFormHidden('contact_uid', $this->getVar('contact_uid', 'e')));
75
        $form->addElement(new XoopsFormLabel(_AM_CONTACT_FROM, '', ''));
76
        $form->addElement(
77
            new XoopsFormText(_AM_CONTACT_NAMEFROM, 'contact_name', 50, 255, XoopsUser::getUnameFromId($GLOBALS['xoopsUser']->uid())),
78
            true
79
        );
80
        $form->addElement(new XoopsFormText(_AM_CONTACT_MAILFROM, 'contact_mail', 50, 255, $GLOBALS['xoopsUser']->getVar('email')), true);
81
        $form->addElement(new XoopsFormLabel(_AM_CONTACT_TO, '', ''));
82
        $form->addElement(new XoopsFormText(_AM_CONTACT_NAMETO, 'contact_nameto', 50, 255, $this->getVar('contact_name')), true);
83
        $form->addElement(new XoopsFormText(_AM_CONTACT_MAILTO, 'contact_mailto', 50, 255, $this->getVar('contact_mail')), true);
84
        $form->addElement(new XoopsFormText(_AM_CONTACT_SUBJECT, 'contact_subject', 50, 255, _RE . $this->getVar('contact_subject')), true);
85
        $form->addElement(new XoopsFormTextArea(_AM_CONTACT_MESSAGE, 'contact_message', '', 5, 60), true);
86
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
87
88
        return $form;
89
    }
90
91
    /**
92
     * Returns an array representation of the object
93
     *
94
     * @return array
95
     **/
96
    public function toArray()
97
    {
98
        $ret  = array();
99
        $vars =& $this->getVars();
100
        foreach (array_keys($vars) as $i) {
101
            $ret [$i] = $this->getVar($i);
102
        }
103
104
        return $ret;
105
    }
106
}
107
108
/**
109
 * Class ContactContactHandler
110
 */
111
class ContactContactHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
112
{
113
    /**
114
     * ContactContactHandler constructor.
115
     * @param null|XoopsDatabase $db
116
     */
117
    public function __construct(XoopsDatabase $db)
118
    {
119
        parent::__construct($db, 'contact', 'contact', 'contact_id', 'contact_mail');
120
    }
121
122
    /**
123
     * Get variables passed by GET or POST method
124
     * @param        $global
125
     * @param        $key
126
     * @param string $default
127
     * @param string $type
128
     * @return false|int|mixed|string
129
     */
130
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
131
    public function contactCleanVars(&$global, $key, $default = '', $type = 'int')
132
    {
133
        switch ($type) {
134
            case 'array':
135
                $ret = (isset($global[$key]) && is_array($global[$key])) ? $global[$key] : $default;
136
                break;
137
            case 'date':
138
                $ret = isset($global[$key]) ? strtotime($global[$key]) : $default;
139
                break;
140
            case 'string':
141
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
142
                break;
143
            case 'mail':
144
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_EMAIL) : $default;
145
                break;
146
            case 'url':
147
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) : $default;
148
                break;
149
            case 'ip':
150
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_IP) : $default;
151
                break;
152
            case 'amp':
153
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_FLAG_ENCODE_AMP) : $default;
154
                break;
155
            case 'text':
156
                $ret = isset($global[$key]) ? htmlentities($global[$key], ENT_QUOTES, 'UTF-8') : $default;
157
                break;
158
            case 'platform':
159
                $ret = isset($global[$key]) ? $this->contactPlatform($global[$key]) : $this->contactPlatform($default);
160
                break;
161
            case 'type':
162
                $ret = isset($global[$key]) ? $this->contactType($global[$key]) : $this->contactType($default);
163
                break;
164
            case 'int':
165
            default:
166
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
167
                break;
168
        }
169
        if ($ret === false) {
170
            return $default;
171
        }
172
173
        return $ret;
174
    }
175
*/
176
177
    /**
178
     * @return array
179
     */
180
    public function contactInfoProcessing()
181
    {
182
        $contact                       = array();
183
        $contact['contact_cid']        = XoopsRequest::getInt('contact_id', 0, 'POST');
184
        $contact['contact_uid']        = XoopsRequest::getInt('contact_uid', 0, 'POST');
185
        $contact['contact_name']       = XoopsRequest::getString('contact_name', '', 'POST');
186
        $contact['contact_nameto']     = XoopsRequest::getString('contact_nameto', '', 'POST');
187
        $contact['contact_subject']    = XoopsRequest::getString('contact_subject', '', 'POST');
188
        $contact['contact_mail']       = XoopsRequest::getString('contact_mail', '', 'POST');
189
        $contact['contact_mailto']     = XoopsRequest::getEmail('contact_mailto', '', 'POST');
190
        $contact['contact_url']        = XoopsRequest::getUrl('contact_url', '', 'POST');
191
        $contact['contact_create']     = time();
192
        $contact['contact_icq']        = XoopsRequest::getString('contact_icq', '', 'POST');
193
        $contact['contact_company']    = XoopsRequest::getString('contact_company', '', 'POST');
194
        $contact['contact_location']   = XoopsRequest::getString('contact_location', '', 'POST');
195
        $contact['contact_phone']      = XoopsRequest::getString('contact_phone', '', 'int');
196
        $contact['contact_department'] = XoopsRequest::getString('contact_department', _MD_CONTACT_DEFULTDEP, 'POST');
197
        $contact['contact_ip']         = getenv('REMOTE_ADDR');
198
        $contact['contact_message']    = XoopsRequest::getText('contact_message', '', 'POST');
199
        $contact['contact_address']    = XoopsRequest::getString('contact_address', '', 'POST');
200
        $contact['contact_platform']   = XoopsRequest::getString('contact_platform', 'Web', 'POST');
201
        $contact['contact_type']       = XoopsRequest::getString('contact_type', 'Contact', 'POST');
202
        $contact['contact_reply']      = XoopsRequest::getInt('contact_reply', 0, 'POST');
203
204
        return $contact;
205
    }
206
207
    /**
208
     * @param $contact
209
     * @return string
210
     */
211
    public function contactSendMail($contact)
0 ignored issues
show
Coding Style introduced by
contactSendMail 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...
212
    {
213
        $xoopsMailer =& xoops_getMailer();
214
        $xoopsMailer->useMail();
215
        $xoopsMailer->setToEmails($this->contactToEmails($contact['contact_department']));
216
        $xoopsMailer->setFromEmail($contact['contact_mail']);
217
        $xoopsMailer->setFromName(html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8'));
218
219
        $subjectPrefix = '';
220
        if ($GLOBALS['xoopsModuleConfig']['form_dept'] && $GLOBALS['xoopsModuleConfig']['subject_prefix'] && $GLOBALS['xoopsModuleConfig']['contact_dept']) {
221
            $subjectPrefix = '[' . $GLOBALS['xoopsModuleConfig']['prefix_text'] . ' ' . $contact['contact_department'] . ']: ';
222
        }
223
        $xoopsMailer->setSubject($subjectPrefix . html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8'));
224
        $xoopsMailer->setBody(html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8'));
225
        if ($xoopsMailer->send()) {
226
            $message = _MD_CONTACT_MES_SEND;
227
        } else {
228
            $message = $xoopsMailer->getErrors();
229
        }
230
231
        return $message;
232
    }
233
234
    /**
235
     * @param $contact
236
     * @return string
237
     */
238
    public function contactSendMailConfirm($contact)
0 ignored issues
show
Coding Style introduced by
contactSendMailConfirm 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...
239
    {
240
        $xoopsMailer =& xoops_getMailer();
241
        $xoopsMailer->useMail();
242
        $xoopsMailer->setToEmails($contact['contact_mail']);
243
        $xoopsMailer->setFromEmail($this->contactToEmails($contact['contact_department']));
244
        $xoopsMailer->setFromName(html_entity_decode($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES, 'UTF-8'));
245
246
        $xoopsMailer->setSubject(_MD_CONTACT_MAILCONFIRM_SUBJECT);
247
        $body = str_replace('{NAME}', html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8'), _MD_CONTACT_MAILCONFIRM_BODY);
248
        $body = str_replace('{SUBJECT}', html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8'), $body);
249
        $body = str_replace('{BODY}', html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8'), $body);
250
        $xoopsMailer->setBody($body);
251
        if ($xoopsMailer->send()) {
252
            $message = _MD_CONTACT_MES_SEND;
253
        } else {
254
            $message = $xoopsMailer->getErrors();
255
        }
256
257
        return $message;
258
    }
259
260
    /**
261
     * @param $contact
262
     * @return string
263
     */
264
    public function contactReplyMail($contact)
265
    {
266
        $xoopsMailer =& xoops_getMailer();
267
        $xoopsMailer->useMail();
268
        $xoopsMailer->setToEmails($contact['contact_mailto']);
269
        $xoopsMailer->setFromEmail($contact['contact_mail']);
270
        $xoopsMailer->setFromName($contact['contact_name']);
271
        $xoopsMailer->setSubject($contact['contact_subject']);
272
        $xoopsMailer->setBody($contact['contact_message']);
273
        if ($xoopsMailer->send()) {
274
            $message = _MD_CONTACT_MES_SEND;
275
        } else {
276
            $message = $xoopsMailer->getErrors();
277
        }
278
279
        return $message;
280
    }
281
282
    /**
283
     * @param null $department
284
     * @return array
285
     */
286
    public function contactToEmails($department = null)
287
    {
288
//        global $xoopsConfig;
289
        $department_mail[] = xoops_getModuleOption('contact_recipient_std', 'contact');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$department_mail was never initialized. Although not strictly required by PHP, it is generally a good practice to add $department_mail = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
290
        if (!empty($department)) {
291
            $departments = xoops_getModuleOption('contact_dept', 'contact');
292
            foreach ($departments as $vals) {
293
                $vale = explode(',', $vals);
294
                if ($department == $vale[0]) {
295
                    $department_mail[] = $vale[1];
296
                }
297
            }
298
        }
299
300
        return $department_mail;
301
    }
302
303
    /**
304
     * @param $contact_id
305
     * @return bool
306
     */
307
    public function contactAddReply($contact_id)
308
    {
309
        $obj = $this->get($contact_id);
310
        $obj->setVar('contact_reply', 1);
311
        if (!$this->insert($obj)) {
312
            return false;
313
        }
314
315
        return true;
316
    }
317
318
    /**
319
     * @param $contact_id
320
     * @return array|bool
321
     */
322
    public function contactGetReply($contact_id)
323
    {
324
        $criteria = new CriteriaCompo();
325
        $criteria->add(new Criteria('contact_cid', $contact_id));
326
        $criteria->add(new Criteria('contact_type', 'Contact'));
327
        $contacts =& $this->getObjects($criteria, false);
328
        if ($contacts) {
329
            $ret = array();
330
            /** @var Contact $root */
331 View Code Duplication
            foreach ($contacts as $root) {
0 ignored issues
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...
332
                $tab                   = array();
0 ignored issues
show
Unused Code introduced by
$tab 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...
333
                $tab                   = $root->toArray();
334
                $tab['contact_owner']  = XoopsUser::getUnameFromId($root->getVar('contact_uid'));
335
                $tab['contact_create'] = formatTimestamp($root->getVar('contact_create'), _MEDIUMDATESTRING);
336
                $ret []                = $tab;
337
            }
338
339
            return $ret;
340
        } else {
341
            return false;
342
        }
343
    }
344
345
    /**
346
     * @param $contact
347
     * @param $id
348
     * @return array
349
     */
350
    public function contactGetAdminList($contact, $id)
351
    {
352
        $ret      = array();
353
        $criteria = new CriteriaCompo();
354
        $criteria->add(new Criteria($id, '0'));
355
        $criteria->add(new Criteria('contact_type', 'Contact'));
356
        $criteria->setSort($contact['sort']);
357
        $criteria->setOrder($contact['order']);
358
        $criteria->setStart($contact['start']);
359
        $criteria->setLimit($contact['limit']);
360
        $contacts =& $this->getObjects($criteria, false);
361
        if ($contacts) {
362
            /** @var Contact $root */
363 View Code Duplication
            foreach ($contacts as $root) {
0 ignored issues
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...
364
                $tab                   = array();
0 ignored issues
show
Unused Code introduced by
$tab 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...
365
                $tab                   = $root->toArray();
366
                $tab['contact_owner']  = XoopsUser::getUnameFromId($root->getVar('contact_uid'));
367
                $tab['contact_create'] = formatTimestamp($root->getVar('contact_create'), _MEDIUMDATESTRING);
368
                $ret []                = $tab;
369
            }
370
        }
371
372
        return $ret;
373
    }
374
375
    /**
376
     * Get file Count
377
     * @param $id
378
     * @return int
379
     */
380
    public function contactGetCount($id)
381
    {
382
        $criteria = new CriteriaCompo();
383
        $criteria->add(new Criteria($id, '0'));
384
        $criteria->add(new Criteria('contact_type', 'Contact'));
385
386
        return $this->getCount($criteria);
387
    }
388
389
    /**
390
     * Get Insert ID
391
     */
392
    public function getInsertId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
393
    {
394
        return $this->db->getInsertId();
395
    }
396
397
    /**
398
     * Contact Prune Count
399
     * @param $timestamp
400
     * @param $onlyreply
401
     * @return int
402
     */
403 View Code Duplication
    public function contactPruneCount($timestamp, $onlyreply)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
404
    {
405
        $criteria = new CriteriaCompo();
406
        $criteria->add(new Criteria('contact_create', $timestamp, '<='));
407
        if ($onlyreply) {
408
            $criteria->add(new Criteria('contact_reply', 1));
409
        }
410
411
        return $this->getCount($criteria);
412
    }
413
414
    /**
415
     * Contact Delete Before Date
416
     * @param $timestamp
417
     * @param $onlyreply
418
     */
419 View Code Duplication
    public function contactDeleteBeforeDate($timestamp, $onlyreply)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
420
    {
421
        $criteria = new CriteriaCompo();
422
        $criteria->add(new Criteria('contact_create', $timestamp, '<='));
423
        if ($onlyreply) {
424
            $criteria->add(new Criteria('contact_reply', 1));
425
        }
426
        $this->deleteAll($criteria);
427
    }
428
429
    /**
430
     * Contact Platform
431
     * @param $platform
432
     * @return string
433
     */
434
    public function contactPlatform($platform)
435
    {
436
        $platform = strtolower($platform);
437
        switch ($platform) {
438
            case 'Android':
439
                $ret = 'Android';
440
                break;
441
442
            case 'Ios':
443
                $ret = 'Ios';
444
                break;
445
446
            case 'Web':
447
            default:
448
                $ret = 'Web';
449
                break;
450
        }
451
452
        return $ret;
453
    }
454
455
    /**
456
     * Contact type
457
     * @param $type
458
     * @return string
459
     */
460
    public function contactType($type)
461
    {
462
        $type = strtolower($type);
463
        switch ($type) {
464
            case 'Mail':
465
                $ret = 'Mail';
466
                break;
467
468
            case 'Phone':
469
                $ret = 'Phone';
470
                break;
471
472
            case 'Contact':
473
            default:
474
                $ret = 'Contact';
475
                break;
476
        }
477
478
        return $ret;
479
    }
480
481
    /**
482
     * Contact logs
483
     * @param      $column
484
     * @param null $timestamp
485
     * @return array
486
     */
487
    public function contactLogs($column, $timestamp = null)
488
    {
489
        $ret = array();
490
        if (!in_array($column, array('contact_mail', 'contact_url', 'contact_phone'))) {
491
            return $ret;
492
        }
493
        $criteria = new CriteriaCompo();
494
        $criteria->add(new Criteria('contact_cid', '0'));
495
        if (!empty($timestamp)) {
496
            $criteria->add(new Criteria('contact_create', $timestamp, '<='));
497
        }
498
        $criteria->setSort('contact_create');
499
        $criteria->setOrder('DESC');
500
        $contacts =& $this->getObjects($criteria, false);
501
        if ($contacts) {
502
            /** @var Contact $root */
503
            foreach ($contacts as $root) {
504
                $rootColumn = $root->getVar($column);
505
                if (!empty($rootColumn)) {
506
                    $ret[] = $root->getVar($column);
507
                    unset($root);
508
                }
509
            }
510
        }
511
512
        return array_unique($ret);
513
    }
514
}
515