Completed
Push — master ( ececdd...b33bae )
by Michael
04:39 queued 02:00
created

AboutTree::makeArrayTree()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 10
rs 9.4285
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 11 and the first side effect is on line 3.

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
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
4
5
require_once XOOPS_ROOT_PATH . '/class/tree.php';
6
7
if (!class_exists('AboutTree')) {
8
    /**
9
     * Class AboutTree
10
     */
11
    class AboutTree extends XoopsObjectTree
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...
12
    {
13
        /**
14
         * AboutTree constructor.
15
         * @param array $objectArr
16
         * @param null  $rootId
17
         */
18
        public function __construct(&$objectArr, $rootId = null)
19
        {
20
            parent::__construct($objectArr, 'page_id', 'page_pid', $rootId);
21
        }
22
23
        /**
24
         * @param        $key
25
         * @param        $ret
26
         * @param        $prefix_orig
27
         * @param string $prefix_curr
28
         * @param null   $tags
29
         */
30
        public function makeTreeItems($key, &$ret, $prefix_orig, $prefix_curr = '', $tags = null)
31
        {
32
            if ($key > 0) {
33 View Code Duplication
                if (count($tags) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
34
                    foreach ($tags as $tag) {
0 ignored issues
show
Bug introduced by
The expression $tags of type null is not traversable.
Loading history...
35
                        $ret[$key][$tag] = $this->_tree[$key]['obj']->getVar($tag);
36
                    }
37
                } else {
38
                    $ret[$key]['page_title'] = $this->_tree[$key]['obj']->getVar('page_title');
39
                }
40
                $ret[$key]['prefix'] = $prefix_curr;
41
                $prefix_curr .= $prefix_orig;
42
            }
43
            if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) {
44
                foreach ($this->_tree[$key]['child'] as $childkey) {
45
                    $this->makeTreeItems($childkey, $ret, $prefix_orig, $prefix_curr, $tags);
46
                }
47
            }
48
        }
49
50
        /**
51
         * @param  string $prefix
52
         * @param  int    $key
53
         * @param  null   $tags
54
         * @return array
55
         */
56
        public function &makeTree($prefix = '-', $key = 0, $tags = null)
57
        {
58
            $ret = array();
59
            $this->makeTreeItems($key, $ret, $prefix, '', $tags);
60
61
            return $ret;
62
        }
63
64
        /**
65
         * @param  string $name
66
         * @param  string $fieldName
67
         * @param  string $prefix
68
         * @param  string $selected
69
         * @param  bool   $addEmptyOption
70
         * @param  int    $key
71
         * @param  string $extra
72
         * @return string
73
         */
74
        public function makeSelBox($name, $fieldName, $prefix = '-', $selected = '', $addEmptyOption = false, $key = 0, $extra = '')
75
        {
76
            $ret = '<select name=' . $name . '>';
77
            if (!empty($addEmptyOption)) {
78
                $ret .= '<option value="0">' . (is_string($EmptyOption) ? $EmptyOption : '') . '</option>';
0 ignored issues
show
Bug introduced by
The variable $EmptyOption does not exist. Did you mean $addEmptyOption?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
79
            }
80
            $this->_makeSelBoxOptions('page_title', $selected, $key, $ret, $prefix);
81
            $ret .= '</select>';
82
83
            return $ret;
84
        }
85
86
        /**
87
         * @param       $key
88
         * @param       $ret
89
         * @param array $tags
90
         * @param int   $depth
91
         */
92
        public function getAllChildArray($key, &$ret, $tags = array(), $depth = 0)
93
        {
94
            if (--$depth == 0) {
95
                return;
96
            }
97
98
            if (isset($this->_tree[$key]['child'])) {
99
                foreach ($this->_tree[$key]['child'] as $childkey) {
100
                    if (isset($this->_tree[$childkey]['obj'])):
101 View Code Duplication
                        if (count($tags) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
102
                            foreach ($tags as $tag) {
103
                                $ret['child'][$childkey][$tag] = $this->_tree[$childkey]['obj']->getVar($tag);
104
                            }
105
                        } else {
106
                            $ret['child'][$childkey]['page_title'] = $this->_tree[$childkey]['obj']->getVar('page_title');
107
                        }
108
                    endif;
109
110
                    $this->getAllChildArray($childkey, $ret['child'][$childkey], $tags, $depth);
111
                }
112
            }
113
        }
114
115
        /**
116
         * @param  int   $key
117
         * @param  null  $tags
118
         * @param  int   $depth
119
         * @return array
120
         */
121
        public function &makeArrayTree($key = 0, $tags = null, $depth = 0)
122
        {
123
            $ret = array();
124
            if ($depth > 0) {
125
                $depth++;
126
            }
127
            $this->getAllChildArray($key, $ret, $tags, $depth);
128
129
            return $ret;
130
        }
131
    }
132
}
133