Animal   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 73
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNumOfFields() 0 27 2
A getConfig() 0 3 1
A __construct() 0 10 2
1
<?php
2
3
namespace XoopsModules\Pedigree;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Pedigree module for XOOPS
17
 *
18
 * @copyright   {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
19
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @package     pedigree
21
 * @subpackage  class
22
 * @since       1.3.1
23
 * @author      XOOPS Module Dev Team
24
 * @author      ZySpec <[email protected]>
25
 */
26
27
use XoopsModules\Pedigree\{
28
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
29
};
30
31
/**
32
 * Animal Class
33
 */
34
class Animal
35
{
36
    protected $myTree       = [];
37
    protected $fields       = [];
38
    protected $configValues = [];
39
40
    /**
41
     * class constructor
42
     *
43
     * initializes the tree array
44
     * @param int|null $id
45
     */
46
    public function __construct($id = null)
47
    {
48
        $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
49
        $id            = null !== $id ? (int)$id : 1;
50
        $myTreeHandler = Helper::getInstance()->getHandler('Tree');
51
52
        $criteria = new \CriteriaCompo();
53
        $criteria->add(new \Criteria('id', $id));
54
        $criteria->setLimit(1);
55
        $this->myTree = $myTreeHandler->getAll($criteria, null, false);
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsModules\Pedigree\TreeHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        /** @scrutinizer ignore-call */ 
56
        $this->myTree = $myTreeHandler->getAll($criteria, null, false);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        /*
57
        $SQL = "SELECT * FROM " . $GLOBALS['xoopsDB']->prefix("pedigree_registry") . " WHERE id = {$id}";
58
        $result    = $GLOBALS['xoopsDB']->query($SQL);
59
        $row       = $GLOBALS['xoopsDB']->fetchRow($result);
60
        $numfields = mysqli_num_fields($result);
61
        for ($i = 0; $i < $numfields; ++$i) {
62
            $key        =$GLOBALS['xoopsDB']->getFieldName($result, $i);
63
            $this->$key = $row[$i];
64
        }
65
        */
66
    }
67
68
    /**
69
     * Number of Fields
70
     * @return array
71
     */
72
    public function getNumOfFields()
73
    {
74
        $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
75
        $fieldsHandler = Helper::getInstance()->getHandler('Fields');
76
        $criteria      = new \CriteriaCompo();
77
        $criteria->setSort('`order`');
78
        $criteria->setOrder('ASC');
79
        $this->fields       = $fieldsHandler->getIds($criteria); //get all object IDs
0 ignored issues
show
Bug introduced by
The method getIds() does not exist on XoopsModules\Pedigree\FieldsHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        /** @scrutinizer ignore-call */ 
80
        $this->fields       = $fieldsHandler->getIds($criteria); //get all object IDs

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
        $this->configValues = $fieldsHandler->getAll($criteria, null, false); //get objects as arrays
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsModules\Pedigree\FieldsHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
        /** @scrutinizer ignore-call */ 
81
        $this->configValues = $fieldsHandler->getAll($criteria, null, false); //get objects as arrays

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
        if (empty($this->configValues)) {
82
            $this->configValues = '';
83
        }
84
        /*
85
        $SQL    = "SELECT * FROM " . $GLOBALS['xoopsDB']->prefix("pedigree_fields") . " ORDER BY `order`";
86
        $result = $GLOBALS['xoopsDB']->query($SQL);
87
        $fields = [];
88
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
89
            $fields[] = $row['id'];
90
            $configValues[] = $row;
91
92
        }
93
        $this->configValues = isset($configValues) ? $configValues : '';
94
        //print_r ($this->configValues); exit();
95
        */
96
        unset($fieldsHandler, $criteria);
97
98
        return $this->fields;
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    public function getConfig()
105
    {
106
        return $this->configValues;
107
    }
108
}
109