Passed
Push — master ( 2ecc51...c1b656 )
by Michael
04:26 queued 02:02
created

efqDataFieldHandler::getFieldValue()   D

Complexity

Conditions 19
Paths 19

Size

Total Lines 81
Code Lines 65

Duplication

Lines 39
Ratio 48.15 %

Importance

Changes 0
Metric Value
cc 19
eloc 65
nc 19
nop 3
dl 39
loc 81
rs 4.9709
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
2
// $Id: listing.php,v 1.1.0 2007/11/03 17:46:00 wtravel
3
//  ------------------------------------------------------------------------ //
4
//                				EFQ Directory			                     //
5
//                    Copyright (c) 2006 EFQ Consultancy                     //
6
//                       <http://www.efqdirectory.com/>                      //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
//	Part of the efqDirectory module provided by: wtravel					 //
28
// 	e-mail: [email protected]											 //
29
//	Purpose: Create a business directory for xoops.		 	 				 //
30
//	Based upon the mylinks and the mxDirectory modules						 //
31
// ------------------------------------------------------------------------- //
32
33
/**
34
 * Class efqDataField
35
 * Manages operations for datafields
36
 *
37
 * @package   efqDirectory
38
 * @author    EFQ Consultancy <[email protected]>
39
 * @copyright EFQ Consultancy (c) 2007
40
 * @version   1.1.0
41
 */
42
class efqDataField extends XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
{
44
45
    /**
46
     * Constructor
47
     */
48
    public function efqDataField()
49
    {
50
        // class constructor;
51
    }
52
}
53
54
/**
55
 * Class efqDataFieldHandler
56
 * Manages database operations for data fields
57
 *
58
 * @package   efqDirectory
59
 * @author    EFQ Consultancy <[email protected]>
60
 * @copyright EFQ Consultancy (c) 2007
61
 * @version   1.1.0
62
 */
63
class efqDataFieldHandler extends XoopsObjectHandler
0 ignored issues
show
Bug introduced by
The type XoopsObjectHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
{
65
    public $errorhandler;
66
67
    public function efqDataFieldHandler()
68
    {
69
        //Instantiate class
70
        global $eh;
71
        $this->db           = XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
        $this->errorhandler = $eh;
73
    }
74
75
    public function getDataFields($itemid, $show = 10, $min = 0)
76
    {
77
        $sql = "SELECT DISTINCT t.dtypeid, t.title, t.section, t.icon, f.typeid, f.fieldtype, f.ext, t.options, d.itemid, d.value, d.customtitle, t.custom ";
78
        $sql .= "FROM " . $this->db->prefix("efqdiralpha1_item_x_cat") . " ic, " . $this->db->prefix("efqdiralpha1_dtypes_x_cat") . " xc, " . $this->db->prefix("efqdiralpha1_fieldtypes") . " f, " . $this->db->prefix("efqdiralpha1_dtypes") . " t ";
79
        $sql .= "LEFT JOIN " . $this->db->prefix("efqdiralpha1_data") . " d ON (t.dtypeid=d.dtypeid AND d.itemid=" . $itemid . ") ";
80
        $sql .= "WHERE ic.cid=xc.cid AND ic.active='1' AND xc.dtypeid=t.dtypeid AND t.fieldtypeid=f.typeid AND t.activeyn='1' AND ic.itemid=" . $itemid . "";
81
        $data_result = $this->db->query($sql) or $this->errorhandler->show("0013");
82
        //$numrows = $this->db->getRowsNum($data_result);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
83
        $arr = array();
84 View Code Duplication
        while (list($dtypeid, $title, $section, $icon, $ftypeid, $fieldtype, $ext, $options, $itemid, $value, $customtitle, $custom) = $this->db->fetchRow($data_result)) {
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...
85
            $fieldvalue = $this->getFieldValue($fieldtype, $options, $value);
86
            if ($icon != '') {
87
                $iconurl = "<img src=\"uploads/$icon\" />";
88
            } else {
89
                $iconurl = "";
90
            }
91
            if ($custom != '0' && $customtitle != "") {
92
                $title = $customtitle;
93
            }
94
            $arr[] = array(
95
                'dtypeid'     => $dtypeid,
96
                'title'       => $title,
97
                'section'     => $section,
98
                'icon'        => $iconurl,
99
                'ftypeid'     => $ftypeid,
100
                'fieldtype'   => $fieldtype,
101
                'ext'         => $ext,
102
                'options'     => $options,
103
                'custom'      => $custom,
104
                'itemid'      => $itemid,
105
                'value'       => $fieldvalue,
106
                'customtitle' => $customtitle
107
            );
108
        }
109
110
        return $arr;
111
    }
112
113
    public function getFieldValue($fieldtype = "", $options = "", $value = 0)
114
    {
115
        global $myts, $moddir;
116
        switch ($fieldtype) {
117
            case "dhtml":
118
                return $myts->displayTarea($value);
119
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
120
            //case "gmap":
121
            //			$gmapHandler = new efqGmapHandler();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
122
            //			$gmap = new efqGmap();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
123
            //			$gmap->setPointsJS($gmapHandler->getPointsJS($gmap));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
124
            //			$gmap->generateMap();
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...
125
            //			$ret = $gmap->showMap();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
126
            //			unset($gmap);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
127
            //			unset($gmapHandler);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
128
            //return $myts->makeTboxData4Show($value);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
129
            //break;
130
            case "radio":
131
                return $myts->makeTboxData4Show($value);
132
                break;
133 View Code Duplication
            case "rating":
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...
134
                $xoops_url = XOOPS_URL;
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
135
                switch ($value) {
136
                    case 1:
137
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_1.gif";
138
                        break;
139
                    case 2:
140
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_2.gif";
141
                        break;
142
                    case 3:
143
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_3.gif";
144
                        break;
145
                    case 4:
146
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_4.gif";
147
                        break;
148
                    case 5:
149
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_5.gif";
150
                        break;
151
                    case 6:
152
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_6.gif";
153
                        break;
154
                    case 7:
155
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_7.gif";
156
                        break;
157
                    case 8:
158
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_8.gif";
159
                        break;
160
                    case 9:
161
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_9.gif";
162
                        break;
163
                    case 10:
164
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_10.gif";
165
                        break;
166
                    default:
167
                        $src = "";
168
                }
169
                $rating = "<img src=\"$src\" />";
170
171
                return $rating;
172
                break;
173
            case "select":
174
                return $myts->makeTboxData4Show($value);
175
                break;
176
            case "textbox":
177
                return $myts->makeTboxData4Show($value);
178
                break;
179
            case "url":
180
                $link = explode('|', $value);
181
182
                return '<a href="' . $myts->makeTboxData4Show($link[0]) . '" title="' . $myts->makeTboxData4Show($link[1]) . '">' . $myts->makeTboxData4Show($link[0]) . '</a>';
183
                break;
184
            case "yesno":
185
                if ($value == '1') {
186
                    return _YES;
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
187
                } else {
188
                    return _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
189
                }
190
                break;
191
            default:
192
                return $myts->makeTboxData4Show($value);
193
                break;
194
        }
195
    }
196
}
197