Completed
Pull Request — master (#1)
by
unknown
03:00
created

PedigreeField::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 3
nop 2
dl 14
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
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
 * PedigreeBreadcrumb Class
13
 *
14
 * @copyright   {@link http://xoops.org/ XOOPS Project}
15
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
16
 * @author      lucio <[email protected]>
17
 * @package     Pedigree
18
 * @since       1.31
19
 *
20
 */
21
/**
22
 * Class Field
23
 */
24
class PedigreeField
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...
25
{
26
    protected $id;
27
28
    /**
29
     * @param $fieldnumber
30
     * @param $config
31
     */
32 View Code Duplication
    public function __construct($fieldnumber, $config)
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...
33
    {
34
        //find key where Id = $fieldnumber;
35
        $configCount = count($config);
36
        for ($x = 0; $x < $configCount; ++$x) {
37
            //@todo - figure out if this is suppose to be an assignment or just a compare ('=' or '==')
38
            if ($config[$x]['Id'] = $fieldnumber) {
39
                foreach ($config[$x] as $key => $value) {
40
                    $this->$key = $value;
41
                }
42
            }
43
        }
44
        $this->id = $fieldnumber;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function isActive()
51
    {
52
        return ('1' == $this->getSetting('isactive')) ? true : false;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function inAdvanced()
59
    {
60
        return ('1' == $this->getSetting('viewinadvanced')) ? true : false;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    public function isLocked()
67
    {
68
        return ('1' == $this->getSetting('locked')) ? true : false;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    public function hasSearch()
75
    {
76
        return ('1' == $this->getSetting('hassearch')) ? true : false;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function addLitter()
83
    {
84
        return ('1' == $this->getSetting('litter')) ? true : false;
85
    }
86
87
    /**
88
     * @return bool
89
     */
90
    public function generalLitter()
91
    {
92
        return ('1' == $this->getSetting('generallitter')) ? true : false;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    public function hasLookup()
99
    {
100
        return ('1' == $this->getSetting('lookuptable')) ? true : false;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getSearchString()
107
    {
108
        return '&amp;o=naam&amp;p';
109
    }
110
111
    /**
112
     * @return bool
113
     */
114
    public function inPie()
115
    {
116
        return ('1' == $this->getSetting('viewinpie')) ? true : false;
117
    }
118
119
    /**
120
     * @return bool
121
     */
122
    public function inPedigree()
123
    {
124
        return ('1' == $this->getSetting('viewinpedigree')) ? true : false;
125
    }
126
127
    /**
128
     * @return bool
129
     */
130
    public function inList()
131
    {
132
        return ('1' == $this->getSetting('viewinlist')) ? true : false;
133
    }
134
135
    public function getId()
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...
136
    {
137
        return $this->id;
138
    }
139
140
    /**
141
     * @param $setting
142
     *
143
     * @return mixed
144
     */
145
    public function getSetting($setting)
146
    {
147
        return $this->{$setting};
148
    }
149
150
    /**
151
     * @param $fieldnumber
152
     *
153
     * @return array
154
     */
155 View Code Duplication
    public function lookupField($fieldnumber)
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...
Coding Style introduced by
lookupField 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...
156
    {
157
        $ret = array();
158
        global $xoopsDB;
0 ignored issues
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...
159
        $SQL    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix("pedigree_lookup{$fieldnumber}") . " ORDER BY 'order'";
160
        $result = $GLOBALS['xoopsDB']->query($SQL);
161
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
162
            $ret[] = array('id' => $row['Id'], 'value' => $row['value']);
163
        }
164
        //array_multisort($ret,SORT_ASC);
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...
165
        return $ret;
166
    }
167
168
    /**
169
     * @return XoopsFormLabel
170
     */
171
    public function viewField()
172
    {
173
        $view = new XoopsFormLabel($this->fieldname, $this->value);
0 ignored issues
show
Bug introduced by
The property fieldname does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
174
175
        return $view;
176
    }
177
178
    /**
179
     * @return string
180
     */
181
    public function showField()
182
    {
183
        return $this->fieldname . ' : ' . $this->value;
184
    }
185
186
    /**
187
     * @return mixed|string
188
     */
189
    public function showValue()
190
    {
191
        global $myts;
0 ignored issues
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...
192
193
        return $myts->displayTarea($this->value);
194
        //return $this->value;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
195
    }
196
197
    /**
198
     * @return string
199
     */
200
    public function searchField()
201
    {
202
        return '<input type="text" name="query" size="20">';
203
    }
204
}
205