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

PedigreeTextArea   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 62
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 4
A editField() 0 6 1
A newField() 0 6 1
A getSearchString() 0 4 1

How to fix   Duplicated Code   

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:

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

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
 * Pedigree module for XOOPS
13
 *
14
 * @copyright   {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project}
15
 * @copyright   {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
16
 * @license     GPL 2.0 or later
17
 * @package     pedigree
18
 * @subpackage  class
19
 * @author      XOOPS Mod Development Team
20
 */
21
22
require_once __DIR__ . '/htmlinput.abstract.php';
23
24
/**
25
 * Class PedigreeSelectBox
26
 */
27
class PedigreeTextArea extends PedigreeHtmlInputAbstract
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: searchField, showField, showValue, viewField
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...
28
{
29
    // Define class variables
30
    private $fieldnumber;
31
    private $fieldname;
32
    private $value;
33
    private $defaultvalue;
34
    private $lookuptable;
0 ignored issues
show
Unused Code introduced by
The property $lookuptable is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
36
    /**
37
     * Constructor
38
     *
39
     * @param Field $parentObject
40
     * @param PedigreeAnimal $animalObject
41
     */
42 View Code Duplication
    public function __construct($parentObject, $animalObject)
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...
43
    {
44
        $this->fieldnumber  = $parentObject->getId();
45
        $this->fieldname    = $parentObject->fieldname;
0 ignored issues
show
Bug introduced by
The property fieldname does not seem to exist in Field.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
47
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue does not seem to exist in Field.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
48
        if ($parentObject->hasLookup()) {
49
            xoops_error('No lookuptable may be specified for userfield ' . $this->fieldnumber, get_class($this));
50
        }
51
        if ($parentObject->inAdvanced()) {
52
            xoops_error('userfield ' . $this->fieldnumber . ' cannot be shown in advanced info', get_class($this));
53
        }
54
        if ($parentObject->inPie()) {
55
            xoops_error('A Pie-chart cannot be specified for userfield ' . $this->fieldnumber, get_class($this));
56
        }
57
    }
58
59
    /**
60
     * @return XoopsFormTextArea
61
     */
62
    public function editField()
63
    {
64
        $textarea = new XoopsFormTextArea('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value, $rows = 5, $cols = 50);
65
66
        return $textarea;
67
    }
68
69
    /**
70
     * @param string $name
71
     *
72
     * @return XoopsFormTextArea
73
     */
74
    public function newField($name = '')
75
    {
76
        $textarea = new XoopsFormTextArea('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue, $rows = 5, $cols = 50);
77
78
        return $textarea;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getSearchString()
85
    {
86
        return '&amp;o=naam&amp;l=1';
87
    }
88
}
89