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

PedigreeAnimal::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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
 * 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
/**
23
 * Class Animal
24
 */
25
class PedigreeAnimal
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...
26
{
27
    protected $dirname;
28
    protected $configValues = array();
29
    /**
30
     * @param int $animalnumber {@internal param int $id animal Id}}
31
     */
32
    public function __construct($animalnumber = 0)
33
    {
34
        $this->dirname = basename(dirname(__DIR__));
35
        $animalNum = (0 == (int)$animalnumber) ? 1 : (int)$animalnumber;
36
        $ptreeHandler = xoops_getModuleHandler('tree', $this->dirname);
37
        $ptree = $ptreeHandler->getAll(new Criteria('Id', $animalNum), null, false, true);
38
        while (list($key, $val) = each($ptree)) {
39
            $this->$key = $val;
40
        }
41
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
42
        global $xoopsDB;
43
        if (0 == $animalnumber) {
44
            $SQL = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE ID = '1'";
45
        } else {
46
            $SQL = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ID = ' . $animalnumber;
47
        }
48
        $result    = $GLOBALS['xoopsDB']->query($SQL);
49
        $row       = $GLOBALS['xoopsDB']->fetchRow($result);
50
        $numfields = $GLOBALS['xoopsDB']->getFieldsNum($result);
51
        for ($i = 0; $i < $numfields; ++$i) {
52
            $key        = mysqli_fetch_field_direct($result, $i)->name;
53
            $this->$key = $row[$i];
54
        }
55
*/
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function getNumOfFields()
62
    {
63
        $fields = array();
64
        $fieldsHandler  = xoops_getModuleHandler('fields', $this->dirname);
65
        $allFieldsArray = $fieldsHandler->getAll(null, null, false, true);
66
        foreach ($allFieldsArray as $key=>$val) {
67
            $fields[] = $key;
68
            $configValues[] = $val;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$configValues was never initialized. Although not strictly required by PHP, it is generally a good practice to add $configValues = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
69
        }
70
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
71
        global $xoopsDB;
72
        $SQL    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' ORDER BY `order`';
73
        $fields = array();
74
        $result = $GLOBALS['xoopsDB']->query($SQL);
75
        $count  = 0;
76
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
77
            $fields[] = $row['Id'];
78
            ++$count;
79
            $configValues[] = $row;
80
        }
81
*/
82
        $this->configValues = isset($configValues) ? $configValues : '';
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($configValues) ? $configValues : '' can also be of type string. However, the property $configValues is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
83
        //print_r ($this->configValues); die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
84
        return $fields;
85
    }
86
87
    /**
88
     * @return mixed
89
     */
90
    public function getConfig()
91
    {
92
        return $this->configValues;
93
    }
94
}
95