FormSelectCountry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
1
<?php
2
3
namespace XoopsModules\Xfguestbook\Form;
4
5
//
6
//  ------------------------------------------------------------------------ //
7
//             XF Guestbook                                                  //
8
// ------------------------------------------------------------------------- //
9
//  This program is free software; you can redistribute it and/or modify     //
10
//  it under the terms of the GNU General Public License as published by     //
11
//  the Free Software Foundation; either version 2 of the License, or        //
12
//  (at your option) any later version.                                      //
13
//                                                                           //
14
//  You may not change or alter any portion of this comment or credits       //
15
//  of supporting developers from this source code or any supporting         //
16
//  source code which is considered copyrighted (c) material of the          //
17
//  original comment or credit authors.                                      //
18
//                                                                           //
19
//  This program is distributed in the hope that it will be useful,          //
20
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
//  GNU General Public License for more details.                             //
23
//                                                                           //
24
//  You should have received a copy of the GNU General Public License        //
25
//  along with this program; if not, write to the Free Software              //
26
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
//  ------------------------------------------------------------------------ //
28
29
require_once dirname(__DIR__, 4) . '/class/xoopsform/formselect.php';
30
31
/**
32
 * Class FormSelectCountry
33
 */
34
class FormSelectCountry extends \XoopsFormSelect
35
{
36
    /**
37
     * FormSelectCountry constructor.
38
     * @param      $caption
39
     * @param      $name
40
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
41
     * @param int  $size
42
     * @param bool $nullopt
43
     */
44
    public function __construct($caption, $name, $value = null, $size = 1, $nullopt = false)
45
    {
46
        /** @var \XoopsMySQLDatabase $db */
47
        $db = \XoopsDatabaseFactory::getDatabaseConnection();
48
        parent::__construct($caption, $name, $value, $size);
49
        $sql    = 'SELECT country_code, country_name FROM ' . $db->prefix('xfguestbook_country') . ' ORDER BY country_name';
50
        $result = $db->query($sql);
51
        if ($nullopt) {
52
            $this->addOption('', '-');
53
        }
54
        $this->addOption('other', MI_XFGUESTBOOK_OTHER);
55
        while (false !== ($myrow = $db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        while (false !== ($myrow = $db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
56
            $this->addOption($myrow['country_code'], $myrow['country_name']);
57
        }
58
    }
59
}
60