Completed
Branch master (44f723)
by Michael
11:35 queued 08:26
created

PedigreeHtmlInputAbstract::getSearchString()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
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 29 and the first side effect is on line 13.

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
 *  pedigree HTML Input Interface Class Elements
4
 *
5
 * @copyright ::  ZySpec Incorporated
6
 * @license   ::    {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
7
 * @package   ::    pedigree
8
 * @subpackage:: class
9
 * @author    ::     zyspec <[email protected]>
10
 * @since     ::      1.3.1
11
 */
12
13
defined('XOOPS_ROOT_PATH') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
14
15
/**
16
 * PedigreeHtmlInputAbstract
17
 *
18
 * @package  ::   pedigree
19
 * @author   ::    zyspec <[email protected]>
20
 * @copyright:: Copyright (c) 2014 ZySpec Incorporated
21
 * @access::    public
22
 */
23
24
require_once dirname(__DIR__) . '/include/class_field.php';
25
26
/**
27
 * Class PedigreeHtmlInputAbstract
28
 */
29
abstract class PedigreeHtmlInputAbstract extends Field
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...
30
{
31
    /**
32
     * @return mixed
33
     */
34
    abstract public function editField();
35
36
    /**
37
     * @param $name
38
     * @return mixed
39
     */
40
    abstract public function newField($name);
41
42
    /**
43
     * @return mixed
44
     */
45
    abstract public function viewField();
46
47
    /**
48
     * @return mixed
49
     */
50
    abstract public function showField();
51
52
    /**
53
     * @return mixed
54
     */
55
    abstract public function showValue();
56
57
    /**
58
     * @return mixed
59
     */
60
    abstract public function searchField();
61
62
    /**
63
     * @return mixed
64
     */
65
    abstract public function getSearchString();
66
67
    /**
68
     * @param string $message
69
     *
70
     * @return void
71
     */
72
    public function echoMsg($message)
73
    {
74
        echo "<span style='color: red;'><h3>{$message}</h3></span>";
75
    }
76
77
    /**
78
     * @param $fieldnumber
79
     *
80
     * @return array
81
     */
82 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...
83
    {
84
        $ret = array();
85
        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...
86
        $SQL    = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $fieldnumber) . " ORDER BY 'order'";
87
        $result = $GLOBALS['xoopsDB']->query($SQL);
88
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
89
            $ret[] = array('id' => $row['Id'], 'value' => $row['value']);
90
        }
91
        //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...
92
        return $ret;
93
    }
94
}
95